discourse/app/assets/javascripts/admin/addon/components/webhook-event-chooser.js
Krzysztof Kotlarek c468110929
FEATURE: granular webhooks (#23070)
Before this change, webhooks could be only configured for specific groups like for example, all topic events.

We would like to have more granular control like for example topic_created or topic_destroyed.

Test are failing because plugins changed has to be merged as well:
discourse/discourse-assign#498
discourse/discourse-solved#248
discourse/discourse-topic-voting#159
2023-10-09 03:35:31 +00:00

40 lines
842 B
JavaScript

import Component from "@glimmer/component";
import I18n from "I18n";
export default class WebhookEventChooser extends Component {
get details() {
return I18n.t(
`admin.web_hooks.${this.args.group}_event.${this.args.type.name}`
);
}
get eventTypeExists() {
return this.args.eventTypes.any(
(event) => event.name === this.args.type.name
);
}
get enabled() {
return this.eventTypeExists;
}
set enabled(value) {
const eventTypes = this.args.eventTypes;
// add an association when not exists
if (value === this.eventTypeExists) {
return value;
}
if (value) {
eventTypes.addObject(this.args.type);
} else {
eventTypes.removeObjects(
eventTypes.filter((eventType) => eventType.name === this.args.type.name)
);
}
return value;
}
}