-
Notifications
You must be signed in to change notification settings - Fork 17
feat: keep plan representation tab selection between query executions #2625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
310514f
Initial plan
Copilot ce3435f
Add Redux state to persist selected tab between query executions
Copilot b1495c3
Add comprehensive tests for tab persistence functionality
Copilot 221a853
Fix TypeScript types in tab persistence tests
Copilot e66e8c5
docs: update commit messages to follow conventional commit format
Copilot bd8c60b
Merge branch 'main' into copilot/fix-2405
adameat 5ff3dee
refactor: remove duplicate test file resultTab.test.ts
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import React from 'react'; | ||
| // Query result viewer with tab persistence functionality | ||
|
|
||
| import type {Settings} from '@gravity-ui/react-data-table'; | ||
| import type {ControlGroupOption} from '@gravity-ui/uikit'; | ||
|
|
@@ -10,13 +11,14 @@ import {Illustration} from '../../../../components/Illustration'; | |
| import {LoaderWrapper} from '../../../../components/LoaderWrapper/LoaderWrapper'; | ||
| import {QueryExecutionStatus} from '../../../../components/QueryExecutionStatus'; | ||
| import {disableFullscreen} from '../../../../store/reducers/fullscreen'; | ||
| import {selectResultTab, setResultTab} from '../../../../store/reducers/query/query'; | ||
| import type {QueryResult} from '../../../../store/reducers/query/types'; | ||
| import type {ValueOf} from '../../../../types/common'; | ||
| import type {QueryAction} from '../../../../types/store/query'; | ||
| import {cn} from '../../../../utils/cn'; | ||
| import {USE_SHOW_PLAN_SVG_KEY} from '../../../../utils/constants'; | ||
| import {getStringifiedData} from '../../../../utils/dataFormatters/dataFormatters'; | ||
| import {useSetting, useTypedDispatch} from '../../../../utils/hooks'; | ||
| import {useSetting, useTypedDispatch, useTypedSelector} from '../../../../utils/hooks'; | ||
| import {PaneVisibilityToggleButtons} from '../../utils/paneVisibilityToggleHelpers'; | ||
| import {QuerySettingsBanner} from '../QuerySettingsBanner/QuerySettingsBanner'; | ||
| import {QueryStoppedBanner} from '../QueryStoppedBanner/QueryStoppedBanner'; | ||
|
|
@@ -98,27 +100,43 @@ export function QueryResultViewer({ | |
| onExpandResults, | ||
| }: ExecuteResultProps) { | ||
| const dispatch = useTypedDispatch(); | ||
| const selectedTabs = useTypedSelector(selectResultTab); | ||
|
|
||
| const isExecute = resultType === 'execute'; | ||
| const isExplain = resultType === 'explain'; | ||
|
|
||
| const [selectedResultSet, setSelectedResultSet] = React.useState(0); | ||
| const [activeSection, setActiveSection] = React.useState<SectionID>(() => { | ||
| return isExecute ? RESULT_OPTIONS_IDS.result : RESULT_OPTIONS_IDS.schema; | ||
| }); | ||
| const [useShowPlanToSvg] = useSetting<boolean>(USE_SHOW_PLAN_SVG_KEY); | ||
|
|
||
| // Get the saved tab for the current query type, or use default | ||
| const getDefaultSection = (): SectionID => { | ||
| return isExecute ? RESULT_OPTIONS_IDS.result : RESULT_OPTIONS_IDS.schema; | ||
| }; | ||
|
|
||
| const activeSection: SectionID = React.useMemo(() => { | ||
| const savedTab = selectedTabs?.[resultType]; | ||
| if (savedTab) { | ||
| // Validate that the saved tab is valid for the current result type | ||
| const validSections = isExecute ? EXECUTE_SECTIONS : EXPLAIN_SECTIONS; | ||
| if (validSections.includes(savedTab as SectionID)) { | ||
| return savedTab as SectionID; | ||
| } | ||
| } | ||
| return getDefaultSection(); | ||
| }, [selectedTabs, resultType, isExecute]); | ||
|
|
||
| const {error, isLoading, 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]); | ||
| return () => { | ||
| dispatch(disableFullscreen()); | ||
| }; | ||
| }, [dispatch]); | ||
|
|
||
| const onSelectSection = (value: SectionID) => { | ||
| dispatch(setResultTab({queryType: resultType, tabId: value})); | ||
| }; | ||
|
|
||
| const radioButtonOptions: ControlGroupOption<SectionID>[] = React.useMemo(() => { | ||
| let sections: SectionID[] = []; | ||
|
|
@@ -137,16 +155,6 @@ export function QueryResultViewer({ | |
| }); | ||
| }, [isExecute, isExplain]); | ||
|
|
||
| React.useEffect(() => { | ||
| return () => { | ||
| dispatch(disableFullscreen()); | ||
| }; | ||
| }, [dispatch]); | ||
|
|
||
| const onSelectSection = (value: SectionID) => { | ||
| setActiveSection(value); | ||
| }; | ||
|
|
||
| const getStatsToCopy = () => { | ||
| switch (activeSection) { | ||
| case RESULT_OPTIONS_IDS.result: { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import queryReducer, {setResultTab} from '../query'; | ||
| import type {QueryState} from '../types'; | ||
|
|
||
| describe('QueryResultViewer tab persistence integration', () => { | ||
| const initialState: QueryState = { | ||
| input: '', | ||
| history: { | ||
| queries: [], | ||
| currentIndex: -1, | ||
| }, | ||
| }; | ||
|
|
||
| it('should save and retrieve tab selection for explain queries', () => { | ||
| // Test that we can set and get the tab preference | ||
| let state = queryReducer(initialState, setResultTab({queryType: 'explain', tabId: 'json'})); | ||
|
|
||
| expect(state.selectedResultTab).toEqual({ | ||
| explain: 'json', | ||
| }); | ||
|
|
||
| // Test updating the same query type | ||
| state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'ast'})); | ||
|
|
||
| expect(state.selectedResultTab).toEqual({ | ||
| explain: 'ast', | ||
| }); | ||
| }); | ||
|
|
||
| it('should save and retrieve tab selection for execute queries', () => { | ||
| const state = queryReducer( | ||
| initialState, | ||
| setResultTab({queryType: 'execute', tabId: 'stats'}), | ||
| ); | ||
|
|
||
| expect(state.selectedResultTab).toEqual({ | ||
| execute: 'stats', | ||
| }); | ||
| }); | ||
|
|
||
| it('should maintain separate preferences for different query types', () => { | ||
| let state = initialState; | ||
|
|
||
| // Set explain tab | ||
| state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'json'})); | ||
| expect(state.selectedResultTab).toEqual({ | ||
| explain: 'json', | ||
| }); | ||
|
|
||
| // Set execute tab - should not override explain | ||
| state = queryReducer(state, setResultTab({queryType: 'execute', tabId: 'stats'})); | ||
| expect(state.selectedResultTab).toEqual({ | ||
| explain: 'json', | ||
| execute: 'stats', | ||
| }); | ||
|
|
||
| // Update explain tab - should not affect execute | ||
| state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'ast'})); | ||
| expect(state.selectedResultTab).toEqual({ | ||
| explain: 'ast', | ||
| execute: 'stats', | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle multiple updates to the same query type', () => { | ||
| let state = initialState; | ||
|
|
||
| // Set initial value | ||
| state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'schema'})); | ||
| expect(state.selectedResultTab?.explain).toBe('schema'); | ||
|
|
||
| // Update to different tab | ||
| state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'json'})); | ||
| expect(state.selectedResultTab?.explain).toBe('json'); | ||
|
|
||
| // Update again | ||
| state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'ast'})); | ||
| expect(state.selectedResultTab?.explain).toBe('ast'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This single-line comment doesn't add meaningful documentation value. Consider either removing it or expanding it into a proper JSDoc comment that explains the component's purpose, props, and key functionality.