File tree Expand file tree Collapse file tree 2 files changed +79
-2
lines changed
Expand file tree Collapse file tree 2 files changed +79
-2
lines changed Original file line number Diff line number Diff line change 1+ // [start get_config_branching_paths]
2+ var cc = DataStudioApp . createCommunityConnector ( ) ;
3+
4+ function getConfig ( request ) {
5+ var configParams = request . configParams ;
6+ // For the initial getConfig request, request.configParams will be undefined.
7+ // For subsequent requests, it'll include the configuration so far.
8+ var isFirstRequest = configParams === undefined ;
9+ var config = cc . getConfig ( ) ;
10+
11+ config
12+ . newSelectSingle ( )
13+ . setId ( 'country' )
14+ . setName ( 'Country' )
15+ // Set isDynamic to true so any changes to Country will clear the state
16+ // selections.
17+ . setIsDynamic ( true )
18+ . addOption (
19+ config
20+ . newOptionBuilder ( )
21+ . setLabel ( 'United States' )
22+ . setValue ( 'USA' )
23+ )
24+ . addOption (
25+ config
26+ . newOptionBuilder ( )
27+ . setLabel ( 'Canada' )
28+ . setValue ( 'CA' )
29+ ) ;
30+
31+ if ( isFirstRequest ) {
32+ // Tell DS that this is a stepped config request. This will make the 'NEXT'
33+ // button show.
34+ config . setIsSteppedConfig ( true ) ;
35+ } else {
36+ // validate a valid value was selected for configParams.country
37+ if ( configParams . country === undefined ) {
38+ cc . newUserError ( )
39+ . setText ( 'You must choose a country.' )
40+ . throwException ( ) ;
41+ }
42+ switch ( configParams . country ) {
43+ case 'USA' : {
44+ config
45+ . newSelectSingle ( )
46+ . setId ( 'state' )
47+ . setName ( 'State' )
48+ . addOption (
49+ config
50+ . newOptionBuilder ( )
51+ . setLabel ( 'New York' )
52+ . setValue ( 'NY' )
53+ )
54+ . addOption (
55+ config
56+ . newOptionBuilder ( )
57+ . setLabel ( 'Calfornia' )
58+ . setValue ( 'CA' )
59+ ) ;
60+ break ;
61+ }
62+ case 'CA' : {
63+ // No additional configuration is needed for Canada.
64+ break ;
65+ }
66+ default : {
67+ cc . newUserError ( )
68+ . setText ( 'You must either select "CA" or "USA"' )
69+ . throwException ( ) ;
70+ }
71+ }
72+ }
73+ return config . build ( ) ;
74+ }
75+ // [end get_config_branching_paths]
Original file line number Diff line number Diff line change 1- var cc = DataStudioApp . createCommunityConnector ( ) ;
2-
31// https://developers.google.com/datastudio/connector/reference#isadminuser
42function isAdminUser ( ) {
53 return false ;
64}
75
6+ // [start get_config_dynamic_dropdowns]
7+ var cc = DataStudioApp . createCommunityConnector ( ) ;
8+
89function optionsForState ( state ) {
910 switch ( state ) {
1011 case 'IL' : {
@@ -83,6 +84,7 @@ function getConfig(request) {
8384 }
8485 return config . build ( ) ;
8586}
87+ // [end get_config_dynamic_dropdowns]
8688
8789function getFields ( ) {
8890 var fields = cc . getFields ( ) ;
You can’t perform that action at this time.
0 commit comments