@@ -43,16 +43,22 @@ function render({ model, el }) {
4343 const errorContainer = document . createElement ( 'div' ) ;
4444 errorContainer . classList . add ( 'error-message' ) ;
4545
46- const deferredContainer = document . createElement ( 'div' ) ;
47- deferredContainer . classList . add ( 'deferred-message' ) ;
48- const deferredText = document . createElement ( 'p' ) ;
49- deferredText . textContent =
50- 'This is a preview of the widget. The SQL query has not been executed yet.' ;
51- const runButton = document . createElement ( 'button' ) ;
52- runButton . textContent = 'Run Query and Display Widget' ;
53- runButton . classList . add ( 'run-button' ) ;
54- deferredContainer . appendChild ( deferredText ) ;
55- deferredContainer . appendChild ( runButton ) ;
46+ function createDeferredView ( ) {
47+ const container = document . createElement ( 'div' ) ;
48+ container . classList . add ( 'deferred-message' ) ;
49+ const text = document . createElement ( 'p' ) ;
50+ text . textContent =
51+ 'This is a preview of the widget. The SQL query has not been executed yet.' ;
52+ const button = document . createElement ( 'button' ) ;
53+ button . textContent = 'Run Query and Display Widget' ;
54+ button . classList . add ( 'run-button' ) ;
55+ container . appendChild ( text ) ;
56+ container . appendChild ( button ) ;
57+ return { container, button } ;
58+ }
59+
60+ const { container : deferredContainer , button : runButton } =
61+ createDeferredView ( ) ;
5662
5763 const tableContainer = document . createElement ( 'div' ) ;
5864 tableContainer . classList . add ( 'table-container' ) ;
@@ -334,8 +340,7 @@ function render({ model, el }) {
334340 runButton . addEventListener ( Event . CLICK , ( ) => {
335341 model . set ( ModelProperty . START_EXECUTION , true ) ;
336342 model . save_changes ( ) ;
337- // Optimistically switch UI state or wait for model update?
338- // Wait for model update via observer for robustness, but could show loading here.
343+ // Update button state to indicate loading.
339344 runButton . textContent = 'Running...' ;
340345 runButton . disabled = true ;
341346 } ) ;
0 commit comments