Skip to content
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

fix: unsaved changes in query editor #2026

Merged
merged 9 commits into from
Mar 20, 2025
Merged

fix: unsaved changes in query editor #2026

merged 9 commits into from
Mar 20, 2025

Conversation

astandrik
Copy link
Collaborator

@astandrik astandrik commented Mar 18, 2025

Closes #1984

CI Results

Test Status: ✅ PASSED

📊 Full Report

Total Passed Failed Flaky Skipped
278 277 0 0 1
Test Changes Summary ✨7 ⏭️1

✨ New Tests (7)

  1. No unsaved changes modal when running a query and selecting from history (tenant/queryHistory/queryHistory.test.ts)
  2. No unsaved changes modal when running a query that is identical to last in history (tenant/queryHistory/queryHistory.test.ts)
  3. Unsaved changes modal appears when modifying a query and selecting from history (tenant/queryHistory/queryHistory.test.ts)
  4. No unsaved changes modal when selecting from history after saving a query (tenant/queryHistory/queryHistory.test.ts)
  5. No unsaved changes modal when opening another query after saving (tenant/savedQueries/savedQueries.test.ts)
  6. Unsaved changes modal appears when selecting a saved query after modifications (tenant/savedQueries/savedQueries.test.ts)
  7. No unsaved changes modal when switching from saved query to another query (tenant/savedQueries/savedQueries.test.ts)

⏭️ Skipped Tests (1)

  1. Streaming query shows some results and banner when stop button is clicked (tenant/queryEditor/queryEditor.test.ts)

Bundle Size: ✅

Current: 83.22 MB | Main: 83.22 MB
Diff: +1.75 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.

Copy link

@Copilot 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 addresses unsaved changes in the query editor by updating the changeUserInput function signature and its usages across multiple components to accept an optional isDirty flag.

  • Updated the changeUserInput interface in several components (QueriesHistory, SavedQueries, Query, QueryEditor, YqlEditor, TopQueries) to include an optional isDirty property.
  • Modified calls to changeUserInput to explicitly set isDirty to false or true as needed.
  • Updated the query reducer and related selectors to incorporate the isDirty state.

Reviewed Changes

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

Show a summary per file
File Description
src/containers/Tenant/Query/QueriesHistory/QueriesHistory.tsx Updated changeUserInput interface and applyQueryClick to pass isDirty flag.
src/containers/Tenant/Query/SavedQueries/SavedQueries.tsx Modified changeUserInput interface and applyQueryClick to include isDirty flag.
src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TopQueries.tsx Updated dispatch of changeUserInput to pass isDirty flag.
src/containers/Tenant/Query/Query.tsx Adjusted handleUserInputChange to accept isDirty flag.
src/store/reducers/query/query.ts Updated changeUserInput reducer and selectors to handle the new isDirty property.
src/containers/Tenant/Diagnostics/TopQueries/TopQueries.tsx Updated dispatch of changeUserInput to include isDirty flag.
src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx Updated changeUserInput in props to include isDirty flag.
src/containers/Tenant/Query/QueryEditor/YqlEditor.tsx Updated keybinding and onChange calls to pass isDirty flag.
src/store/reducers/query/types.ts Updated QueryState interface to include isDirty property.
src/utils/hooks/withConfirmation/useChangeInputWithConfirmation.tsx Modified hook to include selectIsDirty and adjust behavior accordingly.

@astandrik astandrik requested a review from Copilot March 18, 2025 15:55

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 fixes an issue where unsaved changes in the query editor were not properly handled by adding a new isDirty flag and updating confirmation logic. Key changes include:

  • Updating the confirmation hook to only trigger when there are unsaved changes.
  • Dispatching setIsDirty updates across various query-related components.
  • Adding the isDirty flag to the query state and its corresponding reducer and selectors.

Reviewed Changes

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

Show a summary per file
File Description
src/utils/hooks/withConfirmation/useChangeInputWithConfirmation.tsx Modified to check both userInput and isDirty before triggering confirmation.
src/containers/Tenant/Diagnostics/TenantCpu/TopQueries.tsx Added dispatch(setIsDirty(false)) to reset dirty status on query selection.
src/containers/Tenant/Query/QueryEditor/YqlEditor.tsx Replaced snippet insertion logic with changeUserInput and setIsDirty update.
src/containers/Tenant/Diagnostics/TopQueries/TopQueries.tsx Reset the dirty flag upon user query selection.
src/containers/Tenant/ObjectSummary/SchemaTree/SchemaTree.tsx Updated confirmation trigger condition to include isDirty.
src/containers/Tenant/Query/QueriesHistory/QueriesHistory.tsx Reset the dirty flag upon selecting a query from history.
src/containers/Tenant/Query/SavedQueries/SavedQueries.tsx Reset the dirty flag when a saved query is applied.
src/store/reducers/query/types.ts and src/store/reducers/query/query.ts Introduced the isDirty state field with corresponding reducer and selectors.
Comments suppressed due to low confidence (2)

src/containers/Tenant/Query/QueryEditor/YqlEditor.tsx:96

  • The original snippet insertion logic using the snippetController2 has been removed and replaced by a changeUserInput call. Confirm that this behavior is intentional and that no functionality relying on snippet insertion will be affected.
changeUserInput({input});

src/store/reducers/query/query.ts:50

  • [nitpick] Consider providing an explicit default value for the newly added isDirty property in the query state to ensure consistent behavior across the application.
const slice = createSlice({
@artemmufazalov
Copy link
Member

You should also setIsDirty(false) on save query

Probably it should be here (but it's better to check): https://github.com/ydb-platform/ydb-embedded-ui/blob/main/src/store/reducers/queryActions/queryActions.ts#L77

Or maybe in Save query dialog itself

@astandrik
Copy link
Collaborator Author

@artemmufazalov fixed

@@ -173,6 +174,7 @@ export default function QueryEditor(props: QueryEditorProps) {
if (!partial) {
if (text !== historyQueries[historyCurrentIndex]?.queryText) {
dispatch(saveQueryToHistory({queryText: text, queryId}));
dispatch(setIsDirty(false));
Copy link
Member

Choose a reason for hiding this comment

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

If I run some query twice, for the second run it won't be saved in history again and confirmation will be shown. This row should be if(!partial) block

@astandrik astandrik added this pull request to the merge queue Mar 20, 2025
Merged via the queue into main with commit d1d64f7 Mar 20, 2025
7 checks passed
@astandrik astandrik deleted the astandrik.1984 branch March 20, 2025 10:36
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.

Confirmation modal "You have unsaved changes in query editor" is annoying
2 participants