Add AttributeFilter in Activity (#2608)

Signed-off-by: Alexander Platov <sas_lord@mail.ru>
This commit is contained in:
Alexander Platov 2023-02-09 06:09:53 +03:00 committed by GitHub
parent 8108f2e59b
commit 96fac678fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 66 additions and 18 deletions

View File

@ -31,6 +31,7 @@
"@hcengineering/platform": "^0.6.8", "@hcengineering/platform": "^0.6.8",
"@hcengineering/model-core": "^0.6.0", "@hcengineering/model-core": "^0.6.0",
"@hcengineering/activity": "^0.6.0", "@hcengineering/activity": "^0.6.0",
"@hcengineering/ui": "^0.6.3" "@hcengineering/ui": "^0.6.3",
"@hcengineering/activity-resources": "^0.6.1"
} }
} }

View File

@ -14,7 +14,7 @@
// //
import type { ActivityFilter, DisplayTx, TxViewlet } from '@hcengineering/activity' import type { ActivityFilter, DisplayTx, TxViewlet } from '@hcengineering/activity'
import activity from '@hcengineering/activity' import activity from './plugin'
import core, { Class, Doc, DocumentQuery, DOMAIN_MODEL, Ref, Tx } from '@hcengineering/core' import core, { Class, Doc, DocumentQuery, DOMAIN_MODEL, Ref, Tx } from '@hcengineering/core'
import { Builder, Model } from '@hcengineering/model' import { Builder, Model } from '@hcengineering/model'
import { TDoc } from '@hcengineering/model-core' import { TDoc } from '@hcengineering/model-core'
@ -39,9 +39,16 @@ export class TTxViewlet extends TDoc implements TxViewlet {
@Model(activity.class.ActivityFilter, core.class.Class, DOMAIN_MODEL) @Model(activity.class.ActivityFilter, core.class.Class, DOMAIN_MODEL)
export class TActivityFilter extends TDoc implements ActivityFilter { export class TActivityFilter extends TDoc implements ActivityFilter {
label!: IntlString label!: IntlString
filter!: Resource<(tx: DisplayTx) => boolean> filter!: Resource<(tx: DisplayTx, _class?: Ref<Doc>) => boolean>
} }
export function createModel (builder: Builder): void { export function createModel (builder: Builder): void {
builder.createModel(TTxViewlet, TActivityFilter) builder.createModel(TTxViewlet, TActivityFilter)
builder.createDoc(activity.class.ActivityFilter, core.space.Model, {
label: activity.string.Attributes,
filter: activity.filter.AttributeFilter
})
} }
export default activity

View File

@ -0,0 +1,29 @@
//
// Copyright © 2022 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import type { DisplayTx } from '@hcengineering/activity'
import { activityId } from '@hcengineering/activity'
import activity from '@hcengineering/activity-resources/src/plugin'
import type { Resource, IntlString } from '@hcengineering/platform'
import { mergeIds } from '@hcengineering/platform'
import { Doc, Ref } from '@hcengineering/core'
export default mergeIds(activityId, activity, {
filter: {
AttributeFilter: '' as Resource<(tx: DisplayTx, _class?: Ref<Doc>) => boolean>
},
string: {
Attributes: '' as IntlString
}
})

View File

@ -16,7 +16,7 @@
import type { DisplayTx, TxViewlet } from '@hcengineering/activity' import type { DisplayTx, TxViewlet } from '@hcengineering/activity'
import { attachmentId } from '@hcengineering/attachment' import { attachmentId } from '@hcengineering/attachment'
import attachment from '@hcengineering/attachment-resources/src/plugin' import attachment from '@hcengineering/attachment-resources/src/plugin'
import type { Ref } from '@hcengineering/core' import type { Ref, Doc } from '@hcengineering/core'
import type { IntlString, Resource } from '@hcengineering/platform' import type { IntlString, Resource } from '@hcengineering/platform'
import { mergeIds } from '@hcengineering/platform' import { mergeIds } from '@hcengineering/platform'
import type { AnyComponent } from '@hcengineering/ui' import type { AnyComponent } from '@hcengineering/ui'
@ -51,6 +51,6 @@ export default mergeIds(attachmentId, attachment, {
Attachments: '' as Ref<ActionCategory> Attachments: '' as Ref<ActionCategory>
}, },
filter: { filter: {
AttachmentsFilter: '' as Resource<(tx: DisplayTx) => boolean> AttachmentsFilter: '' as Resource<(tx: DisplayTx, _class?: Ref<Doc>) => boolean>
} }
}) })

View File

@ -16,7 +16,7 @@
import type { DisplayTx, TxViewlet } from '@hcengineering/activity' import type { DisplayTx, TxViewlet } from '@hcengineering/activity'
import { Channel, chunterId } from '@hcengineering/chunter' import { Channel, chunterId } from '@hcengineering/chunter'
import chunter from '@hcengineering/chunter-resources/src/plugin' import chunter from '@hcengineering/chunter-resources/src/plugin'
import type { Ref, Space } from '@hcengineering/core' import type { Ref, Space, Doc } from '@hcengineering/core'
import type { IntlString, Resource } from '@hcengineering/platform' import type { IntlString, Resource } from '@hcengineering/platform'
import { mergeIds } from '@hcengineering/platform' import { mergeIds } from '@hcengineering/platform'
import type { AnyComponent } from '@hcengineering/ui' import type { AnyComponent } from '@hcengineering/ui'
@ -93,7 +93,7 @@ export default mergeIds(chunterId, chunter, {
ChunterBrowserVisible: '' as Resource<(spaces: Space[]) => boolean> ChunterBrowserVisible: '' as Resource<(spaces: Space[]) => boolean>
}, },
filter: { filter: {
CommentsFilter: '' as Resource<(tx: DisplayTx) => boolean>, CommentsFilter: '' as Resource<(tx: DisplayTx, _class?: Ref<Doc>) => boolean>,
BacklinksFilter: '' as Resource<(tx: DisplayTx) => boolean> BacklinksFilter: '' as Resource<(tx: DisplayTx, _class?: Ref<Doc>) => boolean>
} }
}) })

View File

@ -14,6 +14,7 @@
"Added": "added", "Added": "added",
"Removed": "removed", "Removed": "removed",
"From": "from", "From": "from",
"All": "All" "All": "All",
"Attributes": "Attributes"
} }
} }

View File

@ -14,6 +14,7 @@
"Added": "добавила(а)", "Added": "добавила(а)",
"Removed": "удалил(а)", "Removed": "удалил(а)",
"From": "из", "From": "из",
"All": "Все" "All": "Все",
"Attributes": "Атрибуты"
} }
} }

View File

@ -117,8 +117,8 @@
) )
} }
let filterActions: ((tx: DisplayTx) => boolean)[] = [] // Enabled filters let filterActions: ((tx: DisplayTx, _class?: Ref<Doc>) => boolean)[] = [] // Enabled filters
const updateFiltered = () => (filtered = txes.filter((it) => filterActions.some((f) => f(it)))) const updateFiltered = () => (filtered = txes.filter((it) => filterActions.some((f) => f(it, object._class))))
async function updateFilterActions (fls: ActivityFilter[], selected: Ref<Doc>[] | 'All'): Promise<void> { async function updateFilterActions (fls: ActivityFilter[], selected: Ref<Doc>[] | 'All'): Promise<void> {
if (selected === 'All' || !Array.isArray(selected)) filterActions = [() => true] if (selected === 'All' || !Array.isArray(selected)) filterActions = [() => true]
else { else {
@ -133,7 +133,7 @@
setTimeout(() => updateFiltered(), 0) setTimeout(() => updateFiltered(), 0)
} }
$: updateFilterActions(filters, selectedFilter) $: updateFilterActions(filters, selectedFilter)
$: filtered = txes.filter((it) => filterActions.some((f) => f(it))) $: filtered = txes.filter((it) => filterActions.some((f) => f(it, object._class)))
</script> </script>
{#if !integrate || transparent} {#if !integrate || transparent}

View File

@ -13,7 +13,9 @@
// limitations under the License. // limitations under the License.
// //
import { Doc, Ref } from '@hcengineering/core'
import { Resources } from '@hcengineering/platform' import { Resources } from '@hcengineering/platform'
import type { DisplayTx } from '@hcengineering/activity'
import Activity from './components/Activity.svelte' import Activity from './components/Activity.svelte'
import TxView from './components/TxView.svelte' import TxView from './components/TxView.svelte'
@ -22,7 +24,14 @@ export { TxView }
export * from './activity' export * from './activity'
export * from './utils' export * from './utils'
export function attributeFilter (tx: DisplayTx, _class?: Ref<Doc>): boolean {
return tx.tx.objectClass === _class
}
export default async (): Promise<Resources> => ({ export default async (): Promise<Resources> => ({
filter: {
AttributeFilter: attributeFilter
},
component: { component: {
Activity Activity
} }

View File

@ -97,7 +97,7 @@ export interface DisplayTx {
*/ */
export interface ActivityFilter extends Doc { export interface ActivityFilter extends Doc {
label: IntlString label: IntlString
filter: Resource<(tx: DisplayTx) => boolean> filter: Resource<(tx: DisplayTx, _class?: Ref<Doc>) => boolean>
} }
/** /**

View File

@ -14,7 +14,7 @@
// //
import attachment, { Attachment } from '@hcengineering/attachment' import attachment, { Attachment } from '@hcengineering/attachment'
import { ObjQueryType, SortingOrder, SortingQuery, Markup } from '@hcengineering/core' import { ObjQueryType, SortingOrder, SortingQuery, Markup, Ref, Doc } from '@hcengineering/core'
import { IntlString, Resources } from '@hcengineering/platform' import { IntlString, Resources } from '@hcengineering/platform'
import preference from '@hcengineering/preference' import preference from '@hcengineering/preference'
import { getClient } from '@hcengineering/presentation' import { getClient } from '@hcengineering/presentation'
@ -228,7 +228,7 @@ export async function DeleteAttachment (attach: Attachment): Promise<void> {
) )
} }
export function attachmentsFilter (tx: DisplayTx): boolean { export function attachmentsFilter (tx: DisplayTx, _class?: Ref<Doc>): boolean {
return tx.tx.objectClass === attachment.class.Attachment return tx.tx.objectClass === attachment.class.Attachment
} }

View File

@ -207,11 +207,11 @@ async function update (source: Doc, key: string, target: RelatedDocument[], msg:
await updateBacklinksList(getClient(), q, backlinks) await updateBacklinksList(getClient(), q, backlinks)
} }
export function commentsFilter (tx: DisplayTx): boolean { export function commentsFilter (tx: DisplayTx, _class?: Ref<Doc>): boolean {
return tx.tx.objectClass === chunter.class.Comment return tx.tx.objectClass === chunter.class.Comment
} }
export function backlinksFilter (tx: DisplayTx): boolean { export function backlinksFilter (tx: DisplayTx, _class?: Ref<Doc>): boolean {
return tx.tx.objectClass === chunter.class.Backlink return tx.tx.objectClass === chunter.class.Backlink
} }