-
Notifications
You must be signed in to change notification settings - Fork 17
fix(QueriesHistory): move queries manipulations to hook #3103
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
base: main
Are you sure you want to change the base?
Conversation
b341ea7 to
9d4d454
Compare
|
greptile-review |
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.
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
useQueriesHistoryhook that manages history state and operations - Removed Redux actions (
saveQueryToHistory,updateQueryInHistory,goToPreviousQuery,goToNextQuery) - Modified query API to return
queryStatsfor 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
applyQueryClickfunction is recreated on every render but is not wrapped inuseCallback. According to the project's React performance guidelines, functions should be memoized withuseCallback.
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));
};
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
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.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
b1399ce to
1f2e37e
Compare
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.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
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.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
|
@greptile-review |
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.
8 files reviewed, no comments
| const [historyQueries, setQueries] = React.useState<QueryInHistory[]>([]); | ||
| const [historyCurrentIndex, setCurrentIndex] = React.useState(-1); | ||
|
|
||
| React.useEffect(() => { |
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.
is it possible to check this before saving (not in useEffect)?
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.
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
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.
Agreed in PM to get rid of this effect. Also agreed recalculate actual values and slice over limit queries in handlers
Part of #2892
Stand: https://nda.ya.ru/t/BEIjuuLI7N8Qd7
Goal: manipulate values from
useSettingin hook instead of store with direct LS accessCI Results
Test Status:⚠️ FLAKY
📊 Full Report
Test Changes Summary ⏭️2
⏭️ Skipped Tests (2)
Bundle Size: ✅
Current: 66.13 MB | Main: 66.13 MB
Diff: +1.47 KB (0.00%)
✅ Bundle size unchanged.
ℹ️ CI Information