CLUE-525: Edit button appears on the left toolbar for any document the user can edit - #2930
Conversation
… group) Extract the edit-button visibility fix that had been folded into the CLUE-550 (Driving Question Board) branch. In the Sort Work document area, show the Edit button not only for the user's own documents but also for their own group's document (a group doc created by any member of the user's group), so any document the user can actually edit exposes the Edit affordance. This is the CLUE-525 change on its own, without the CLUE-550 DQB work it had been entangled with. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Source showEdit's uid/type/groupId from the document metadata (which is kept in sync by Firestore listeners) rather than the lazily-fetched full document. For a group document created by another group member, the full document's groupId can be undefined until it finishes loading, which previously left the Edit button hidden until the view was reloaded. The metadata carries these fields reactively, so the button now appears as soon as the document syncs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pull the Sort Work Edit-button visibility rule into a pure canEditSortWorkDocument predicate and cover it with a truth table: own doc, own-group doc (incl. created by another group member), another group's doc, another student's doc, no-group user, both-undefined guard, and the metadata-sourced group-id path that the reactive fix relies on. The component now calls the helper with metadata-preferred fields; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2930 +/- ##
===========================================
- Coverage 85.00% 69.33% -15.67%
===========================================
Files 957 952 -5
Lines 54527 54511 -16
Branches 14357 14359 +2
===========================================
- Hits 46348 37794 -8554
- Misses 8161 16683 +8522
- Partials 18 34 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
collaborative-learning
|
||||||||||||||||||||||||||||
| Project |
collaborative-learning
|
| Branch Review |
CLUE-525-edit-button-should-appear-on-left-toolbar-when-user-can-edit
|
| Run status |
|
| Run duration | 03m 39s |
| Commit |
|
| Committer | Scott Cytacki |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
4
|
| View all changes introduced in this branch ↗︎ | |
There was a problem hiding this comment.
Pull request overview
Updates Sort Work’s left-pane toolbar logic so the Edit button appears for any document the current user can edit (their own documents and their group’s documents), and makes the visibility reactive by preferring Firestore-synced document metadata over the lazily-fetched full document.
Changes:
- Added a pure
canEditSortWorkDocument()predicate for Sort Work edit-button visibility. - Updated
SortWorkDocumentAreato computeshowEditfrom reactive metadata (with full-document fallback). - Added a Jest truth-table style unit test suite for the new predicate.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/document/sort-work-edit-permission.ts | Introduces the canEditSortWorkDocument predicate to centralize “own doc or own-group doc” edit visibility rules. |
| src/components/document/sort-work-edit-permission.test.ts | Adds unit tests covering key permission cases for the new predicate. |
| src/components/document/sort-work-document-area.tsx | Switches Edit-button visibility from “owned only” to the new predicate, preferring reactive metadata fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it("recognizes an own-group doc purely from the group id (metadata-sourced)", () => { | ||
| expect(canEditSortWorkDocument({ | ||
| docUid: "student-2", docType: GroupDocument, docGroupId: myGroup, userId: me, userGroupId: myGroup | ||
| })).toBe(true); | ||
| }); |
Put the "can this user edit this document?" question beside its sibling
"can this user see this document?" (isDocumentAccessibleToUser), which the
Sort Work document area calls two lines above it.
- Move src/components/document/sort-work-edit-permission.ts into
src/models/document/document-utils.ts and rename the export to
canUserEditDocument. The rule isn't Sort-Work-specific.
- Take { document, documentMetadata, user } instead of five loose
primitives, mirroring isDocumentAccessibleToUser. This pulls the
metadata-preferring merge inside the function, where it can be tested:
the merge is what makes the button appear as soon as a groupmate's
document syncs, and it was previously spelled out at the call site and
therefore outside the tested unit.
- Name the type check isCollaborativeDoc, since what it really asks is
whether the document is multi-writer. Note that the check is
load-bearing: problem documents also carry a groupId, so dropping it
would make a groupmate's problem document editable.
Behavior is unchanged. All seven predicate test cases move into
document-utils.test.ts, joined by one covering the document-fallback path
and one asserting the per-field metadata preference.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Pushed a follow-up that relocates and reshapes the predicate. No behavior change — same truth table, same call site semantics. 1. Moved and renamed: "Can this user edit this document?" is a model-level permission question. Its sibling — "can this user see this document?" — is already 2. Takes const showEdit = canUserEditDocument({
document: openDocument, documentMetadata: openDocumentMetadata, user
});This matters beyond tidiness: the metadata-preferring merge is the interesting part of the fix, and it was previously outside the tested unit. The reactivity bug this PR fixes lives in the "prefer metadata, fall back to the document" merge. With the merge spelled out at the call site, the unit test could only assert the truth table over already-merged values. Inside the function it's directly testable — there's now a case passing a 3. Named the axis test: That expression isn't really asking "is this a group document" for its own sake — it's asking "is this a multi-writer document that people other than its owner may edit." Worth noting for future readers: the type check is load-bearing. Problem documents also carry a Not changed here: the resources-pane edit gate at Type note: the Verification: |
scytacki
left a comment
There was a problem hiding this comment.
@lbondaryk I revised this so it is compatible with the PRs I'm working on. Please test it to make sure it is still working before you merge.
What & why
The Edit button in the Sort Work left-pane toolbar only appeared for documents the user owned (
openDocument?.uid === user.id). It should appear for any document the user can edit — including their own group's document (a group doc created by any member of their group).This fix had originally been written for CLUE-525 but got folded into the CLUE-550 (Driving Question Board) branch and never landed on
masteron its own. This PR extracts just the CLUE-525 change onto a clean branch, drops the DQB-specific bits (which belong to CLUE-550), and fixes a reactivity bug in it.Changes
sort-work-document-area.tsx): show Edit when the doc is the user's own or their own group's document.groupIdcould be undefined until it finished loading, so the Edit button stayed hidden until the view was reloaded. The metadata carries these fields reactively, so the button now appears as soon as the doc syncs — no reload. (This mirrors howisDocumentAccessibleToUser/isVisiblein this same component already prefers metadata for the same reason.)canEditSortWorkDocumentpredicate with a truth-table unit test (own doc, own-group doc incl. created by a groupmate, another group's doc, another student's doc, no-group user, both-undefined guard, and the metadata-sourced group-id path that the reactive fix relies on).Testing
canEditSortWorkDocumentunit tests pass (7 cases);tsc+ lint clean.🤖 Generated with Claude Code