Ghost/ghost/admin/lib/koenig-editor/addon/helpers/card-is-available.js
Kevin Ansfield cdf0565d3b Hid gifs card when tenor API config is not available
refs https://github.com/TryGhost/Team/issues/1220

- added array support to `{{card-is-available}}` helper where every key needs to be present for the card to be available
- changed gifs card `isAvailable` property to require both the feature flag and the tenor api key to be set in config
2021-11-16 12:14:21 +00:00

35 lines
982 B
JavaScript

import Helper from '@ember/component/helper';
import {get} from '@ember/object';
import {isArray} from '@ember/array';
import {inject as service} from '@ember/service';
export default class CardIsAvailableHelper extends Helper {
@service config;
@service feature;
@service settings;
compute([card], {postType} = {}) {
let cardIsAvailable = true;
if (typeof card.isAvailable === 'string') {
cardIsAvailable = get(this, card.isAvailable);
}
if (isArray(card.isAvailable)) {
cardIsAvailable = card.isAvailable.every((key) => {
return get(this, key);
});
}
if (card.developerExperiment) {
cardIsAvailable = cardIsAvailable && this.config.get('enableDeveloperExperiments');
}
if (postType && card.postType) {
cardIsAvailable = cardIsAvailable && card.postType === postType;
}
return cardIsAvailable;
}
}