Skip to content

Commit

Permalink
chore: allow extensibility of bool gambit
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Nov 8, 2024
1 parent 5d10fdc commit c2b91ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 12 additions & 4 deletions framework/core/js/src/common/query/IGambit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type KeyValueGambitSuggestion = {
};

export type GroupedGambitSuggestion = {
group: 'is' | 'has' | string;
group: 'is' | 'has' | 'allows' | string;
key: string | string[];
};

Expand All @@ -82,8 +82,16 @@ export abstract class BooleanGambit implements IGambit<GambitType.Grouped> {
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)) {
Expand All @@ -102,15 +110,15 @@ export abstract class BooleanGambit implements IGambit<GambitType.Grouped> {
}

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}`;
}

suggestion() {
return {
group: app.translator.trans('core.lib.gambits.boolean_key', {}, true),
group: this.groupKey(),
key: this.key(),
};
}
Expand Down
5 changes: 4 additions & 1 deletion framework/core/locale/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2b91ba

Please sign in to comment.