@@ -76,26 +76,28 @@ def render(self, project_code: str, **_kwargs) -> None:
76
76
77
77
def show_connection_form (self , selected_connection : dict , _mode : str , project_code ) -> None :
78
78
connection = selected_connection or {}
79
- connection_id = connection .get ("connection_id" , None )
79
+ connection_id = connection .get ("connection_id" , 1 )
80
+ connection_name = connection .get ("connection_name" , "default" )
80
81
sql_flavor = connection .get ("sql_flavor" , "postgresql" )
81
82
data = {}
82
83
83
84
try :
84
85
FlavorForm = BaseConnectionForm .for_flavor (sql_flavor )
85
86
if connection :
86
87
connection ["password" ] = connection ["password" ] or ""
87
- FlavorForm = BaseConnectionForm .for_flavor (sql_flavor )
88
-
89
- form_kwargs = connection or {"sql_flavor" : sql_flavor }
88
+
89
+ form_kwargs = connection or {"sql_flavor" : sql_flavor , "connection_id" : connection_id , "connection_name" : connection_name }
90
90
form = FlavorForm (** form_kwargs )
91
91
92
92
sql_flavor = form .get_field_value ("sql_flavor" , latest = True ) or sql_flavor
93
93
if form .sql_flavor != sql_flavor :
94
- form = BaseConnectionForm .for_flavor (sql_flavor )(sql_flavor = sql_flavor )
94
+ form = BaseConnectionForm .for_flavor (sql_flavor )(sql_flavor = sql_flavor , connection_id = connection_id )
95
+
96
+ form .disable ("connection_name" )
95
97
96
98
form_errors_container = st .empty ()
97
99
data = sp .pydantic_input (
98
- key = f"connection_form:{ connection_id or 'new' } " ,
100
+ key = f"connection_form:{ connection_id } " ,
99
101
model = form , # type: ignore
100
102
)
101
103
data .update ({
@@ -120,16 +122,16 @@ def show_connection_form(self, selected_connection: dict, _mode: str, project_co
120
122
st .error ("Unexpected error displaying the form. Try again" )
121
123
122
124
test_button_column , _ , save_button_column = st .columns ([.2 , .6 , .2 ])
123
- is_submitted , set_submitted = temp_value (f"connection_form-{ connection_id or 'new' } :submit" )
124
- get_connection_status , set_connection_status = temp_value (
125
- f"connection_form-{ connection_id or 'new' } :test_conn"
125
+ is_submitted , set_submitted = temp_value (f"connection_form-{ connection_id } :submit" )
126
+ is_connecting , set_connecting = temp_value (
127
+ f"connection_form-{ connection_id } :test_conn"
126
128
)
127
129
128
130
with save_button_column :
129
131
testgen .button (
130
132
type_ = "flat" ,
131
133
label = "Save" ,
132
- key = f"connection_form:{ connection_id or 'new' } :submit" ,
134
+ key = f"connection_form:{ connection_id } :submit" ,
133
135
on_click = lambda : set_submitted (True ),
134
136
)
135
137
@@ -138,13 +140,14 @@ def show_connection_form(self, selected_connection: dict, _mode: str, project_co
138
140
type_ = "stroked" ,
139
141
color = "basic" ,
140
142
label = "Test Connection" ,
141
- key = f"connection_form:{ connection_id or 'new' } :test" ,
142
- on_click = lambda : set_connection_status ( self . test_connection ( data ) ),
143
+ key = f"connection_form:{ connection_id } :test" ,
144
+ on_click = lambda : set_connecting ( True ),
143
145
)
144
146
145
- if ( connection_status := get_connection_status () ):
147
+ if is_connecting ( ):
146
148
single_element_container = st .empty ()
147
149
single_element_container .info ("Connecting ..." )
150
+ connection_status = self .test_connection (data )
148
151
149
152
with single_element_container .container ():
150
153
renderer = {
0 commit comments