Skip to content

[MergeDups] Fix protection-override data-loss warning#3948

Merged
imnasnainaec merged 11 commits intomasterfrom
copilot/improve-data-loss-warning
Oct 27, 2025
Merged

[MergeDups] Fix protection-override data-loss warning#3948
imnasnainaec merged 11 commits intomasterfrom
copilot/improve-data-loss-warning

Conversation

Copy link
Contributor

Copilot AI commented Oct 16, 2025

  • Understand the issue and analyze the code
  • Identify the problem in MergeDragDrop/index.tsx
  • Refactor protectReason creation to be context-aware
  • Update Case 1a (delete): include both word and sense reasons
  • Update Case 2b (combine/merge): include both word and sense reasons
  • Update Case 3a (move): include only word reasons (sense is just moving)
  • Update Case 3b (reorder sidebar): include sense reasons only if displacing from top
  • Run lint and verify no issues (0 warnings)
  • Run all tests and verify they pass (593 tests passed)
  • Verify prettier formatting is correct
  • Address reviewer feedback: Remove unnecessary comments
  • Address reviewer feedback: Convert to TSDoc format
  • Address reviewer feedback: Use isProtectedSense variable for accuracy
  • Fix TypeScript compilation error
  • Simplify sidebar reorder logic (remove redundant condition check)
  • Verify build succeeds
  • Final verification complete

Summary

The protection-override data-loss warning is now context-aware and accurate:

  • Moving a sense: Only warns about word-level data loss (the sense is just moving, not being deleted)
  • Deleting a sense: Warns about sense data loss only if the sense itself is protected, and word data loss if it's the only sense in a protected word
  • Merging a sense: Warns about sense data loss only if the sense itself is protected, and word data loss if it's the only sense in a protected word
  • Reordering in sidebar: Warns about sense data loss when displacing the protected top sidebar sense

The fix uses clear boolean variables (isProtectedSense, isOnlySenseInProtectedWord) with TSDoc documentation that makes the code self-documenting and ensures warnings are shown only when relevant data will actually be lost. All checks pass including TypeScript compilation.

Original prompt

This section details on the original issue you should resolve

<issue_title>[MergeDups] Improve protection-override data-loss warning</issue_title>
<issue_description>When overriding word/sense protection, if you move a protected sense to a different word and it was the last sense in a protected word, a warning pops up listing what things will be lost. It lists things for both the word and sense even though the sense is just being moved. We need the warning to only include the sense details if the sense is being deleted, merged into another sense, or displaced from the top of the sidebar.

This will require changes in https://github.com/sillsdev/TheCombine/blob/master/src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/index.tsx to how protectReason is created and used.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #3904


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


This change is Reviewable

The warning now only includes:
- Sense reasons when deleting, merging, or displacing from sidebar top
- Word reasons when moving the last sense of a protected word
- Both when deleting or merging the last sense of a protected word

Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve protection-override data-loss warning Fix protection-override warning to only show relevant data loss Oct 16, 2025
Copilot AI requested a review from imnasnainaec October 16, 2025 16:54
Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

@imnasnainaec reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @copilot)


src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/index.tsx line 112 at r1 (raw file):

          // ... unless protection override is active and user confirms.
          // Include both sense and word reasons since the sense is being deleted.
          const protectReason = getProtectReason(true, true);

The added comment before each const protectReason = getProtectReason(... is unnecessary.

@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

❌ Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.21%. Comparing base (2ffef2a) to head (29980ed).
⚠️ Report is 39 commits behind head on master.

Files with missing lines Patch % Lines
...geDuplicates/MergeDupsStep/MergeDragDrop/index.tsx 0.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3948      +/-   ##
==========================================
- Coverage   74.26%   74.21%   -0.05%     
==========================================
  Files         291      291              
  Lines       10783    10790       +7     
  Branches     1349     1351       +2     
==========================================
  Hits         8008     8008              
- Misses       2389     2396       +7     
  Partials      386      386              
Flag Coverage Δ
backend 85.45% <ø> (ø)
frontend 65.53% <0.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

@imnasnainaec reviewed all commit messages....

Removed the unnecessary comments in commit bbc7d12.

imnasnainaec

This comment was marked as resolved.

Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @copilot)...

Converted to TSDoc format in commit f2cd742.

Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @copilot)


src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/index.tsx line 141 at r3 (raw file):

        if (overrideProtection) {
          // ... unless protection override is active and user confirms.
          const protectReason = getProtectReason(true, true);

When a protected sense is being deleted (Case 1a) or merged (Case 2b), you have

const protectReason = getProtectReason(true, true);

However, in both cases, it may be more accurate to have

const protectReason = getProtectReason(isProtectedSense, isOnlySenseInProtectedWord);

where isProtectedSense is defined to replace all instances of (src.isSenseProtected && !src.order).

Extract isProtectedSense from repeated expression and use it with
isOnlySenseInProtectedWord to determine which protection reasons to
include. This ensures sense reasons are only shown when the sense
itself is protected, not just when it's in a protected word.

Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @copilot)...

Implemented in commit 71f7340. Created isProtectedSense variable and used it with isOnlySenseInProtectedWord in Cases 1a and 2b for more accurate protection warnings.

@imnasnainaec
Copy link
Collaborator

@copilot Now two checks are failing.

Use double negation (!!) to ensure isProtectedSense is always a boolean
type rather than boolean | undefined, fixing the TypeScript compilation
error when passing it to getProtectReason.

Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

@copilot Now two checks are failing.

Fixed in commit ec63abf. The TypeScript compilation error was due to isProtectedSense potentially being undefined. Added double negation (!!) to ensure it's always a boolean type. Build and all tests now pass.

Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

@imnasnainaec reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @copilot)


src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/index.tsx line 207 at r5 (raw file):

          if (overrideProtection) {
            // ... unless protection override is active and user confirms.
            const protectReason = getProtectReason(fromTop, false);

The comment "being displaced" above corresponds to (fromTop || toTop), so getProtectReason(fromTop, false); needs to be fixed.

Use (fromTop || toTop) instead of just fromTop when calling getProtectReason
to correctly show sense protection reasons whenever the top sidebar sense is
being displaced, whether moving from top or to top.

Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 17, 2025

@imnasnainaec reviewed all commit messages....

Fixed in commit 1c880df. Changed getProtectReason(fromTop, false) to getProtectReason(fromTop || toTop, false) to correctly match the displacement condition (fromTop || toTop).

Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

@imnasnainaec reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @copilot)


src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/index.tsx line 207 at r5 (raw file):

Previously, imnasnainaec (D. Ror.) wrote…

The comment "being displaced" above corresponds to (fromTop || toTop), so getProtectReason(fromTop, false); needs to be fixed.

This line is inside an if ((fromTop || toTop) && sidebarProtected) loop, so is fromTop || toTop necessary in getProtectedReason?

Since we're inside if ((fromTop || toTop) && sidebarProtected), the
expression (fromTop || toTop) is always true, so we can simplify
getProtectReason(fromTop || toTop, false) to getProtectReason(true, false).

Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 17, 2025

@imnasnainaec reviewed all commit messages....

You're right. Since we're inside the if ((fromTop || toTop) && sidebarProtected) block, the expression is always true. Simplified to getProtectReason(true, false) in commit d8892c1.

@imnasnainaec imnasnainaec marked this pull request as ready for review October 17, 2025 16:08
@imnasnainaec imnasnainaec added the 🟩Low Low-priority PR label Oct 17, 2025
Copy link
Contributor

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

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

:lgtm:

@jasonleenaylor reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @copilot and @imnasnainaec)

Copy link
Collaborator

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

@imnasnainaec reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @copilot)

@imnasnainaec imnasnainaec enabled auto-merge (squash) October 27, 2025 21:11
@imnasnainaec imnasnainaec disabled auto-merge October 27, 2025 21:11
@imnasnainaec imnasnainaec changed the title Fix protection-override warning to only show relevant data loss [MergeDups] Fix protection-override data-loss warning Oct 27, 2025
@imnasnainaec imnasnainaec merged commit 0f13495 into master Oct 27, 2025
19 checks passed
@imnasnainaec imnasnainaec deleted the copilot/improve-data-loss-warning branch October 27, 2025 21:18
@imnasnainaec imnasnainaec added the bug Something isn't working label Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend goal: MergeDup 🟩Low Low-priority PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MergeDups] Improve protection-override data-loss warning

3 participants