UBER-945: pinning for comments (#4050)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2023-11-23 22:26:42 +05:00 committed by GitHub
parent 65e2aa572b
commit 69ac2b781c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 5 deletions

View File

@ -55,6 +55,7 @@ import view, { createAction, actionTemplates as viewTemplates } from '@hcenginee
import workbench from '@hcengineering/model-workbench'
import chunter from './plugin'
import { type AnyComponent } from '@hcengineering/ui/src/types'
import { TypeBoolean } from '@hcengineering/model'
export { chunterId } from '@hcengineering/chunter'
export { chunterOperation } from './migration'
@ -153,6 +154,9 @@ export class TComment extends TAttachedDoc implements Comment {
@Prop(Collection(chunter.class.Reaction), chunter.string.Reactions)
reactions?: number
@Prop(TypeBoolean(), chunter.string.PinMessage)
pinned?: boolean
}
@Model(chunter.class.Backlink, chunter.class.Comment)
@ -753,6 +757,18 @@ export function createModel (builder: Builder, options = { addApplication: true
chunter.ids.ActivityExtension
)
builder.createDoc(
activity.class.ActivityExtension,
core.space.Model,
{
ofClass: chunter.class.Comment,
components: {
action: chunter.component.PinComment
}
},
chunter.ids.PinExtension
)
builder.createDoc(
activity.class.ActivityExtension,
core.space.Model,

View File

@ -34,7 +34,8 @@ export default mergeIds(chunterId, chunter, {
SavedMessages: '' as AnyComponent,
ChunterBrowser: '' as AnyComponent,
CommentReactions: '' as AnyComponent,
ReactionsAction: '' as AnyComponent
ReactionsAction: '' as AnyComponent,
PinComment: '' as AnyComponent
},
action: {
MarkCommentUnread: '' as Ref<Action>,
@ -93,7 +94,8 @@ export default mergeIds(chunterId, chunter, {
TxMessageCreate: '' as Ref<TxViewlet>,
ChunterNotificationGroup: '' as Ref<NotificationGroup>,
ActivityExtension: '' as Ref<ActivityExtension>,
BackLinkActivityExtension: '' as Ref<ActivityExtension>
BackLinkActivityExtension: '' as Ref<ActivityExtension>,
PinExtension: '' as Ref<ActivityExtension>
},
activity: {
TxCommentCreate: '' as AnyComponent,

View File

@ -85,8 +85,9 @@
filters: ActivityFilter[],
selected: Ref<Doc>[] | 'All'
): Promise<void> {
const txesSorted = txes.sort((tx) => ((tx.doc as any)?.pinned ? -1 : 1))
if (selected === 'All') {
filtered = txes
filtered = txesSorted
dispatch('update', filtered)
} else {
selectedFilters = filters.filter((filter) => selected.includes(filter._id))
@ -95,7 +96,7 @@
const fltr = await getResource(filter.filter)
filterActions.push(fltr)
}
filtered = txes.filter((it) => filterActions.some((f) => f(it, object._class)))
filtered = txesSorted.filter((it) => filterActions.some((f) => f(it, object._class)))
dispatch('update', filtered)
}
}

View File

@ -0,0 +1,37 @@
<!--
// Copyright © 2023 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.
-->
<script lang="ts">
import { ActionIcon } from '@hcengineering/ui'
import { getClient } from '@hcengineering/presentation'
import { type Comment } from '@hcengineering/chunter'
import view from '@hcengineering/view'
export let object: Comment | undefined = undefined
const client = getClient()
async function pinComment (ev: Event): Promise<void> {
if (object !== undefined) {
await client.update(object, { pinned: !object?.pinned })
}
}
</script>
<ActionIcon
icon={view.icon.Pin}
iconProps={object?.pinned === true ? { fill: '#3265cb' } : undefined}
size="medium"
action={pinComment}
/>

View File

@ -71,6 +71,7 @@ import TxCommentCreate from './components/activity/TxCommentCreate.svelte'
import TxMessageCreate from './components/activity/TxMessageCreate.svelte'
import ReactionsAction from './components/ReactionsAction.svelte'
import CommentReactions from './components/CommentReactions.svelte'
import PinComment from './components/PinComment.svelte'
import notification from '@hcengineering/notification'
import { writable } from 'svelte/store'
@ -310,7 +311,8 @@ export default async (): Promise<Resources> => ({
SavedMessages,
CommentPanel,
ReactionsAction,
CommentReactions
CommentReactions,
PinComment
},
function: {
GetDmName: getDmName,

View File

@ -103,6 +103,7 @@ export interface Comment extends AttachedDoc {
message: string
attachments?: number
reactions?: number
pinned?: boolean
}
/**