1e3adef145
closes #6170 - add gh-feature-flag component to create a checkbox (reduce duplicate code)
49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
const {
|
|
computed,
|
|
inject: {service},
|
|
Component
|
|
} = Ember;
|
|
|
|
const FeatureFlagComponent = Component.extend({
|
|
tagName: 'label',
|
|
classNames: 'checkbox',
|
|
attributeBindings: ['for'],
|
|
_flagValue: null,
|
|
|
|
feature: service(),
|
|
|
|
isVisible: computed.notEmpty('_flagValue'),
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
|
|
this.get(`feature.${this.get('flag')}`).then((flagValue) => {
|
|
this.set('_flagValue', flagValue);
|
|
});
|
|
},
|
|
|
|
value: computed('_flagValue', {
|
|
get() {
|
|
return this.get('_flagValue');
|
|
},
|
|
set(key, value) {
|
|
return this.set(`feature.${this.get('flag')}`, value);
|
|
}
|
|
}),
|
|
|
|
for: computed('flag', function () {
|
|
return `labs-${this.get('flag')}`;
|
|
}),
|
|
name: computed('flag', function () {
|
|
return `labs[${this.get('flag')}]`;
|
|
})
|
|
});
|
|
|
|
FeatureFlagComponent.reopenClass({
|
|
positionalParams: ['flag']
|
|
});
|
|
|
|
export default FeatureFlagComponent;
|