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 <alexander.onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2023-07-20 16:41:26 +07:00 committed by GitHub
parent cc80202d48
commit 0206a44176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 7 deletions

View File

@ -67,7 +67,7 @@ export { default } from './plugin'
export const DOMAIN_TASK = 'task' as Domain export const DOMAIN_TASK = 'task' as Domain
export const DOMAIN_KANBAN = 'kanban' as Domain export const DOMAIN_KANBAN = 'kanban' as Domain
@Model(task.class.State, core.class.Status) @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 { export class TState extends TStatus implements State {
isArchived!: boolean isArchived!: boolean
} }

View File

@ -89,7 +89,7 @@ export const DOMAIN_TRACKER = 'tracker' as Domain
* @public * @public
*/ */
@Model(tracker.class.IssueStatus, core.class.Status) @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 {} export class TIssueStatus extends TStatus implements IssueStatus {}
/** /**

View File

@ -166,6 +166,7 @@ export interface Class<T extends Obj> extends Classifier {
domain?: Domain domain?: Domain
shortLabel?: string shortLabel?: string
sortingKey?: string sortingKey?: string
filteringKey?: string
} }
/** /**

View File

@ -77,6 +77,7 @@ interface ClassTxes {
kind: ClassifierKind kind: ClassifierKind
shortLabel?: string | IntlString shortLabel?: string | IntlString
sortingKey?: string sortingKey?: string
filteringKey?: string
} }
const transactions = new Map<any, ClassTxes>() const transactions = new Map<any, ClassTxes>()
@ -226,13 +227,20 @@ export function Mixin<T extends Obj> (_class: Ref<Class<T>>, _extends: Ref<Class
* @param icon - * @param icon -
* @returns * @returns
*/ */
export function UX<T extends Obj> (label: IntlString, icon?: Asset, shortLabel?: string, sortingKey?: string) { export function UX<T extends Obj> (
label: IntlString,
icon?: Asset,
shortLabel?: string,
sortingKey?: string,
filteringKey?: string
) {
return function classDecorator<C extends new () => T> (constructor: C): void { return function classDecorator<C extends new () => T> (constructor: C): void {
const txes = getTxes(constructor.prototype) const txes = getTxes(constructor.prototype)
txes.label = label txes.label = label
txes.icon = icon txes.icon = icon
txes.shortLabel = shortLabel txes.shortLabel = shortLabel
txes.sortingKey = sortingKey txes.sortingKey = sortingKey
txes.filteringKey = filteringKey ?? sortingKey
} }
} }
@ -269,7 +277,8 @@ function _generateTx (tx: ClassTxes): Tx[] {
label: tx.label, label: tx.label,
icon: tx.icon, icon: tx.icon,
shortLabel: tx.shortLabel, shortLabel: tx.shortLabel,
sortingKey: tx.sortingKey sortingKey: tx.sortingKey,
filteringKey: tx.filteringKey
}, },
objectId objectId
) )

View File

@ -84,9 +84,9 @@
} }
const resultQuery = const resultQuery =
search !== '' && clazz.sortingKey search !== '' && clazz.filteringKey
? { ? {
[clazz.sortingKey]: { $like: '%' + search + '%' }, [clazz.filteringKey]: { $like: '%' + search + '%' },
_id: { $in: Array.from(targets.keys()) } _id: { $in: Array.from(targets.keys()) }
} }
: { : {
@ -155,7 +155,7 @@
</script> </script>
<div class="selectPopup" use:resizeObserver={() => dispatch('changeContent')}> <div class="selectPopup" use:resizeObserver={() => dispatch('changeContent')}>
{#if clazz.sortingKey} {#if clazz.filteringKey}
<div class="header"> <div class="header">
<EditWithIcon <EditWithIcon
icon={IconSearch} icon={IconSearch}