Skip to content

Optimistic updates when adding/removing documents from projects - #1404

Open
dnass wants to merge 8 commits into
mainfrom
895-move-to-project
Open

dnass wants to merge 8 commits into
mainfrom
895-move-to-project

Conversation

@dnass

@dnass dnass commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Closes #895. When a project is created via the Move to Project form, the selected documents are immediately added to the new project. The document list UI is also updated immediately when documents are bulk added to or removed from a project.

Introduces a new applyEdits util that reduces edited.update boilerplate and enables greater flexibility for patching the store after documents are edited.

Also fixes a bug where checking a project in the form would throw an error if one of the selected documents was already in that project.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Preview deployed: https://preview-1404.staging.documentcloud.org

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 50.7% 3896 / 7683
🔵 Statements 49.11% 4531 / 9225
🔵 Functions 43.9% 1448 / 3298
🔵 Branches 47.75% 1978 / 4142
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/lib/api/documents.ts 86.01% 82.85% 94.28% 87.05% 102-112, 184-185, 194, 212-216, 225, 509, 532-534, 719
src/lib/components/forms/ChangeOwner.svelte 65.07% 56.09% 79.31% 63.79% 99, 149-150, 158, 164-202, 235
src/lib/components/forms/Edit.svelte 0% 0% 0% 0% 76-118
src/lib/components/forms/EditAccess.svelte 0% 0% 0% 0% 71-112
src/lib/components/forms/EditMany.svelte 0% 0% 0% 0% 77-163
src/lib/components/forms/Projects.svelte 0% 0% 0% 0% 73-202
src/lib/components/sidebar/DocumentActions.svelte 59.37% 41.66% 60.46% 57.69% 108-130, 138, 148, 158, 168, 178, 190, 200, 209-219, 208
src/lib/components/viewer/PDF.svelte 71.42% 50% 77.27% 61.11% 39, 42-49, 54, 62-71, 96-95
src/lib/state/search.svelte.ts 81.03% 72.22% 89.28% 83.17% 93-108, 196-205, 218, 219, 220
src/lib/utils/applyEdits.ts 100% 100% 100% 100%
Generated in workflow #1384 for commit a6d4650 by the Vitest Coverage Report Action

@dnass

dnass commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@eyeseast I tried moving the expandable field list to SearchResultsState like we discussed, but it introduced a new issue: The edited store can contain old edits too, so if you edited one document's description and then another document's projects, the first edit would get replayed with the unexpanded projects included. I found this alternative approach of merging partial documents into the store via a util. The key difference is that SearchResultsState is no longer responsible for excluding expandable fields, but I think the new pattern is easy enough to follow.

@eyeseast

Copy link
Copy Markdown
Collaborator

This works.

One thing I found in production is that Solr is very slow to index documents into projects. So if I add a document to a project and get the optimistic update, and then I click that new project link, I don't see the document. I'm not sure if this is a problem we need to solve here, but it's probably something we should address eventually.

Ideally, I'd like to make Solr faster to update, but failing that, we should think about where we can signal to the user that the change did actually work, and things are happening in the background.

@allanlasser allanlasser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM—I'll leave it to Chris for a final ✅

@eyeseast eyeseast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is good to merge. I want to think about how to handle the in-project side, but that's a separate issue. I'm not sure exactly where that needs to live yet.

@dnass
dnass force-pushed the 895-move-to-project branch from 9819dc2 to 131b928 Compare September 14, 2026 13:25
@dnass
dnass force-pushed the 895-move-to-project branch from e7b8a11 to a6d4650 Compare September 14, 2026 13: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.

Improve "Move to Project" UX

3 participants