Skip to content

Commit

Permalink
Fixed excerpt blur saving non-draft posts
Browse files Browse the repository at this point in the history
ref https://linear.app/tryghost/issue/PLG-174

- forcing autosave on excerpt blur caused posts to revert to `draft` and save immediately even when they were published/scheduled
- updated the save-on-excerpt-blur to only autosave drafts
- added acceptance tests for title and excerpt change+blur on published posts
  • Loading branch information
kevinansfield committed Aug 20, 2024
1 parent d6df261 commit 19b8674
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ghost/admin/app/controllers/lexical-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ export default class LexicalEditorController extends Controller {
}
}

@task
*saveExcerptTask() {
if (this.post.status === 'draft') {
yield this.autosaveTask.perform();
}
}

// updates local willPublish/Schedule values, does not get applied to
// the post's `status` value until a save is triggered
@action
Expand Down
2 changes: 1 addition & 1 deletion ghost/admin/app/templates/lexical-editor.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
@excerpt={{readonly this.post.customExcerpt}}
@excerptHasTk={{this.excerptHasTk}}
@setExcerpt={{this.updateExcerpt}}
@onExcerptBlur={{perform this.autosaveTask}}
@onExcerptBlur={{perform this.saveExcerptTask}}
@excerptErrorMessage={{this.excerptErrorMessage}}
@body={{readonly this.post.lexicalScratch}}
@bodyPlaceholder={{concat "Begin writing your " this.post.displayName "..."}}
Expand Down
43 changes: 43 additions & 0 deletions ghost/admin/tests/acceptance/editor/lexical-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,47 @@ describe('Acceptance: Lexical editor', function () {
// TODO: requires editor to be loading
it('saves on content change');
});

describe('existing post', function () {
it('does not save post on title blur', async function () {
const post = this.server.create('post', {status: 'published'});
const originalTitle = post.title;

await visit('/editor/post/1');
await fillIn('[data-test-editor-title-input]', 'Change test');
await blur('[data-test-editor-title-input]');

expect(find('[data-test-editor-post-status]')).not.to.contain.text('Saved');
expect(post.status, 'post status').to.equal('published');
expect(post.title, 'saved title').to.equal(originalTitle);

await click('[data-test-link="posts"]');

expect(find('[data-test-modal="unsaved-post-changes"]'), 'unsaved changes modal').to.exist;

expect(currentURL(), 'currentURL').to.equal(`/editor/post/1`);
});

it('does not save post on excerpt blur', async function () {
// excerpt is not shown by default
enableLabsFlag(this.server, 'editorExcerpt');

const post = this.server.create('post', {status: 'published'});
const originalExcerpt = post.excerpt;

await visit('/editor/post/1');
await fillIn('[data-test-textarea="excerpt"]', 'Change test');
await blur('[data-test-textarea="excerpt"]');

expect(find('[data-test-editor-post-status]')).not.to.contain.text('Saved');
expect(post.status, 'post status').to.equal('published');
expect(post.excerpt, 'saved excerpt').to.equal(originalExcerpt);

await click('[data-test-link="posts"]');

expect(find('[data-test-modal="unsaved-post-changes"]'), 'unsaved changes modal').to.exist;

expect(currentURL(), 'currentURL').to.equal(`/editor/post/1`);
});
});
});

0 comments on commit 19b8674

Please sign in to comment.