From 0206a441762d017cb1be721237f42d7d4690299c Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Thu, 20 Jul 2023 16:41:26 +0700 Subject: [PATCH] TSK-1599 Search key model (#3514) Add filtering key model to be used instead of sorting key as it is not always searchable. Signed-off-by: Alexander Onnikov --- models/task/src/index.ts | 2 +- models/tracker/src/index.ts | 2 +- packages/core/src/classes.ts | 1 + packages/model/src/dsl.ts | 13 +++++++++++-- .../src/components/filter/ObjectFilter.svelte | 6 +++--- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/models/task/src/index.ts b/models/task/src/index.ts index 7c777d6f27..e9cea8f587 100644 --- a/models/task/src/index.ts +++ b/models/task/src/index.ts @@ -67,7 +67,7 @@ export { default } from './plugin' export const DOMAIN_TASK = 'task' as Domain export const DOMAIN_KANBAN = 'kanban' as Domain @Model(task.class.State, core.class.Status) -@UX(task.string.TaskState, task.icon.TaskState, undefined, 'rank') +@UX(task.string.TaskState, task.icon.TaskState, undefined, 'rank', 'name') export class TState extends TStatus implements State { isArchived!: boolean } diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index 11113b2678..ff5f6e3d27 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -89,7 +89,7 @@ export const DOMAIN_TRACKER = 'tracker' as Domain * @public */ @Model(tracker.class.IssueStatus, core.class.Status) -@UX(tracker.string.IssueStatuses, undefined, undefined, 'rank') +@UX(tracker.string.IssueStatuses, undefined, undefined, 'rank', 'name') export class TIssueStatus extends TStatus implements IssueStatus {} /** diff --git a/packages/core/src/classes.ts b/packages/core/src/classes.ts index 2dbe206a20..60f430c3d5 100644 --- a/packages/core/src/classes.ts +++ b/packages/core/src/classes.ts @@ -166,6 +166,7 @@ export interface Class extends Classifier { domain?: Domain shortLabel?: string sortingKey?: string + filteringKey?: string } /** diff --git a/packages/model/src/dsl.ts b/packages/model/src/dsl.ts index aed8be6a16..eb10649f6b 100644 --- a/packages/model/src/dsl.ts +++ b/packages/model/src/dsl.ts @@ -77,6 +77,7 @@ interface ClassTxes { kind: ClassifierKind shortLabel?: string | IntlString sortingKey?: string + filteringKey?: string } const transactions = new Map() @@ -226,13 +227,20 @@ export function Mixin (_class: Ref>, _extends: Ref (label: IntlString, icon?: Asset, shortLabel?: string, sortingKey?: string) { +export function UX ( + label: IntlString, + icon?: Asset, + shortLabel?: string, + sortingKey?: string, + filteringKey?: string +) { return function classDecorator T> (constructor: C): void { const txes = getTxes(constructor.prototype) txes.label = label txes.icon = icon txes.shortLabel = shortLabel txes.sortingKey = sortingKey + txes.filteringKey = filteringKey ?? sortingKey } } @@ -269,7 +277,8 @@ function _generateTx (tx: ClassTxes): Tx[] { label: tx.label, icon: tx.icon, shortLabel: tx.shortLabel, - sortingKey: tx.sortingKey + sortingKey: tx.sortingKey, + filteringKey: tx.filteringKey }, objectId ) diff --git a/plugins/view-resources/src/components/filter/ObjectFilter.svelte b/plugins/view-resources/src/components/filter/ObjectFilter.svelte index ef5f6efc5d..4d711e73de 100644 --- a/plugins/view-resources/src/components/filter/ObjectFilter.svelte +++ b/plugins/view-resources/src/components/filter/ObjectFilter.svelte @@ -84,9 +84,9 @@ } const resultQuery = - search !== '' && clazz.sortingKey + search !== '' && clazz.filteringKey ? { - [clazz.sortingKey]: { $like: '%' + search + '%' }, + [clazz.filteringKey]: { $like: '%' + search + '%' }, _id: { $in: Array.from(targets.keys()) } } : { @@ -155,7 +155,7 @@
dispatch('changeContent')}> - {#if clazz.sortingKey} + {#if clazz.filteringKey}