Skip to content

Commit

Permalink
fix: fix tabs on empty results
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov committed Nov 22, 2024
1 parent 1222fc2 commit e72751d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/containers/Tenant/Query/QueryResult/QueryResultViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const RESULT_OPTIONS_TITLES: Record<SectionID, string> = {
},
};

const EXECUTE_SECTIONS: SectionID[] = ['result', 'schema', 'simplified', 'stats'];
const EXPLAIN_SECTIONS: SectionID[] = ['schema', 'json', 'simplified', 'ast'];

interface ExecuteResultProps {
result: QueryResult;
resultType?: QueryAction;
Expand Down Expand Up @@ -105,23 +108,22 @@ export function QueryResultViewer({
const {error, isLoading, queryId, data = {}} = result;
const {preparedPlan, simplifiedPlan, stats, resultSets, ast} = data;

React.useEffect(() => {
if (resultType === 'execute' && !EXECUTE_SECTIONS.includes(activeSection)) {
setActiveSection('result');
}
if (resultType === 'explain' && !EXPLAIN_SECTIONS.includes(activeSection)) {
setActiveSection('schema');
}
}, [activeSection, resultType]);

const radioButtonOptions: ControlGroupOption<SectionID>[] = React.useMemo(() => {
const sections: SectionID[] = [];
let sections: SectionID[] = [];

if (isExecute) {
sections.push('result');

if (preparedPlan) {
sections.push('schema');
}
if (simplifiedPlan?.plan) {
sections.push('simplified');
}
if (stats) {
sections.push('stats');
}
sections = EXECUTE_SECTIONS;
} else if (isExplain) {
sections.push('schema', 'json', 'simplified', 'ast');
sections = EXPLAIN_SECTIONS;
}

return sections.map((section) => {
Expand All @@ -130,7 +132,7 @@ export function QueryResultViewer({
content: RESULT_OPTIONS_TITLES[section],
};
});
}, [isExecute, isExplain, preparedPlan, simplifiedPlan?.plan, stats]);
}, [isExecute, isExplain]);

React.useEffect(() => {
return () => {
Expand Down Expand Up @@ -214,8 +216,8 @@ export function QueryResultViewer({
}
return <QueryJSONViewer data={preparedPlan?.pristine} />;
}
if (activeSection === RESULT_OPTIONS_IDS.simplified && simplifiedPlan?.plan) {
if (!simplifiedPlan?.plan) {
if (activeSection === RESULT_OPTIONS_IDS.simplified) {
if (!simplifiedPlan?.plan?.length) {
return renderStubMessage();
}
return <SimplifiedPlan plan={simplifiedPlan.plan} />;
Expand Down

0 comments on commit e72751d

Please sign in to comment.