Skip to content

Commit a35648c

Browse files
authored
fix: table charts should update when underlying data updates (#6809)
## 📝 Summary <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes #123). --> Fixes #6791 ## 🔍 Description of Changes <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [ ] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected.
1 parent 323ccdf commit a35648c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

frontend/src/components/data-table/charts/charts.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const CHART_HEIGHT = 290;
4848

4949
export interface TablePanelProps {
5050
cellId: CellId | null;
51+
data: unknown[];
5152
dataTable: JSX.Element;
5253
displayHeader: boolean;
5354
getDataUrl?: GetDataUrl;
@@ -56,6 +57,7 @@ export interface TablePanelProps {
5657

5758
export const TablePanel: React.FC<TablePanelProps> = ({
5859
cellId,
60+
data,
5961
dataTable,
6062
getDataUrl,
6163
fieldTypes,
@@ -211,6 +213,7 @@ export const TablePanel: React.FC<TablePanelProps> = ({
211213
return (
212214
<TabsContent key={idx} value={tab.tabName} className="h-[400px] mt-1">
213215
<ChartPanel
216+
tableData={data}
214217
chartConfig={tab.config}
215218
chartType={tab.chartType}
216219
saveChart={saveChart}
@@ -228,13 +231,15 @@ export const TablePanel: React.FC<TablePanelProps> = ({
228231
const CHART_PLACEHOLDER_CODE = "X and Y columns are not set";
229232

230233
export const ChartPanel: React.FC<{
234+
tableData: unknown[];
231235
chartConfig: ChartSchemaType | null;
232236
chartType: ChartType;
233237
saveChart: (formValues: ChartSchemaType) => void;
234238
saveChartType: (chartType: ChartType) => void;
235239
getDataUrl?: GetDataUrl;
236240
fieldTypes?: FieldTypesWithExternalType | null;
237241
}> = ({
242+
tableData,
238243
chartConfig,
239244
chartType,
240245
saveChart,
@@ -255,7 +260,7 @@ export const ChartPanel: React.FC<{
255260
const { ref: chartContainerRef } = useResizeObserver();
256261

257262
const { data, isPending, error } = useAsyncData(async () => {
258-
if (!getDataUrl) {
263+
if (!getDataUrl || tableData.length === 0) {
259264
return [];
260265
}
261266

@@ -276,7 +281,8 @@ export const ChartPanel: React.FC<{
276281
},
277282
);
278283
return chartData;
279-
}, []);
284+
// Re-run when the data table changes
285+
}, [tableData]);
280286

281287
const formValues = form.watch();
282288

frontend/src/plugins/impl/DataTablePlugin.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ export const LoadingDataTableComponent = memo(
691691
{props.showChartBuilder ? (
692692
<TablePanel
693693
displayHeader={displayHeader}
694+
data={data?.rows || []}
694695
dataTable={dataTable}
695696
getDataUrl={props.get_data_url}
696697
fieldTypes={props.fieldTypes}

0 commit comments

Comments
 (0)