Added support for feature-gated editor cards

refs https://github.com/TryGhost/Team/issues/910

- added `card-is-available` helper that handles the previous `card.developerExperiment` and the new `card.feature` options
- updated `<KoenigMenuContent>` to use the `card-is-available` helper in the conditional when adding cards to the list

Cards can be gated by feature when specifying them in `cards.js`, in the card definition object you can add `feature: 'flagName'` which will mean the card is only available when that feature is enabled.
This commit is contained in:
Kevin Ansfield 2021-07-20 10:48:12 +01:00
parent 6e540cf2ef
commit 10f83ebd45
3 changed files with 24 additions and 1 deletions

View File

@ -5,7 +5,7 @@
{{section.title}}
</div>
{{#each section.items as |item|}}
{{#if (or (not item.developerExperiment) (enable-developer-experiments))}}
{{#if (card-is-available item)}}
<div
class="{{if (eq item @selectedItem) "kg-cardmenu-card-selected"}} {{kg-style "cardmenu-card"}}"
data-kg="cardmenu-card"

View File

@ -0,0 +1,22 @@
import Helper from '@ember/component/helper';
import {get} from '@ember/object';
import {inject as service} from '@ember/service';
export default class CardIsAvailableHelper extends Helper {
@service config;
@service feature;
compute([card]) {
let cardIsAvailable = true;
if (card.developerExperiment) {
cardIsAvailable = this.config.get('enableDeveloperExperiments');
}
if (card.feature) {
cardIsAvailable = get(this.feature, card.feature);
}
return cardIsAvailable;
}
}

View File

@ -0,0 +1 @@
export {default} from 'koenig-editor/helpers/card-is-available';