From c2b91ba1cd09fe21db69b5710682c928948a9efd Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 8 Nov 2024 13:25:08 +0100 Subject: [PATCH] chore: allow extensibility of bool gambit --- framework/core/js/src/common/query/IGambit.ts | 16 ++++++++++++---- framework/core/locale/core.yml | 5 ++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/framework/core/js/src/common/query/IGambit.ts b/framework/core/js/src/common/query/IGambit.ts index 5f152f5c4d..108e7e4c4d 100644 --- a/framework/core/js/src/common/query/IGambit.ts +++ b/framework/core/js/src/common/query/IGambit.ts @@ -71,7 +71,7 @@ export type KeyValueGambitSuggestion = { }; export type GroupedGambitSuggestion = { - group: 'is' | 'has' | string; + group: 'is' | 'has' | 'allows' | string; key: string | string[]; }; @@ -82,8 +82,16 @@ export abstract class BooleanGambit implements IGambit { abstract key(): string | string[]; abstract filterKey(): string; + booleanKey(): 'is' | 'has' | 'allows' { + return 'is'; + } + + groupKey(): string { + return app.translator.trans('core.lib.gambits.group_keys.' + this.booleanKey(), {}, true); + } + pattern(): string { - const is = app.translator.trans('core.lib.gambits.boolean_key', {}, true); + const is = this.groupKey(); let key = this.key(); if (Array.isArray(key)) { @@ -102,7 +110,7 @@ export abstract class BooleanGambit implements IGambit { } fromFilter(value: string, negate: boolean): string { - const is = app.translator.trans('core.lib.gambits.boolean_key', {}, true); + const is = this.groupKey(); const key = this.key(); return `${negate ? '-' : ''}${is}:${key}`; @@ -110,7 +118,7 @@ export abstract class BooleanGambit implements IGambit { suggestion() { return { - group: app.translator.trans('core.lib.gambits.boolean_key', {}, true), + group: this.groupKey(), key: this.key(), }; } diff --git a/framework/core/locale/core.yml b/framework/core/locale/core.yml index ac8c10f99e..a401e9bff9 100644 --- a/framework/core/locale/core.yml +++ b/framework/core/locale/core.yml @@ -733,7 +733,10 @@ core: # These translations are used by gambits. Gambit keys must be in snake_case, no spaces. gambits: - boolean_key: is + group_keys: + allows: allows + has: has + is: is discussions: author: key: author