Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit 0bb9426

Browse files
committed
refactor: code refactor
1 parent 5855a9b commit 0bb9426

4 files changed

Lines changed: 223 additions & 210 deletions

File tree

bigframes/display/anywidget.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame, deferred: bool = Tr
136136
@traitlets.observe("start_execution")
137137
def _on_start_execution(self, change: dict[str, Any]):
138138
if change["new"]:
139-
self._initial_load()
139+
try:
140+
self._initial_load()
141+
except Exception as e:
142+
self._error_message = str(e)
140143
self.is_deferred_mode = False
141144

142145
def _initial_load(self) -> None:

bigframes/display/table_widget.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)