Skip to content

Commit

Permalink
[explore] Prevent duplicated query by data table (apache#12404)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace Guo authored and amitmiran137 committed Jan 14, 2021
1 parent 404bd0b commit 8334093
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 19 additions & 7 deletions superset-frontend/src/explore/components/DataTablesPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,21 @@ export const DataTablesPane = ({
queryFormData,
tableSectionHeight,
onCollapseChange,
chartStatus,
}: {
queryFormData: Record<string, any>;
tableSectionHeight: number;
onCollapseChange: (openPanelName: string) => void;
chartStatus: string;
}) => {
const [data, setData] = useState<{
[RESULT_TYPES.results]?: Record<string, any>[];
[RESULT_TYPES.samples]?: Record<string, any>[];
}>(NULLISH_RESULTS_STATE);
const [isLoading, setIsLoading] = useState(NULLISH_RESULTS_STATE);
const [isLoading, setIsLoading] = useState({
[RESULT_TYPES.results]: true,
[RESULT_TYPES.samples]: true,
});
const [error, setError] = useState(NULLISH_RESULTS_STATE);
const [filterText, setFilterText] = useState('');
const [activeTabKey, setActiveTabKey] = useState<string>(
Expand Down Expand Up @@ -150,11 +155,18 @@ export const DataTablesPane = ({

useEffect(() => {
if (panelOpen && isRequestPending[RESULT_TYPES.results]) {
setIsRequestPending(prevState => ({
...prevState,
[RESULT_TYPES.results]: false,
}));
getData(RESULT_TYPES.results);
if (chartStatus === 'loading') {
setIsLoading(prevIsLoading => ({
...prevIsLoading,
[RESULT_TYPES.results]: true,
}));
} else {
setIsRequestPending(prevState => ({
...prevState,
[RESULT_TYPES.results]: false,
}));
getData(RESULT_TYPES.results);
}
}
if (
panelOpen &&
Expand All @@ -167,7 +179,7 @@ export const DataTablesPane = ({
}));
getData(RESULT_TYPES.samples);
}
}, [panelOpen, isRequestPending, getData, activeTabKey]);
}, [panelOpen, isRequestPending, getData, activeTabKey, chartStatus]);

const filteredData = {
[RESULT_TYPES.results]: useFilteredTableData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const ExploreChartPanel = props => {
queryFormData={props.chart.latestQueryFormData}
tableSectionHeight={tableSectionHeight}
onCollapseChange={onCollapseChange}
chartStatus={props.chart.chartStatus}
/>
</Split>
)}
Expand Down

0 comments on commit 8334093

Please sign in to comment.