{{ message }}
[DRAFT] dp ← Auto-save for version edits#27158
Draft
alvarosabu wants to merge 3 commits intoalvaro/cms-1865-discard-item-less-versions-navigate-to-collectionfrom
Draft
Conversation
…mposable; integrate auto-save in item.vue for version management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Scope
What's changed:
useAutoSavecomposable (app/src/composables/use-auto-save.ts) — debounced (750ms) auto-save driven byeditswatcher. One revision per editing session: first save of the session creates a revision, subsequent saves patch it in place untilAUTO_SAVE_SNAPSHOT_INTERVAL_MINUTES(5m) of inactivity promotes the next save to a new revision. ExposesautoSaveErrorandresetSession; resets oncurrentVersionchange.createRevisionoption toVersionsService.save()and?createRevision=falsequery param onPOST /versions/:id/save. When false and the version has an item, skip the activity/revision insert and merge the clean delta into the latest existing revision so the sidebar reflects accumulated edits. SnapshotsrevisionDeltabeforedeepMapObjectsmutates it with_user/_datemetadata.item.vuefor versioned items viaautoSaveRevision(forceNew): manual save / stale session →saveVersion(...)(creates revision); otherwise →saveVersion(..., { createRevision: false }). Manual stay/quit shortcuts for versions removed — auto-save handles it.patchVersionDeltapath inuse-versions.ts(was a rawPATCH /versions/:idthat bypassedVersionsService.save— prepareDelta, hooks, permissions). Consolidates auto-save and manual save onto a single server pipeline.confirmVersionExistsonly returnsfalseon HTTP 404; other errors (network, 5xx) are re-thrown instead of being silently treated as "version gone".Potential Risks / Drawbacks
assign({}, latestRevision.data ?? {}, cleanRevisionDelta)— shallow merge. Nested objects in the delta overwrite whole subtrees rather than deep-merging. Matches prior client-side behaviour but worth confirming for complex relational payloads.cleanRevisionDeltais captured viaJSON.parse(JSON.stringify(...))— any non-JSON values in the delta (Date, undefined, Map) will be lost. Current payloads are JSON so this should be fine, but sharp edge.editsmutation (deep watch). Debounced at 750ms; overlapping saves guarded by anisSavingmutex. Worth monitoring for very large forms.req.query['createRevision'] !== 'false'— any other truthy string evaluates totrue. Consistent with existing Directus patterns.Tested Scenarios
currentVersion→ session resets; next save creates a new revision.currentVersion !== null.handleVersionGoneswallows the error silently;autoSaveErrornot set.confirmVersionExistsnow surface instead of being silenced.Review Notes / Questions
alvaro/cms-1865-discard-item-less-versions-navigate-to-collection; merge that first.minororpatchentry for the new?createRevisionquery param? It's additive and defaults to current behavior.createRevision: falsebranch ofVersionsService.save()(latest-revision lookup + accumulated merge). Would appreciate guidance on where those belong inapi/src/services/versions.test.ts.AUTO_SAVE_SNAPSHOT_INTERVAL_MINUTESandAUTO_SAVE_DEBOUNCE_MSare module constants — open to moving to settings if product wants them configurable.Checklist
Fixes CMS-1867