@@ -90,99 +90,111 @@ def update_preview():
9090 else "Data Preview (all rows)"
9191 )
9292 ui .label (preview_title ).classes ("text-sm text-grey-7" )
93- ui .aggrid .from_polars (preview_df , theme = "quartz" ).classes (
94- "w-full h-64"
95- )
9693
97- # Create column mapping UI using grid
98- with ui .grid (columns = 2 ).classes ("gap-2" ):
99- # create labels for grid header
100- ui .label ("Required Input Information" ) # populates row 1, column 1
101- ui .label ("Imported Dataset Columns" ) # pupolates row 1, column 2
102-
103- # this then fills the rows with column information
104- for input_col in input_columns :
105- # Left column: Input column info card
106- with ui .row ().classes ("items-center gap-1" ):
107- ui .label (input_col .human_readable_name_or_fallback ()).classes (
108- "text-bold text-lg"
109- )
110- if input_col .description :
111- with ui .icon ("info" ).classes ("text-grey-6 cursor-pointer" ):
112- ui .tooltip (input_col .description )
113-
114- # Right column: Dropdown for column selection
115- # Get compatible user columns
116- compatible_columns = [
117- user_col
118- for user_col in user_columns
119- if get_data_type_compatibility_score (
120- input_col .data_type , user_col .data_type
121- )
122- is not None
123- ]
124-
125- # Create dropdown options
126- dropdown_options = {
127- f"{ user_col .name } " : user_col .name
128- for user_col in compatible_columns
129- }
130-
131- # Pre-select the auto-mapped column
132- default_value = None
133- if input_col .name in draft_column_mapping :
134- mapped_col_name = draft_column_mapping [input_col .name ]
135- default_value = next (
136- (
137- k
138- for k , v in dropdown_options .items ()
139- if v == mapped_col_name
140- ),
141- None ,
94+ # create AGGRRID directly from df
95+ grid = ui .aggrid .from_polars (
96+ preview_df ,
97+ theme = "quartz" ,
98+ auto_size_columns = True ,
99+ ).classes ("w-full h-64" )
100+ grid .on (
101+ "firstDataRendered" ,
102+ lambda : grid .run_grid_method ("sizeColumnsToFit" ),
142103 )
143104
144- # Create dropdown with on_change handler
145- dropdown = (
146- ui .select (
147- options = list (dropdown_options .keys ()),
148- label = "Select dataset column" ,
149- value = default_value ,
150- on_change = lambda : update_preview (),
151- )
152- .classes ("w-40" )
153- .props ("use-chips" )
105+ # Shared container for cards, grid, and button
106+ with (
107+ ui .column ()
108+ .classes ("w-full items-center gap-6" )
109+ .style ("max-width: 960px; margin: 0 auto;" )
110+ ):
111+ ui .label ("Map Your Data Columns" ).classes ("text-lg font-bold mb-4" )
112+
113+ with ui .row ().classes ("flex-wrap gap-6 justify-center w-full" ):
114+ for input_col in input_columns :
115+ with ui .card ().classes (
116+ "w-52 p-4 no-shadow border border-gray-200"
117+ ):
118+ with ui .row ().classes ("items-center gap-1" ):
119+ ui .label (
120+ input_col .human_readable_name_or_fallback ()
121+ ).classes ("text-bold" )
122+ if input_col .description :
123+ with ui .icon ("info" ).classes (
124+ "text-grey-6 cursor-pointer"
125+ ):
126+ ui .tooltip (input_col .description )
127+
128+ compatible_columns = [
129+ user_col
130+ for user_col in user_columns
131+ if get_data_type_compatibility_score (
132+ input_col .data_type , user_col .data_type
133+ )
134+ is not None
135+ ]
136+
137+ dropdown_options = {
138+ f"{ user_col .name } " : user_col .name
139+ for user_col in compatible_columns
140+ }
141+
142+ default_value = None
143+ if input_col .name in draft_column_mapping :
144+ mapped_col_name = draft_column_mapping [input_col .name ]
145+ default_value = next (
146+ (
147+ k
148+ for k , v in dropdown_options .items ()
149+ if v == mapped_col_name
150+ ),
151+ None ,
152+ )
153+
154+ dropdown = (
155+ ui .select (
156+ options = list (dropdown_options .keys ()),
157+ value = default_value ,
158+ on_change = lambda : update_preview (),
159+ )
160+ .classes ("w-full mt-2" )
161+ .props ("use-chips" )
162+ )
163+
164+ column_dropdowns [input_col .name ] = (
165+ dropdown ,
166+ dropdown_options ,
167+ )
168+
169+ # Preview section (created after cards)
170+ preview_container = ui .column ().classes ("w-full" )
171+
172+ # Initial preview render
173+ update_preview ()
174+
175+ # Action button
176+ with ui .row ().classes ("w-full justify-end" ):
177+
178+ def _on_proceed ():
179+ """Build column mapping and proceed."""
180+ final_mapping = {}
181+ for input_col_name , (
182+ dropdown ,
183+ options ,
184+ ) in column_dropdowns .items ():
185+ if dropdown .value :
186+ final_mapping [input_col_name ] = options [dropdown .value ]
187+
188+ # Store mapping in session
189+ self .session .column_mapping = final_mapping
190+ self .notify_success ("Column mapping saved!" )
191+
192+ # Navigate to parameters configuration page
193+ self .navigate_to (gui_routes .configure_analysis_parameters )
194+
195+ ui .button (
196+ "Configure Parameters" ,
197+ icon = "arrow_forward" ,
198+ color = "primary" ,
199+ on_click = _on_proceed ,
154200 )
155-
156- # Store reference for later
157- column_dropdowns [input_col .name ] = (dropdown , dropdown_options )
158-
159- # Preview section (created after grid)
160- ui .separator ()
161- preview_container = ui .column ().classes ("w-full" )
162-
163- # Initial preview render
164- update_preview ()
165-
166- # Action button
167- with ui .row ().classes ("w-full justify-end" ):
168-
169- def _on_proceed ():
170- """Build column mapping and proceed."""
171- final_mapping = {}
172- for input_col_name , (dropdown , options ) in column_dropdowns .items ():
173- if dropdown .value :
174- final_mapping [input_col_name ] = options [dropdown .value ]
175-
176- # Store mapping in session
177- self .session .column_mapping = final_mapping
178- self .notify_success ("Column mapping saved!" )
179-
180- # Navigate to parameters configuration page
181- self .navigate_to (gui_routes .configure_analysis_parameters )
182-
183- ui .button (
184- "Configure Parameters" ,
185- icon = "arrow_forward" ,
186- color = "primary" ,
187- on_click = _on_proceed ,
188- )
0 commit comments