mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 11:31:57 +03:00
Improve Channels table sort (#2168)
This commit is contained in:
parent
3b25cc2b83
commit
0f87f42706
@ -77,7 +77,7 @@ export class TContact extends TDoc implements Contact {
|
||||
}
|
||||
|
||||
@Model(contact.class.Channel, core.class.AttachedDoc, DOMAIN_CHANNEL)
|
||||
@UX(contact.string.Channel, contact.icon.Person, undefined, 'lastMessage')
|
||||
@UX(contact.string.Channel, contact.icon.Person)
|
||||
export class TChannel extends TAttachedDoc implements Channel {
|
||||
@Prop(TypeRef(contact.class.ChannelProvider), contact.string.ChannelProvider)
|
||||
provider!: Ref<ChannelProvider>
|
||||
@ -184,7 +184,14 @@ export function createModel (builder: Builder): void {
|
||||
{
|
||||
attachTo: contact.class.Member,
|
||||
descriptor: view.viewlet.Table,
|
||||
config: ['', '$lookup.contact.$lookup.channels', 'modifiedOn'],
|
||||
config: [
|
||||
'',
|
||||
{
|
||||
key: '$lookup.contact.$lookup.channels',
|
||||
sortingKey: ['$lookup.contact.$lookup.channels.lastMessage', '$lookup.contact.channels']
|
||||
},
|
||||
'modifiedOn'
|
||||
],
|
||||
hiddenKeys: ['name', 'contact']
|
||||
},
|
||||
contact.viewlet.TableMember
|
||||
@ -207,7 +214,7 @@ export function createModel (builder: Builder): void {
|
||||
'attachments',
|
||||
'modifiedOn',
|
||||
{ key: '', presenter: view.component.RolePresenter, label: view.string.Role },
|
||||
'$lookup.channels'
|
||||
{ key: '$lookup.channels', sortingKey: ['$lookup.channels.lastMessage', 'channels'] }
|
||||
],
|
||||
hiddenKeys: ['name']
|
||||
},
|
||||
|
@ -177,7 +177,13 @@ export function createModel (builder: Builder): void {
|
||||
{
|
||||
attachTo: lead.mixin.Customer,
|
||||
descriptor: view.viewlet.Table,
|
||||
config: ['', '$lookup._class', 'leads', 'modifiedOn', '$lookup.channels'],
|
||||
config: [
|
||||
'',
|
||||
'$lookup._class',
|
||||
'leads',
|
||||
'modifiedOn',
|
||||
{ key: '$lookup.channels', sortingKey: ['$lookup.channels.lastMessage', 'channels'] }
|
||||
],
|
||||
hiddenKeys: ['name']
|
||||
},
|
||||
lead.viewlet.TableCustomer
|
||||
@ -198,7 +204,10 @@ export function createModel (builder: Builder): void {
|
||||
'attachments',
|
||||
'comments',
|
||||
'modifiedOn',
|
||||
'$lookup.attachedTo.$lookup.channels'
|
||||
{
|
||||
key: '$lookup.attachedTo.$lookup.channels',
|
||||
sortingKey: ['$lookup.attachedTo.$lookup.channels.lastMessage', '$lookup.attachedTo.channels']
|
||||
}
|
||||
]
|
||||
},
|
||||
lead.viewlet.TableLead
|
||||
|
@ -283,7 +283,7 @@ export function createModel (builder: Builder): void {
|
||||
}
|
||||
},
|
||||
'modifiedOn',
|
||||
'$lookup.channels'
|
||||
{ key: '$lookup.channels', sortingKey: ['$lookup.channels.lastMessage', 'channels'] }
|
||||
],
|
||||
hiddenKeys: ['name']
|
||||
},
|
||||
@ -330,7 +330,10 @@ export function createModel (builder: Builder): void {
|
||||
'attachments',
|
||||
'comments',
|
||||
'modifiedOn',
|
||||
'$lookup.attachedTo.$lookup.channels'
|
||||
{
|
||||
key: '$lookup.attachedTo.$lookup.channels',
|
||||
sortingKey: ['$lookup.attachedTo.$lookup.channels.lastMessage', '$lookup.attachedTo.channels']
|
||||
}
|
||||
]
|
||||
},
|
||||
recruit.viewlet.TableApplicant
|
||||
|
@ -64,11 +64,17 @@
|
||||
async function update (
|
||||
_class: Ref<Class<Doc>>,
|
||||
query: DocumentQuery<Doc>,
|
||||
sortKey: string,
|
||||
sortKey: string | string[],
|
||||
sortOrder: SortingOrder,
|
||||
lookup: Lookup<Doc>,
|
||||
options?: FindOptions<Doc>
|
||||
) {
|
||||
const sort = Array.isArray(sortKey)
|
||||
? sortKey.reduce((acc: Record<string, SortingOrder>, val) => {
|
||||
acc[val] = sortOrder
|
||||
return acc
|
||||
}, {})
|
||||
: { [sortKey]: sortOrder }
|
||||
const update = q.query(
|
||||
_class,
|
||||
query,
|
||||
@ -81,7 +87,7 @@
|
||||
dispatch('content', objects)
|
||||
loading = loading === 1 ? 0 : -1
|
||||
},
|
||||
{ sort: { [sortKey]: sortOrder }, limit: 200, lookup, ...options }
|
||||
{ sort, limit: 200, lookup, ...options }
|
||||
)
|
||||
if (update && ++loading > 0) {
|
||||
objects = []
|
||||
|
@ -67,8 +67,13 @@ export async function getObjectPresenter (
|
||||
}
|
||||
const presenter = await getResource(presenterMixin.presenter)
|
||||
const key = preserveKey.sortingKey ?? preserveKey.key
|
||||
const sortingKey =
|
||||
clazz.sortingKey !== undefined ? (key.length > 0 ? key + '.' + clazz.sortingKey : clazz.sortingKey) : key
|
||||
const sortingKey = Array.isArray(key)
|
||||
? key
|
||||
: clazz.sortingKey !== undefined
|
||||
? key.length > 0
|
||||
? key + '.' + clazz.sortingKey
|
||||
: clazz.sortingKey
|
||||
: key
|
||||
return {
|
||||
key: preserveKey.key,
|
||||
_class,
|
||||
@ -118,7 +123,11 @@ async function getAttributePresenter (
|
||||
throw new Error('attribute presenter not found for ' + JSON.stringify(preserveKey))
|
||||
}
|
||||
const resultKey = preserveKey.sortingKey ?? preserveKey.key
|
||||
const sortingKey = attribute.type._class === core.class.ArrOf ? resultKey + '.length' : resultKey
|
||||
const sortingKey = Array.isArray(resultKey)
|
||||
? resultKey
|
||||
: attribute.type._class === core.class.ArrOf
|
||||
? resultKey + '.length'
|
||||
: resultKey
|
||||
const presenter = await getResource(presenterMixin.presenter)
|
||||
|
||||
return {
|
||||
@ -240,7 +249,7 @@ export async function buildModel (options: BuildModelOptions): Promise<Attribute
|
||||
return errorPresenter
|
||||
}
|
||||
})
|
||||
return (await (await Promise.all(model)).filter((a) => a !== undefined)) as AttributeModel[]
|
||||
return (await Promise.all(model)).filter((a) => a !== undefined) as AttributeModel[]
|
||||
}
|
||||
|
||||
export async function deleteObject (client: TxOperations, object: Doc): Promise<void> {
|
||||
|
@ -331,7 +331,7 @@ export interface BuildModelKey {
|
||||
props?: Record<string, any>
|
||||
|
||||
label?: IntlString
|
||||
sortingKey?: string
|
||||
sortingKey?: string | string[]
|
||||
|
||||
// On client sorting function
|
||||
sortingFunction?: (a: Doc, b: Doc) => number
|
||||
@ -347,7 +347,7 @@ export interface AttributeModel {
|
||||
presenter: AnySvelteComponent
|
||||
// Extra properties for component
|
||||
props?: Record<string, any>
|
||||
sortingKey: string
|
||||
sortingKey: string | string[]
|
||||
// Extra icon if applicable
|
||||
icon?: Asset
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user