From fbb3471a498fcec4d8aebec0ddabab827c0a7a95 Mon Sep 17 00:00:00 2001 From: Chunosov Date: Thu, 12 Dec 2024 09:45:50 +0700 Subject: [PATCH] Show/hide completed applicants in all viewlets (#7428) --- models/recruit/src/index.ts | 53 +++++++++---------- plugins/task-resources/src/utils.ts | 6 +-- .../src/components/Table.svelte | 42 +++++++++++++-- .../src/components/TableBrowser.svelte | 6 ++- server-plugins/task-resources/src/index.ts | 2 +- 5 files changed, 73 insertions(+), 36 deletions(-) diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index a8e2857cd4..003de31209 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -435,6 +435,26 @@ export function createModel (builder: Builder): void { }, recruit.viewlet.TableApplicant ) + + const applicationDoneOption: ViewOptionModel = { + key: 'hideDoneState', + type: 'toggle', + defaultValue: true, + actionTarget: 'query', + action: recruit.function.HideDoneState, + label: recruit.string.HideDoneState + } + + // hiding applicants related to archived vacancies from applicants view + const hideApplicantsFromArchivedVacanciesOption: ViewOptionModel = { + key: 'hideArchivedVacancies', + type: 'toggle', + defaultValue: true, + actionTarget: 'query', + action: recruit.function.HideArchivedVacancies, + label: recruit.string.HideApplicantsFromArchivedVacancies + } + builder.createDoc( view.class.Viewlet, core.space.Model, @@ -479,9 +499,10 @@ export function createModel (builder: Builder): void { hiddenKeys: ['name', 'attachedTo'], sortable: true }, - baseQuery: { - isDone: false, - '$lookup.space.archived': false + viewOptions: { + groupBy: [], + orderBy: [], + other: [applicationDoneOption, hideApplicantsFromArchivedVacanciesOption] } }, recruit.viewlet.ApplicantTable @@ -519,25 +540,6 @@ export function createModel (builder: Builder): void { ] } - const applicationDoneOption: ViewOptionModel = { - key: 'hideDoneState', - type: 'toggle', - defaultValue: true, - actionTarget: 'query', - action: recruit.function.HideDoneState, - label: recruit.string.HideDoneState - } - - // hiding applicants related to archived vacancies from applicants view - const hideApplicantsFromArchivedVacanciesOption: ViewOptionModel = { - key: 'hideArchivedVacancies', - type: 'toggle', - defaultValue: true, - actionTarget: 'query', - action: recruit.function.HideArchivedVacancies, - label: recruit.string.HideApplicantsFromArchivedVacancies - } - const applicantViewOptions = (colors: boolean, hides: boolean): ViewOptionsModel => { const model: ViewOptionsModel = { groupBy: ['status', 'assignee', 'space', 'createdBy', 'modifiedBy'], @@ -794,13 +796,8 @@ export function createModel (builder: Builder): void { { attachTo: recruit.class.Applicant, descriptor: task.viewlet.Kanban, - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - baseQuery: { - isDone: false, - '$lookup.space.archived': false - }, viewOptions: { - ...applicantViewOptions(false, false), + ...applicantViewOptions(false, true), groupDepth: 1 }, options: { diff --git a/plugins/task-resources/src/utils.ts b/plugins/task-resources/src/utils.ts index 894d075e88..e1a4cc86c4 100644 --- a/plugins/task-resources/src/utils.ts +++ b/plugins/task-resources/src/utils.ts @@ -17,7 +17,7 @@ import { type ViewQueryOption, type Viewlet } from '@hcengineering/view' -import { getCategories, getCategorySpaces } from '@hcengineering/view-resources' +import { getCategories, getCategorySpaces, concatCategories } from '@hcengineering/view-resources' /** * @public @@ -55,7 +55,7 @@ export async function updateTaskKanbanCategories ( viewlet.descriptor ) if (res !== undefined) { - categories = res + categories = concatCategories(res, categories) break } } @@ -78,7 +78,7 @@ export async function getTaskKanbanResultQuery ( if (viewOption.actionTarget !== 'query') continue const queryOption = viewOption as ViewQueryOption const f = await getResource(queryOption.action) - result = f(viewOptionsStore[queryOption.key] ?? queryOption.defaultValue, query) + result = f(viewOptionsStore[queryOption.key] ?? queryOption.defaultValue, result) } return result } diff --git a/plugins/view-resources/src/components/Table.svelte b/plugins/view-resources/src/components/Table.svelte index e1a47263fa..10ab2dcee5 100644 --- a/plugins/view-resources/src/components/Table.svelte +++ b/plugins/view-resources/src/components/Table.svelte @@ -24,9 +24,11 @@ Ref, SortingOrder, TxOperations, - getObjectValue + getObjectValue, + mergeQueries } from '@hcengineering/core' import notification from '@hcengineering/notification' + import { getResource } from '@hcengineering/platform' import { createQuery, getClient, reduceCalls, updateAttribute } from '@hcengineering/presentation' import ui, { Button, @@ -39,7 +41,14 @@ mouseAttractor, resizeObserver } from '@hcengineering/ui' - import { AttributeModel, BuildModelKey, BuildModelOptions } from '@hcengineering/view' + import { + AttributeModel, + BuildModelKey, + BuildModelOptions, + ViewOptionModel, + ViewOptions, + ViewQueryOption + } from '@hcengineering/view' import { deepEqual } from 'fast-equals' import { createEventDispatcher } from 'svelte' import { showMenu } from '../actions' @@ -59,6 +68,8 @@ export let tableId: string | undefined = undefined export let readonly = false export let showFooter = false + export let viewOptionsConfig: ViewOptionModel[] | undefined = undefined + export let viewOptions: ViewOptions | undefined = undefined export let totalQuery: DocumentQuery | undefined = undefined @@ -117,6 +128,29 @@ : { ...(options?.sort ?? {}), [sortKey]: sortOrder } } + async function getResultQuery ( + query: DocumentQuery, + viewOptions: ViewOptionModel[] | undefined, + viewOptionsStore: ViewOptions | undefined + ): Promise> { + if (viewOptions === undefined || viewOptionsStore === undefined) { + return query + } + let result: DocumentQuery = hierarchy.clone(query) + for (const viewOption of viewOptions) { + if (viewOption.actionTarget !== 'query') continue + const queryOption = viewOption as ViewQueryOption + const f = await getResource(queryOption.action) + const resultP = f(viewOptionsStore[queryOption.key] ?? queryOption.defaultValue, result) + if (resultP instanceof Promise) { + result = await resultP + } else { + result = resultP + } + } + return result + } + const update = reduceCalls(async function ( _class: Ref>, query: DocumentQuery, @@ -126,9 +160,11 @@ limit: number, options?: FindOptions ) { + const p = await getResultQuery(query, viewOptionsConfig, viewOptions) + const resultQuery = mergeQueries(p, query) loading += q.query( _class, - query, + resultQuery, (result) => { if (sortingFunction !== undefined) { const sf = sortingFunction diff --git a/plugins/view-resources/src/components/TableBrowser.svelte b/plugins/view-resources/src/components/TableBrowser.svelte index a8454a0bcb..f5404485e4 100644 --- a/plugins/view-resources/src/components/TableBrowser.svelte +++ b/plugins/view-resources/src/components/TableBrowser.svelte @@ -16,7 +16,7 @@ import type { Class, Doc, DocumentQuery, FindOptions, Ref } from '@hcengineering/core' import { ActionContext } from '@hcengineering/presentation' import { FadeOptions, Scroller, tableSP } from '@hcengineering/ui' - import { BuildModelKey } from '@hcengineering/view' + import { BuildModelKey, ViewOptions, Viewlet } from '@hcengineering/view' import { onMount } from 'svelte' import { focusStore, ListSelectionProvider, SelectDirection } from '../selection' import { LoadingProps } from '../utils' @@ -34,6 +34,8 @@ export let tableId: string | undefined = undefined export let fade: FadeOptions = tableSP export let prefferedSorting: string = 'modifiedOn' + export let viewOptions: ViewOptions | undefined = undefined + export let viewlet: Viewlet | undefined = undefined // If defined, will show a number of dummy items before real data will appear. export let loadingProps: LoadingProps | undefined = undefined @@ -79,6 +81,8 @@ checked={$selection ?? []} {prefferedSorting} {tableId} + {viewOptions} + viewOptionsConfig={viewlet?.viewOptions?.other} selection={listProvider.current($focusStore)} on:row-focus={(evt) => { listProvider.updateFocus(evt.detail) diff --git a/server-plugins/task-resources/src/index.ts b/server-plugins/task-resources/src/index.ts index 2f5943a6db..77dfc862cd 100644 --- a/server-plugins/task-resources/src/index.ts +++ b/server-plugins/task-resources/src/index.ts @@ -50,7 +50,7 @@ export async function OnStateUpdate (txes: TxCUD[], control: TriggerControl } } } - return [] + return result } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type