mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
4207c9d0d1
refs TryGhost/Team#3122 <!-- Leave the line below if you'd like GitHub Copilot to generate a summary from your commit --> <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 87727d9</samp> Added `data-testid` attributes to various elements in the announcement bar settings feature to enable Playwright testing. Fixed a potential bug with the `visibilitySettings` getter in the `visibility.js` component. Added Playwright tests for the announcement bar settings feature in `announcement-bar-settings.spec.js`.
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class AnnouncementSettingsVisibilityComponent extends Component {
|
|
@service settings;
|
|
@service membersUtils;
|
|
|
|
visibilityOptions = {
|
|
freeMembers: 'free_members',
|
|
paidMembers: 'paid_members',
|
|
visitors: 'visitors'
|
|
};
|
|
|
|
get visibilitySettings() {
|
|
return this.settings.announcementVisibility || [];
|
|
}
|
|
|
|
get isPaidAvailable() {
|
|
return this.membersUtils.isStripeEnabled;
|
|
}
|
|
|
|
get isFreeMembersChecked() {
|
|
return this.visibilitySettings.includes(this.visibilityOptions.freeMembers);
|
|
}
|
|
|
|
get isPaidMembersChecked() {
|
|
return this.visibilitySettings.includes(this.visibilityOptions.paidMembers);
|
|
}
|
|
|
|
get isVisitorsChecked() {
|
|
return this.visibilitySettings.includes(this.visibilityOptions.visitors);
|
|
}
|
|
|
|
get isMembersEnabled() {
|
|
return this.settings.membersEnabled;
|
|
}
|
|
|
|
@action
|
|
updateVisibility(event) {
|
|
let updatedVisibilityOptions = [...this.visibilitySettings];
|
|
const value = event.target.value;
|
|
|
|
if (event.target.checked) {
|
|
updatedVisibilityOptions.push(value);
|
|
} else {
|
|
updatedVisibilityOptions = updatedVisibilityOptions.filter(item => item !== value);
|
|
}
|
|
|
|
this.settings.announcementVisibility = updatedVisibilityOptions;
|
|
// update preview if there are no visibility options or just one to avoid update flickering on every check
|
|
if (!updatedVisibilityOptions.length || updatedVisibilityOptions.length === 1) {
|
|
this.args.onChange?.();
|
|
}
|
|
}
|
|
}
|