Ghost/ghost/admin/app/adapters/post.js
Kevin Ansfield e5c26aac89 Added newsletter dropdown to publish menu
closes https://github.com/TryGhost/Team/issues/1479

- updated post adapter to append `?newsletter_id=xyz` when passed a `newsletterId` adapterOption
- updated editor save task to pass `options.newsletterId` through as `adapterOptions.newsletterId`
- set up `post.newsletter` relationship ready for handling embedded newsletter association from the API
  - explicitly deleted when serializing back to the API as it doesn't yet ignore the attribute
- updated `<GhPublishmenu>` for newsletter support
  - fetches newsletters on first render so they are available in the dropdown
  - sets "default" (first in the ordered list) newsletter as the initially selected newsletter
  - adds newsletter dropdown to draft publish menu
  - passes `newsletterId` option to editor save task when it's set

This is a minimal implementation for testing. Not included:
- correct free/paid member counts based on selected newsletter
- correct member count in confirmation modal
- indication of selected newsletter for scheduled post
2022-04-06 10:22:06 +01:00

31 lines
1.1 KiB
JavaScript

import ApplicationAdapter from 'ghost-admin/adapters/application';
export default class Post extends ApplicationAdapter {
// posts and pages now include everything by default
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
const url = this.buildURL(modelName, id, snapshot, requestType, query);
const parsedUrl = new URL(url);
if (snapshot?.adapterOptions?.sendEmailWhenPublished) {
let emailRecipientFilter = snapshot.adapterOptions.sendEmailWhenPublished;
if (emailRecipientFilter === 'status:free,status:-free') {
emailRecipientFilter = 'all';
}
parsedUrl.searchParams.append('email_recipient_filter', emailRecipientFilter);
}
if (snapshot?.adapterOptions?.newsletterId) {
const newsletterId = snapshot.adapterOptions.newsletterId;
parsedUrl.searchParams.append('newsletter_id', newsletterId);
}
return parsedUrl.toString();
}
buildQuery(store, modelName, options) {
return options;
}
}