From 8b5c18d6e58830137aba8fa7bb3971671412cc8b Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 10 Sep 2021 09:24:38 +0100 Subject: [PATCH] Hid email specific cards from card menus when editing pages no issue Pages can not be sent by email so by hiding email-specific cards when editing pages we can reduce confusion and clutter. - added a `@postType` argument to editor components that can be passed through to sub components - set `@postType` to `post.displayName` which is either `post` or `page` - updated `{{card-is-available}}` helper to compare a `postType` property on card menu items to the passed in `postType` --- ghost/admin/app/components/gh-koenig-editor.hbs | 1 + ghost/admin/app/templates/editor.hbs | 1 + .../lib/koenig-editor/addon/components/koenig-editor.hbs | 2 ++ .../koenig-editor/addon/components/koenig-menu-content.hbs | 2 +- .../lib/koenig-editor/addon/components/koenig-plus-menu.hbs | 1 + .../lib/koenig-editor/addon/helpers/card-is-available.js | 6 +++++- ghost/admin/lib/koenig-editor/addon/options/cards.js | 6 ++++-- 7 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ghost/admin/app/components/gh-koenig-editor.hbs b/ghost/admin/app/components/gh-koenig-editor.hbs index 67ac40d905..f2df4652ee 100644 --- a/ghost/admin/app/components/gh-koenig-editor.hbs +++ b/ghost/admin/app/components/gh-koenig-editor.hbs @@ -52,6 +52,7 @@ @updateSnippet={{@updateSnippet}} @deleteSnippet={{@deleteSnippet}} @cardOptions={{@cardOptions}} + @postType={{@postType}} /> \ No newline at end of file diff --git a/ghost/admin/app/templates/editor.hbs b/ghost/admin/app/templates/editor.hbs index c5d4c789bc..1c856bcc9e 100644 --- a/ghost/admin/app/templates/editor.hbs +++ b/ghost/admin/app/templates/editor.hbs @@ -92,6 +92,7 @@ @cardOptions={{hash post=this.post }} + @postType={{this.post.displayName}} />
diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.hbs b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.hbs index 8bae5cdbd0..293a1e053f 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.hbs +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.hbs @@ -56,6 +56,7 @@ @deleteSnippet={{this.deleteSnippet}} @replaceWithCardSection={{action "replaceWithCardSection"}} @replaceWithPost={{action "replaceWithPost"}} + @postType={{@postType}} /> {{!-- slash menu popup --}} @@ -66,6 +67,7 @@ @deleteSnippet={{this.deleteSnippet}} @replaceWithCardSection={{action "replaceWithCardSection"}} @replaceWithPost={{action "replaceWithPost"}} + @postType={{@postType}} /> {{!-- all component cards wormholed into the editor canvas --}} diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-menu-content.hbs b/ghost/admin/lib/koenig-editor/addon/components/koenig-menu-content.hbs index 542ffbeed4..f535c2de84 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-menu-content.hbs +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-menu-content.hbs @@ -5,7 +5,7 @@ {{section.title}}
{{#each section.items as |item|}} - {{#if (card-is-available item)}} + {{#if (card-is-available item postType=@postType)}}
{{/if}} \ No newline at end of file diff --git a/ghost/admin/lib/koenig-editor/addon/helpers/card-is-available.js b/ghost/admin/lib/koenig-editor/addon/helpers/card-is-available.js index a297257066..a7d9974ee2 100644 --- a/ghost/admin/lib/koenig-editor/addon/helpers/card-is-available.js +++ b/ghost/admin/lib/koenig-editor/addon/helpers/card-is-available.js @@ -6,7 +6,7 @@ export default class CardIsAvailableHelper extends Helper { @service config; @service feature; - compute([card]) { + compute([card], {postType} = {}) { let cardIsAvailable = true; if (card.developerExperiment) { @@ -17,6 +17,10 @@ export default class CardIsAvailableHelper extends Helper { cardIsAvailable = get(this.feature, card.feature); } + if (postType && card.postType) { + cardIsAvailable = card.postType === postType; + } + return cardIsAvailable; } } diff --git a/ghost/admin/lib/koenig-editor/addon/options/cards.js b/ghost/admin/lib/koenig-editor/addon/options/cards.js index 71749a773a..61c5514aff 100644 --- a/ghost/admin/lib/koenig-editor/addon/options/cards.js +++ b/ghost/admin/lib/koenig-editor/addon/options/cards.js @@ -121,7 +121,8 @@ export const CARD_MENU = [ desc: 'Only visible when delivered by email', matches: ['email'], type: 'card', - replaceArg: 'email' + replaceArg: 'email', + postType: 'post' }, { label: 'Email call to action', @@ -129,7 +130,8 @@ export const CARD_MENU = [ desc: 'Target free or paid members with a CTA', matches: ['email', 'cta'], type: 'card', - replaceArg: 'email-cta' + replaceArg: 'email-cta', + postType: 'post' }, { label: 'Public preview',