Skip to content

Conversation

@artemmufazalov
Copy link
Member

@artemmufazalov artemmufazalov commented Nov 18, 2025

Part of #2892

Stand: https://nda.ya.ru/t/BEIjuuLI7N8Qd7

Goal: manipulate values from useSetting in hook instead of store with direct LS access

CI Results

Test Status: ⚠️ FLAKY

📊 Full Report

Total Passed Failed Flaky Skipped
378 372 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: 66.13 MB | Main: 66.13 MB
Diff: +1.47 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.

@artemmufazalov artemmufazalov changed the title refactor(QueriesHistory): move queries manipulations to hook fix(QueriesHistory): move queries manipulations to hook Nov 18, 2025
@artemmufazalov
Copy link
Member Author

greptile-review

Copilot finished reviewing on behalf of artemmufazalov November 18, 2025 19:50
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 refactors the queries history management by moving it from Redux store actions/reducers to a custom React hook (useQueriesHistory). The main goal is to use the useSetting hook for localStorage access instead of direct settingsManager calls, improving consistency with the project's architecture.

Key changes:

  • Created new useQueriesHistory hook that manages history state and operations
  • Removed Redux actions (saveQueryToHistory, updateQueryInHistory, goToPreviousQuery, goToNextQuery)
  • Modified query API to return queryStats for history updates in components
  • Updated components to consume the new hook instead of Redux selectors/actions

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/store/reducers/query/useQueriesHistory.ts New hook managing queries history with local state, replacing Redux store logic
src/store/reducers/query/types.ts Simplified state structure by removing nested history object; added QueryStats interface
src/store/reducers/query/query.ts Removed history-related actions/selectors and modified API to return queryStats
src/store/reducers/query/test/tabPersistence.test.tsx Updated test to reflect simplified QueryState structure
src/containers/Tenant/Query/QueryEditor/helpers.ts Updated to use useQueriesHistory hook instead of selector
src/containers/Tenant/Query/QueryEditor/YqlEditor.tsx Integrated useQueriesHistory hook for navigation functions
src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx Integrated hook and added promise handler to update history with query stats
src/containers/Tenant/Query/QueriesHistory/QueriesHistory.tsx Updated to use filteredHistoryQueries from hook with proper memoization
Comments suppressed due to low confidence (1)

src/containers/Tenant/Query/QueriesHistory/QueriesHistory.tsx:51

  • The applyQueryClick function is recreated on every render but is not wrapped in useCallback. According to the project's React performance guidelines, functions should be memoized with useCallback.

Since this function is passed to useChangeInputWithConfirmation, it should be memoized to prevent unnecessary re-renders:

const applyQueryClick = React.useCallback((query: QueryInHistory) => {
    changeUserInput({input: query.queryText});
    dispatch(setIsDirty(false));
    dispatch(setQueryTab(TENANT_QUERY_TABS_ID.newQuery));
}, [changeUserInput, dispatch]);
    const applyQueryClick = (query: QueryInHistory) => {
        changeUserInput({input: query.queryText});
        dispatch(setIsDirty(false));
        dispatch(setQueryTab(TENANT_QUERY_TABS_ID.newQuery));
    };

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

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

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

@artemmufazalov artemmufazalov marked this pull request as ready for review November 19, 2025 21:56
@Raubzeug
Copy link
Contributor

@greptile-review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

8 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

const [historyQueries, setQueries] = React.useState<QueryInHistory[]>([]);
const [historyCurrentIndex, setCurrentIndex] = React.useState(-1);

React.useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to check this before saving (not in useEffect)?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can receive undefined value from meta, if setting was never set before, so this condition is needed to migrate safely after.

As for setting or updating value, it will be always valid and defined, since I create new value based on current, and current value should be always valid because of this useEffect

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed in PM to get rid of this effect. Also agreed recalculate actual values and slice over limit queries in handlers

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.

3 participants