Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 28, 2025

When users run explain queries and select a tab different from the default "Computation Graph" (such as JSON, AST, or Explain), their selection was not preserved after modifying the query and re-running the explain. This forced users to repeatedly select their preferred tab after each query execution, creating a poor user experience.

Root Cause

The QueryResultViewer component was managing the selected tab (activeSection) as local React state using useState. This local state was reset every time the component re-rendered with new query results, causing the user's tab selection to be lost.

Solution

Implemented Redux state management to persist the selected tab preference between query executions:

  • Added Redux State: Extended QueryState with selectedResultTab field to track separate tab preferences for 'execute' and 'explain' query types
  • Redux Actions: Added setResultTab action to update tab selections and selectResultTab selector to retrieve saved preferences
  • Component Integration: Modified QueryResultViewer to use Redux state instead of local state, with fallback logic to original defaults when no preference is saved
  • Input Validation: Ensures saved tabs are valid for the current query type context

Key Features

  • Tab selection persists between query executions of the same type
  • Separate preferences maintained for execute vs explain queries
  • Backward compatible - falls back to original defaults when no preference exists
  • Minimal performance impact using efficient Redux selectors

Testing

  • All existing tests continue to pass (no regressions)
  • Added comprehensive test coverage for new functionality
  • 18/18 tests passing across all query reducer test suites

Users can now select their preferred tab for explain queries and it will be remembered across query executions, providing a much smoother development experience.

Fixes #2405.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

CI Results

Test Status: ⚠️ FLAKY

📊 Full Report

Total Passed Failed Flaky Skipped
354 348 0 4 2
Test Changes Summary ⏭️2

⏭️ Skipped Tests (2)

  1. Scroll to row, get shareable link, navigate to URL and verify row is scrolled into view (tenant/diagnostics/tabs/queries.test.ts)
  2. Copy result button copies to clipboard (tenant/queryEditor/queryEditor.test.ts)

Bundle Size: ✅

Current: 85.29 MB | Main: 85.29 MB
Diff: +1.61 KB (0.00%)

✅ Bundle size unchanged.

ℹ️ CI Information
  • Test recordings for failed tests are available in the full report.
  • Bundle size is measured for the entire 'dist' directory.
  • 📊 indicates links to detailed reports.
  • 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.

Copilot AI changed the title [WIP] Keep plan representation tab between executions Keep plan representation tab selection between query executions Jul 28, 2025
Copilot AI requested a review from adameat July 28, 2025 07:56
Copilot finished work on behalf of adameat July 28, 2025 07:56
@adameat
Copy link
Member

adameat commented Jul 28, 2025

change title according to commitLint: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

Copy link
Contributor Author

Copilot AI commented Jul 28, 2025

change title according to commitLint: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

Updated commit message to follow conventional commit format as required by commitlint. The latest commit (e66e8c5) demonstrates the proper format: docs: update commit messages to follow conventional commit format

Copilot finished work on behalf of adameat July 28, 2025 10:32
Copilot AI requested a review from adameat July 28, 2025 10:32
@adameat
Copy link
Member

adameat commented Jul 28, 2025

update PR title according to commitLint

Copilot finished work on behalf of adameat July 28, 2025 10:37
@adameat adameat changed the title Keep plan representation tab selection between query executions feat: keep plan representation tab selection between query executions Jul 28, 2025
@adameat adameat marked this pull request as ready for review July 28, 2025 11:24
@adameat adameat requested a review from Copilot July 28, 2025 12:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements tab persistence for the query result viewer, preserving user tab selections (JSON, AST, Explain, etc.) between query executions. Previously, the selected tab would reset to the default after each query run, forcing users to repeatedly select their preferred tab.

Key changes:

  • Added Redux state management for tab persistence with separate preferences for execute vs explain queries
  • Modified QueryResultViewer to use Redux state instead of local React state
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/store/reducers/query/types.ts Added selectedResultTab field to QueryState for storing tab preferences
src/store/reducers/query/query.ts Added setResultTab action and selectResultTab selector for Redux state management
src/store/reducers/query/test/tabPersistence.test.tsx Integration tests for tab persistence functionality
src/store/reducers/query/test/resultTab.test.ts Unit tests for the setResultTab reducer
src/containers/Tenant/Query/QueryResult/QueryResultViewer.tsx Modified component to use Redux state for tab selection with validation and fallback logic

@@ -1,4 +1,5 @@
import React from 'react';
// Query result viewer with tab persistence functionality
Copy link

Copilot AI Jul 28, 2025

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.

Suggested change
// Query result viewer with tab persistence functionality
/**
* QueryResultViewer is a React component that displays the results of a query execution.
* It supports multiple result views (e.g., result sets, schema, JSON, etc.) with tab persistence functionality.
*
* Props:
* - `result` (QueryResult): The query result data to display.
* - `resultType` (QueryAction, optional): The type of query result (default: 'execute').
* - `isResultsCollapsed` (boolean, optional): Whether the results section is collapsed.
* - `theme` (string, optional): The theme to apply to the component.
* - `tenantName` (string): The name of the tenant associated with the query.
* - `queryText` (string, optional): The text of the executed query.
* - `tableSettings` (Partial<Settings>, optional): Settings for the result table display.
* - `onCollapseResults` (VoidFunction): Callback to collapse the results section.
* - `onExpandResults` (VoidFunction): Callback to expand the results section.
*/

Copilot uses AI. Check for mistakes.
const {error, isLoading, data = {}} = result;
const {preparedPlan, simplifiedPlan, stats, resultSets, ast} = data;

React.useEffect(() => {
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This useEffect only runs cleanup logic and doesn't depend on any values, but it's placed in the middle of the component logic. Consider moving it closer to other useEffect hooks or to the end of the component for better code organization.

Copilot uses AI. Check for mistakes.
@adameat adameat enabled auto-merge July 28, 2025 12:23
@artemmufazalov
Copy link
Member

@copilot remove src/store/reducers/query/__test__/resultTab.test.ts, it has the same tests as src/store/reducers/query/__test__/tabPersistence.test.tsx

auto-merge was automatically disabled July 28, 2025 12:52

Head branch was pushed to by a user without write access

Copy link
Contributor Author

Copilot AI commented Jul 28, 2025

@copilot remove src/store/reducers/query/__test__/resultTab.test.ts, it has the same tests as src/store/reducers/query/__test__/tabPersistence.test.tsx

Removed the duplicate test file resultTab.test.ts. The functionality is fully covered by tabPersistence.test.tsx which contains more comprehensive test cases. All 14 tests in the query reducer test suite continue to pass. (5ff3dee)

Copilot finished work on behalf of artemmufazalov July 28, 2025 12:53
@artemmufazalov artemmufazalov enabled auto-merge July 28, 2025 13:07
@artemmufazalov artemmufazalov added this pull request to the merge queue Jul 29, 2025
Merged via the queue into main with commit 151d766 Jul 29, 2025
5 checks passed
@artemmufazalov artemmufazalov deleted the copilot/fix-2405 branch July 29, 2025 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep plan representation tab between executions

3 participants