Scenes: SAVE TO STORIES and tags roll back when the project cannot be saved

This commit is contained in:
Sameh Khamis committed 2026-11-16 13:37:21 -08:00
1 parent 85c9f95838
commit c8b440dded
2 files changed
+58 -6

No files matched your search

+18 -6
View File
@@ -602,8 +602,9 @@ export class SceneDirector {
* Set the tags a scene shows on its Stories card.
* @param {string} sceneId
* @param {string[]} tags Keys from STORY_TAGS, at most STORY_TAG_LIMIT.
* @returns {boolean} False when the scene does not exist or a tag is not
* one of STORY_TAGS.
* @returns {boolean} False when the scene does not exist, a tag is not
* one of STORY_TAGS, or the project could not be saved (the tags stay as
* they were and the save error is shown).
*/
setSceneStoryTags(sceneId, tags) {
const scene = this._project.scenes.find(({ id }) => id === sceneId);
@@ -614,9 +615,14 @@ export class SceneDirector {
!next.every((tag) => STORY_TAGS.includes(tag))
)
return false;
const previous = scene.storyTags;
if (next.length) scene.storyTags = next;
else delete scene.storyTags;
this._saveProject();
if (!this._saveProject()) {
if (previous === undefined) delete scene.storyTags;
else scene.storyTags = previous;
return false;
}
this._publish({ type: 'story-details-changed', scene });
if (scene.stories) this._publish({ type: 'stories-changed' });
return true;
@@ -2027,15 +2033,21 @@ export class SceneDirector {
* Publish a scene to the Stories page, or take it off.
* @param {string} sceneId
* @param {boolean} on
* @returns {boolean} False when the scene does not exist, or has no shots
* and `on` is true.
* @returns {boolean} False when the scene does not exist, has no shots and
* `on` is true, or the project could not be saved (the scene stays as it
* was and the save error is shown).
*/
setSceneInStories(sceneId, on) {
const scene = this._project.scenes.find(({ id }) => id === sceneId);
if (!scene || (on && !scene.shots.length)) return false;
const previous = scene.stories;
if (on) scene.stories = true;
else delete scene.stories;
this._saveProject();
if (!this._saveProject()) {
if (previous === undefined) delete scene.stories;
else scene.stories = previous;
return false;
}
this._publish({ type: 'stories-changed' });
return true;
}
+40
View File
@@ -2621,6 +2621,46 @@ test('an invalid thumbnail is not kept and the save error is shown', () => {
}
});
test('SAVE TO STORIES and tags that cannot be saved roll back and show the save error', () => {
const warn = console.warn;
console.warn = () => {};
const { director, storage, restore } = makeDirector();
const changes = recordChanges(director);
try {
director.setSceneStoryTags('scene-1', ['Storms']);
storage.full = true;
changes.length = 0;
assert.equal(director.setSceneInStories('scene-1', true), false);
assert.equal(Object.hasOwn(director._project.scenes[0], 'stories'), false);
assert.deepEqual(director.storyScenes(), []);
assert.match(director._presentation.status, /^Scene not saved/);
assert.equal(director.setSceneStoryTags('scene-1', ['Floods', 'Storms']), false);
assert.deepEqual(director._project.scenes[0].storyTags, ['Storms']);
assert.equal(director.setSceneStoryTags('scene-1', []), false);
assert.deepEqual(director._project.scenes[0].storyTags, ['Storms']);
assert.deepEqual(
changes.filter((type) => type !== 'status-changed'),
[],
'only the save error is announced',
);
// Taking a scene off Stories rolls back the same way.
storage.full = false;
assert.equal(director.setSceneInStories('scene-1', true), true);
storage.full = true;
assert.equal(director.setSceneInStories('scene-1', false), false);
assert.equal(director._project.scenes[0].stories, true);
// The panel's toggle reports no success either.
director._selectedSceneId = 'scene-1';
director._toggleSelectedSceneInStories();
assert.equal(director._project.scenes[0].stories, true);
assert.match(director._presentation.status, /^Scene not saved/);
} finally { console.warn = warn; restore(); }
});
test('story thumbnail and tags survive a reload and an export/import round trip', async () => {
const first = makeDirector();
let saved;