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

UBER-945: pinning for comments #4050

Merged
merged 1 commit into from
Nov 23, 2023
Merged
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
16 changes: 16 additions & 0 deletions models/chunter/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
6 changes: 4 additions & 2 deletions models/chunter/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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)
}
}
37 changes: 37 additions & 0 deletions plugins/chunter-resources/src/components/PinComment.svelte
Original file line number Diff line number Diff line change
@@ -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}
/>
4 changes: 3 additions & 1 deletion plugins/chunter-resources/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
1 change: 1 addition & 0 deletions plugins/chunter/src/index.ts
Original file line number Diff line number Diff line change
@@ -103,6 +103,7 @@ export interface Comment extends AttachedDoc {
message: string
attachments?: number
reactions?: number
pinned?: boolean
}

/**