Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions frontend/src/components/data-table/charts/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const CHART_HEIGHT = 290;

export interface TablePanelProps {
cellId: CellId | null;
data: unknown[];
dataTable: JSX.Element;
displayHeader: boolean;
getDataUrl?: GetDataUrl;
Expand All @@ -56,6 +57,7 @@ export interface TablePanelProps {

export const TablePanel: React.FC<TablePanelProps> = ({
cellId,
data,
dataTable,
getDataUrl,
fieldTypes,
Expand Down Expand Up @@ -211,6 +213,7 @@ export const TablePanel: React.FC<TablePanelProps> = ({
return (
<TabsContent key={idx} value={tab.tabName} className="h-[400px] mt-1">
<ChartPanel
tableData={data}
chartConfig={tab.config}
chartType={tab.chartType}
saveChart={saveChart}
Expand All @@ -228,13 +231,15 @@ export const TablePanel: React.FC<TablePanelProps> = ({
const CHART_PLACEHOLDER_CODE = "X and Y columns are not set";

export const ChartPanel: React.FC<{
tableData: unknown[];
chartConfig: ChartSchemaType | null;
chartType: ChartType;
saveChart: (formValues: ChartSchemaType) => void;
saveChartType: (chartType: ChartType) => void;
getDataUrl?: GetDataUrl;
fieldTypes?: FieldTypesWithExternalType | null;
}> = ({
tableData,
chartConfig,
chartType,
saveChart,
Expand All @@ -255,7 +260,7 @@ export const ChartPanel: React.FC<{
const { ref: chartContainerRef } = useResizeObserver();

const { data, isPending, error } = useAsyncData(async () => {
if (!getDataUrl) {
if (!getDataUrl || tableData.length === 0) {
return [];
}

Expand All @@ -276,7 +281,8 @@ export const ChartPanel: React.FC<{
},
);
return chartData;
}, []);
// Re-run when the data table changes
}, [tableData]);

const formValues = form.watch();

Expand Down
1 change: 1 addition & 0 deletions frontend/src/plugins/impl/DataTablePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ export const LoadingDataTableComponent = memo(
{props.showChartBuilder ? (
<TablePanel
displayHeader={displayHeader}
data={data?.rows || []}
dataTable={dataTable}
getDataUrl={props.get_data_url}
fieldTypes={props.fieldTypes}
Expand Down
Loading