Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-5564: rework groupping and support PersonAccount #5525

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions models/contact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,16 @@ export function createModel (builder: Builder): void {
pinned: true
})

builder.mixin(core.class.Account, core.class.Class, view.mixin.Aggregation, {
createAggregationManager: contact.aggregation.CreatePersonAggregationManager,
setStoreFunc: contact.function.SetPersonStore,
filterFunc: contact.function.PersonFilterFunction
})

builder.mixin(core.class.Account, core.class.Class, view.mixin.Groupping, {
grouppingManager: contact.aggregation.GrouppingPersonManager
})

builder.mixin(contact.mixin.Employee, core.class.Class, view.mixin.ObjectEditor, {
editor: contact.component.EditEmployee,
pinned: true
Expand Down
6 changes: 4 additions & 2 deletions models/contact/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { contactId } from '@hcengineering/contact'
import contact from '@hcengineering/contact-resources/src/plugin'
import type { Client, Doc, Ref } from '@hcengineering/core'
import type { Client, Doc, DocManager, Ref } from '@hcengineering/core'
import { type ObjectSearchCategory, type ObjectSearchFactory } from '@hcengineering/model-presentation'
import { type NotificationGroup } from '@hcengineering/notification'
import { type IntlString, mergeIds, type Resource } from '@hcengineering/platform'
Expand Down Expand Up @@ -139,6 +139,8 @@ export default mergeIds(contactId, contact, {
GetContactLastName: '' as Resource<TemplateFieldFunc>,
ContactTitleProvider: '' as Resource<(client: Client, ref: Ref<Doc>, doc?: Doc) => Promise<string>>,
ChannelTitleProvider: '' as Resource<(client: Client, ref: Ref<Doc>, doc?: Doc) => Promise<string>>,
ChannelIdentifierProvider: '' as Resource<(client: Client, ref: Ref<Doc>, doc?: Doc) => Promise<string>>
ChannelIdentifierProvider: '' as Resource<(client: Client, ref: Ref<Doc>, doc?: Doc) => Promise<string>>,
SetPersonStore: '' as Resource<(manager: DocManager<any>) => void>,
PersonFilterFunction: '' as Resource<(doc: Doc, target: Doc) => boolean>
}
})
2 changes: 1 addition & 1 deletion models/core/src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class TSpacesTypeData extends TSpace implements RolesAssignment {
}

@Model(core.class.Account, core.class.Doc, DOMAIN_MODEL)
@UX(core.string.Account)
@UX(core.string.Account, undefined, undefined, 'name')
ThetaDR marked this conversation as resolved.
Show resolved Hide resolved
export class TAccount extends TDoc implements Account {
email!: string
role!: AccountRole
Expand Down
8 changes: 7 additions & 1 deletion models/tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ function defineSortAndGrouping (builder: Builder): void {
})

builder.mixin(tracker.class.Component, core.class.Class, view.mixin.Aggregation, {
createAggregationManager: tracker.aggregation.CreateComponentAggregationManager
createAggregationManager: tracker.aggregation.CreateComponentAggregationManager,
setStoreFunc: tracker.function.SetComponentStore,
filterFunc: tracker.function.ComponentFilterFunction
})

builder.mixin(tracker.class.Component, core.class.Class, view.mixin.Groupping, {
grouppingManager: tracker.aggregation.GrouppingComponentManager
})

builder.mixin(tracker.class.TypeIssuePriority, core.class.Class, view.mixin.AllValuesFunc, {
Expand Down
7 changes: 6 additions & 1 deletion models/tracker/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
import { type DocUpdateMessageViewlet } from '@hcengineering/activity'
import { type ChatMessageViewlet } from '@hcengineering/chunter'
import { type StatusCategory, type Doc, type Ref } from '@hcengineering/core'
import { type StatusCategory, type Doc, type Ref, type DocManager } from '@hcengineering/core'
import { type ObjectSearchCategory, type ObjectSearchFactory } from '@hcengineering/model-presentation'
import { type NotificationGroup, type NotificationType } from '@hcengineering/notification'
import { mergeIds, type IntlString, type Resource } from '@hcengineering/platform'
Expand Down Expand Up @@ -119,5 +119,10 @@ export default mergeIds(trackerId, tracker, {
Started: '' as Ref<StatusCategory>,
Completed: '' as Ref<StatusCategory>,
Canceled: '' as Ref<StatusCategory>
},

function: {
SetComponentStore: '' as Resource<(manager: DocManager<any>) => void>,
ComponentFilterFunction: '' as Resource<(doc: Doc, target: Doc) => boolean>
}
})
3 changes: 3 additions & 0 deletions models/view/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
DOMAIN_MODEL,
type Data,
type Doc,
type DocManager,
type DocumentQuery,
type Domain,
type Ref,
Expand Down Expand Up @@ -273,6 +274,8 @@ export class TGroupping extends TClass implements Groupping {
@Mixin(view.mixin.Aggregation, core.class.Class)
export class TAggregation extends TClass implements Aggregation {
createAggregationManager!: CreateAggregationManagerFunc
setStoreFunc!: Resource<(manager: DocManager<any>) => void>
filterFunc!: Resource<(doc: Doc, target: Doc) => boolean>
}

@Mixin(view.mixin.ObjectIcon, core.class.Class)
Expand Down
21 changes: 14 additions & 7 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,29 +306,36 @@ export class AggregateValue {
*/
export type CategoryType = number | string | undefined | Ref<Doc> | AggregateValue

export interface IDocManager<T extends Doc> {
get: (ref: Ref<T>) => T | undefined
getDocs: () => T[]
getIdMap: () => IdMap<T>
filter: (predicate: (value: T) => boolean) => T[]
}

/**
* @public
*/
export class DocManager {
protected readonly byId: IdMap<Doc>
export class DocManager<T extends Doc> implements IDocManager<T> {
protected readonly byId: IdMap<T>

constructor (protected readonly docs: Doc[]) {
constructor (protected readonly docs: T[]) {
this.byId = toIdMap(docs)
}

get (ref: Ref<Doc>): Doc | undefined {
get (ref: Ref<T>): T | undefined {
return this.byId.get(ref)
}

getDocs (): Doc[] {
getDocs (): T[] {
return this.docs
}

getIdMap (): IdMap<Doc> {
getIdMap (): IdMap<T> {
return this.byId
}

filter (predicate: (value: Doc) => boolean): Doc[] {
filter (predicate: (value: T) => boolean): T[] {
return this.docs.filter(predicate)
}
}
Expand Down
11 changes: 9 additions & 2 deletions packages/kanban/src/components/KanbanRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,15 @@
let limitedObjects: IdMap<DocWithRank> = new Map()

const docQuery = createQuery()

$: groupQuery = { ...query, [groupByKey]: typeof state === 'object' ? { $in: state.values } : state }
$: groupQuery = {
...query,
[groupByKey]:
typeof state === 'object'
? state.name !== undefined
? { $in: state.values.flatMap((x) => x._id) }
: undefined
: state
}

$: void limiter.add(async () => {
docQuery.query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
-->
<script lang="ts">
import { PersonAccount } from '@hcengineering/contact'
import { Ref } from '@hcengineering/core'
import { AggregateValue, Ref } from '@hcengineering/core'
import { IconSize } from '@hcengineering/ui'
import { personAccountByIdStore } from '../utils'
import PersonAccountPresenter from './PersonAccountPresenter.svelte'
import { personStore } from '..'

export let value: Ref<PersonAccount>
export let value: Ref<PersonAccount> | AggregateValue
export let avatarSize: IconSize = 'x-small'
export let disabled: boolean = false
export let inline: boolean = false
export let accent: boolean = false
export let compact = false

$: account = $personAccountByIdStore.get(value)
$: _value = $personStore.get(typeof value === 'string' ? value : (value?.values?.[0]?._id as Ref<PersonAccount>))
$: account = $personAccountByIdStore.get(_value?._id ?? (value as Ref<PersonAccount>))
</script>

{#if account}
Expand Down
33 changes: 27 additions & 6 deletions plugins/contact-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
//

import {
getGravatarUrl,
getName,
type AvatarInfo,
type Channel,
type AvatarInfo,
type Contact,
type Person
getGravatarUrl,
getName,
type Person,
type PersonAccount
} from '@hcengineering/contact'
import {
DocManager,
type Class,
type Client,
type Data,
Expand Down Expand Up @@ -120,8 +122,9 @@ import NameChangedActivityMessage from './components/activity/NameChangedActivit
import IconAddMember from './components/icons/AddMember.svelte'
import ExpandRightDouble from './components/icons/ExpandRightDouble.svelte'
import IconMembers from './components/icons/Members.svelte'
import { AggregationManager } from '@hcengineering/view-resources'

import { get } from 'svelte/store'
import { get, writable } from 'svelte/store'
import contact from './plugin'
import {
channelIdentifierProvider,
Expand All @@ -140,6 +143,7 @@ import {
getCurrentEmployeeName,
getCurrentEmployeePosition,
getPersonTooltip,
grouppingPersonManager,
resolveLocation
} from './utils'

Expand Down Expand Up @@ -293,6 +297,16 @@ async function openChannelURL (doc: Channel): Promise<void> {
}
}

function filterPerson (doc: PersonAccount, target: PersonAccount): boolean {
return doc.person === target.person && doc._id !== target._id
}

export const personStore = writable<DocManager<PersonAccount>>(new DocManager([]))

function setStore (manager: DocManager<PersonAccount>): void {
personStore.set(manager)
}

export interface PersonLabelTooltip {
personLabel?: IntlString
placeholderLabel?: IntlString
Expand Down Expand Up @@ -431,9 +445,16 @@ export default async (): Promise<Resources> => ({
ContactTitleProvider: contactTitleProvider,
PersonTooltipProvider: getPersonTooltip,
ChannelTitleProvider: channelTitleProvider,
ChannelIdentifierProvider: channelIdentifierProvider
ChannelIdentifierProvider: channelIdentifierProvider,
SetPersonStore: setStore,
PersonFilterFunction: filterPerson
},
resolver: {
Location: resolveLocation
},
aggregation: {
// eslint-disable-next-line @typescript-eslint/unbound-method
CreatePersonAggregationManager: AggregationManager.create,
GrouppingPersonManager: grouppingPersonManager
}
})
11 changes: 10 additions & 1 deletion plugins/contact-resources/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import contact, { contactId } from '@hcengineering/contact'
import { type Client, type Doc } from '@hcengineering/core'
import { type IntlString, mergeIds, type Resource } from '@hcengineering/platform'
import { type LabelAndProps, type Location } from '@hcengineering/ui'
import { type FilterFunction, type SortFunc } from '@hcengineering/view'
import {
type CreateAggregationManagerFunc,
type GrouppingManagerResource,
type FilterFunction,
type SortFunc
} from '@hcengineering/view'

export default mergeIds(contactId, contact, {
string: {
Expand Down Expand Up @@ -86,5 +91,9 @@ export default mergeIds(contactId, contact, {
FilterChannelHasMessagesResult: '' as FilterFunction,
FilterChannelHasNewMessagesResult: '' as FilterFunction,
PersonTooltipProvider: '' as Resource<(client: Client, doc?: Doc | null) => Promise<LabelAndProps | undefined>>
},
aggregation: {
CreatePersonAggregationManager: '' as CreateAggregationManagerFunc,
GrouppingPersonManager: '' as GrouppingManagerResource
}
})
Loading