update show empty groups (#2897)

Signed-off-by: Ruslan Bayandinov <wazsone@ya.ru>
This commit is contained in:
Ruslan Bayandinov 2023-04-05 18:23:55 +06:00 committed by GitHub
parent 972e82eb32
commit 5130eb8862
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 38 deletions

View File

@ -63,9 +63,9 @@ import type {
ViewOptionsModel, ViewOptionsModel,
ViewOptions, ViewOptions,
AllValuesFunc, AllValuesFunc,
GetAllValuesFunc,
LinkProvider, LinkProvider,
ObjectPanel, ObjectPanel
AllValuesFuncGetter
} from '@hcengineering/view' } from '@hcengineering/view'
import view from './plugin' import view from './plugin'
@ -221,7 +221,7 @@ export class TSortFuncs extends TClass implements ClassSortFuncs {
@Mixin(view.mixin.AllValuesFunc, core.class.Class) @Mixin(view.mixin.AllValuesFunc, core.class.Class)
export class TAllValuesFunc extends TClass implements AllValuesFunc { export class TAllValuesFunc extends TClass implements AllValuesFunc {
func!: Resource<AllValuesFuncGetter> func!: GetAllValuesFunc
} }
@Model(view.class.ViewletPreference, preference.class.Preference) @Model(view.class.ViewletPreference, preference.class.Preference)

View File

@ -17,7 +17,7 @@ import type { IntlString, Metadata, Resource } from '@hcengineering/platform'
import { mergeIds } from '@hcengineering/platform' import { mergeIds } from '@hcengineering/platform'
import { IssueDraft } from '@hcengineering/tracker' import { IssueDraft } from '@hcengineering/tracker'
import { AnyComponent, Location } from '@hcengineering/ui' import { AnyComponent, Location } from '@hcengineering/ui'
import { AllValuesFuncGetter, SortFunc, Viewlet, ViewletDescriptor, ViewQueryAction } from '@hcengineering/view' import { GetAllValuesFunc, SortFunc, Viewlet, ViewletDescriptor, ViewQueryAction } from '@hcengineering/view'
import tracker, { trackerId } from '../../tracker/lib' import tracker, { trackerId } from '../../tracker/lib'
export default mergeIds(trackerId, tracker, { export default mergeIds(trackerId, tracker, {
@ -389,8 +389,8 @@ export default mergeIds(trackerId, tracker, {
IssuePrioritySort: '' as SortFunc, IssuePrioritySort: '' as SortFunc,
SprintSort: '' as SortFunc, SprintSort: '' as SortFunc,
SubIssueQuery: '' as ViewQueryAction, SubIssueQuery: '' as ViewQueryAction,
GetAllPriority: '' as Resource<AllValuesFuncGetter>, GetAllPriority: '' as GetAllValuesFunc,
GetAllComponents: '' as Resource<AllValuesFuncGetter>, GetAllComponents: '' as GetAllValuesFunc,
GetAllSprints: '' as Resource<AllValuesFuncGetter> GetAllSprints: '' as GetAllValuesFunc
} }
}) })

View File

@ -24,7 +24,6 @@ import core, {
DocumentUpdate, DocumentUpdate,
Ref, Ref,
SortingOrder, SortingOrder,
Space,
StatusCategory, StatusCategory,
StatusValue, StatusValue,
toIdMap, toIdMap,
@ -464,25 +463,19 @@ export function subIssueQuery (value: boolean, query: DocumentQuery<Issue>): Doc
async function getAllSomething ( async function getAllSomething (
_class: Ref<Class<Doc>>, _class: Ref<Class<Doc>>,
space: Ref<Space> | undefined, query: DocumentQuery<Doc> | undefined,
onUpdate: () => void, onUpdate: () => void,
queryId: Ref<Doc> queryId: Ref<Doc>
): Promise<any[] | undefined> { ): Promise<any[] | undefined> {
const promise = new Promise<Array<Ref<Doc>>>((resolve, reject) => { const promise = new Promise<Array<Ref<Doc>>>((resolve, reject) => {
let refresh: boolean = false let refresh: boolean = false
const lq = CategoryQuery.getLiveQuery(queryId) const lq = CategoryQuery.getLiveQuery(queryId)
refresh = lq.query( refresh = lq.query(_class, query ?? {}, (res) => {
_class,
{
space
},
(res) => {
const result = res.map((p) => p._id) const result = res.map((p) => p._id)
CategoryQuery.results.set(queryId, result) CategoryQuery.results.set(queryId, result)
resolve(result) resolve(result)
onUpdate() onUpdate()
} })
)
if (!refresh) { if (!refresh) {
resolve(CategoryQuery.results.get(queryId) ?? []) resolve(CategoryQuery.results.get(queryId) ?? [])
@ -492,7 +485,7 @@ async function getAllSomething (
} }
export async function getAllPriority ( export async function getAllPriority (
space: Ref<Space> | undefined, query: DocumentQuery<Doc> | undefined,
onUpdate: () => void, onUpdate: () => void,
queryId: Ref<Doc> queryId: Ref<Doc>
): Promise<any[] | undefined> { ): Promise<any[] | undefined> {
@ -500,19 +493,19 @@ export async function getAllPriority (
} }
export async function getAllComponents ( export async function getAllComponents (
space: Ref<Project> | undefined, query: DocumentQuery<Doc> | undefined,
onUpdate: () => void, onUpdate: () => void,
queryId: Ref<Doc> queryId: Ref<Doc>
): Promise<any[] | undefined> { ): Promise<any[] | undefined> {
return await getAllSomething(tracker.class.Component, space, onUpdate, queryId) return await getAllSomething(tracker.class.Component, query, onUpdate, queryId)
} }
export async function getAllSprints ( export async function getAllSprints (
space: Ref<Project> | undefined, query: DocumentQuery<Doc> | undefined,
onUpdate: () => void, onUpdate: () => void,
queryId: Ref<Doc> queryId: Ref<Doc>
): Promise<any[] | undefined> { ): Promise<any[] | undefined> {
return await getAllSomething(tracker.class.Sprint, space, onUpdate, queryId) return await getAllSomething(tracker.class.Sprint, query, onUpdate, queryId)
} }
export function subIssueListProvider (subIssues: Issue[], target: Ref<Issue>): void { export function subIssueListProvider (subIssues: Issue[], target: Ref<Issue>): void {

View File

@ -147,6 +147,7 @@
{docs} {docs}
{_class} {_class}
{space} {space}
query={resultQuery}
{lookup} {lookup}
loadingPropsLength={getLoadingElementsLength(loadingProps, options)} loadingPropsLength={getLoadingElementsLength(loadingProps, options)}
{baseMenuClass} {baseMenuClass}

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { CategoryType, Class, Doc, generateId, Lookup, Ref, Space } from '@hcengineering/core' import { CategoryType, Class, Doc, DocumentQuery, generateId, Lookup, Ref, Space } from '@hcengineering/core'
import { getResource, IntlString } from '@hcengineering/platform' import { getResource, IntlString } from '@hcengineering/platform'
import { getClient, statusStore } from '@hcengineering/presentation' import { getClient, statusStore } from '@hcengineering/presentation'
import { AnyComponent } from '@hcengineering/ui' import { AnyComponent } from '@hcengineering/ui'
@ -28,6 +28,7 @@
export let docs: Doc[] export let docs: Doc[]
export let _class: Ref<Class<Doc>> export let _class: Ref<Class<Doc>>
export let space: Ref<Space> | undefined export let space: Ref<Space> | undefined
export let query: DocumentQuery<Doc> | undefined
export let lookup: Lookup<Doc> export let lookup: Lookup<Doc>
export let loadingPropsLength: number | undefined export let loadingPropsLength: number | undefined
export let baseMenuClass: Ref<Class<Doc>> | undefined export let baseMenuClass: Ref<Class<Doc>> | undefined
@ -82,7 +83,7 @@
const categoryFunc = viewOption as CategoryOption const categoryFunc = viewOption as CategoryOption
if (viewOptions[viewOption.key] ?? viewOption.defaultValue) { if (viewOptions[viewOption.key] ?? viewOption.defaultValue) {
const f = await getResource(categoryFunc.action) const f = await getResource(categoryFunc.action)
const res = hierarchy.clone(await f(_class, space, groupByKey, update, queryId, $statusStore)) const res = hierarchy.clone(await f(_class, query, groupByKey, update, queryId, $statusStore))
if (res !== undefined) { if (res !== undefined) {
categories = res categories = res
return return

View File

@ -1,4 +1,4 @@
import core, { Class, Doc, Ref, SortingOrder, Space, StatusManager } from '@hcengineering/core' import core, { Class, Doc, DocumentQuery, Ref, SortingOrder, StatusManager } from '@hcengineering/core'
import { getResource } from '@hcengineering/platform' import { getResource } from '@hcengineering/platform'
import { createQuery, getAttributePresenterClass, getClient, LiveQuery } from '@hcengineering/presentation' import { createQuery, getAttributePresenterClass, getClient, LiveQuery } from '@hcengineering/presentation'
import { getCurrentLocation, locationToUrl } from '@hcengineering/ui' import { getCurrentLocation, locationToUrl } from '@hcengineering/ui'
@ -104,7 +104,7 @@ export function migrateViewOpttions (): void {
export async function showEmptyGroups ( export async function showEmptyGroups (
_class: Ref<Class<Doc>>, _class: Ref<Class<Doc>>,
space: Ref<Space> | undefined, query: DocumentQuery<Doc> | undefined,
key: string, key: string,
onUpdate: () => void, onUpdate: () => void,
queryId: Ref<Doc>, queryId: Ref<Doc>,
@ -128,7 +128,7 @@ export async function showEmptyGroups (
const mixin = hierarchy.as(attributeClass, view.mixin.AllValuesFunc) const mixin = hierarchy.as(attributeClass, view.mixin.AllValuesFunc)
if (mixin.func !== undefined) { if (mixin.func !== undefined) {
const f = await getResource(mixin.func) const f = await getResource(mixin.func)
const res = await f(space, onUpdate, queryId) const res = await f(query, onUpdate, queryId)
if (res !== undefined) { if (res !== undefined) {
return await groupByCategory(client, _class, key, res, mgr, viewletDescriptorId) return await groupByCategory(client, _class, key, res, mgr, viewletDescriptorId)
} }

View File

@ -254,17 +254,15 @@ export interface ClassSortFuncs extends Class<Doc> {
/** /**
* @public * @public
*/ */
export type AllValuesFuncGetter = ( export type GetAllValuesFunc = Resource<
space: Ref<Space> | undefined, (query: DocumentQuery<Doc> | undefined, onUpdate: () => void, queryId: Ref<Doc>) => Promise<any[] | undefined>
onUpdate: () => void, >
queryId: Ref<Doc>
) => Promise<any[] | undefined>
/** /**
* @public * @public
*/ */
export interface AllValuesFunc extends Class<Doc> { export interface AllValuesFunc extends Class<Doc> {
func: Resource<AllValuesFuncGetter> func: GetAllValuesFunc
} }
/** /**
@ -506,7 +504,7 @@ export interface ViewOption {
*/ */
export type ViewCategoryActionFunc = ( export type ViewCategoryActionFunc = (
_class: Ref<Class<Doc>>, _class: Ref<Class<Doc>>,
space: Ref<Space> | undefined, query: DocumentQuery<Doc> | undefined,
key: string, key: string,
onUpdate: () => void, onUpdate: () => void,
queryId: Ref<Doc>, queryId: Ref<Doc>,