hookshot/src/HookFilter.ts
Will Hunt 1e8a112a28
Drop ignoreHooks configuration. (#592)
* Refactor HookFilter to only support enabledEvents (and add a function to convert)

* Convert connections to deprecate ignoreHooks

* Update documentation

* Split out EventHookCheckbox

* Refactor frontend to support enableHooks only mode

* drop old field name

* changelog

* Fix enabledHooks for widgets

* Fixes across the board

* Update test description

* Cleanup

* Fix HookFilter

* Fixup checkboxes

* Cleanup
2023-01-10 17:08:50 +00:00

32 lines
1.0 KiB
TypeScript

export class HookFilter<T extends string> {
static convertIgnoredHooksToEnabledHooks<T extends string>(explicitlyEnabledHooks: T[] = [], ignoredHooks: T[], defaultHooks: T[]): T[] {
const resultHookSet = new Set([
...explicitlyEnabledHooks,
...defaultHooks,
]);
// For each ignored hook, remove anything that matches.
for (const ignoredHook of ignoredHooks) {
resultHookSet.delete(ignoredHook);
// If the hook is a "root" hook name, remove all children.
for (const enabledHook of resultHookSet) {
if (enabledHook.startsWith(`${ignoredHook}.`)) {
resultHookSet.delete(enabledHook);
}
}
}
return [...resultHookSet];
}
constructor(
public enabledHooks: T[] = [],
) {
}
public shouldSkip(...hookName: T[]) {
// Should skip if all of the hook names are missing
return hookName.every(name => !this.enabledHooks.includes(name));
}
}