mirror of
https://github.com/hcengineering/platform.git
synced 2026-10-01 22:15:04 +02:00
Add workbench tabs (#6788)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<!--
|
||||
// Copyright © 2024 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 { WorkbenchTab } from '@hcengineering/workbench'
|
||||
import {
|
||||
getNotificationsCount,
|
||||
InboxNotificationsClientImpl,
|
||||
isActivityNotification,
|
||||
isMentionNotification,
|
||||
NotifyMarker
|
||||
} from '@hcengineering/notification-resources'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { InboxNotification } from '@hcengineering/notification'
|
||||
import { onDestroy } from 'svelte'
|
||||
import { concatLink, Doc, Ref } from '@hcengineering/core'
|
||||
import view, { decodeObjectURI } from '@hcengineering/view'
|
||||
import { chunterId } from '@hcengineering/chunter'
|
||||
import { parseLinkId } from '@hcengineering/view-resources'
|
||||
import { parseLocation } from '@hcengineering/ui'
|
||||
|
||||
import chunter from '../plugin'
|
||||
|
||||
export let tab: WorkbenchTab
|
||||
|
||||
const client = getClient()
|
||||
const hierarchy = client.getHierarchy()
|
||||
const notificationClient = InboxNotificationsClientImpl.getClient()
|
||||
const contextByDocStore = notificationClient.contextByDoc
|
||||
|
||||
let objectId: Ref<Doc> | undefined = undefined
|
||||
let notifications: InboxNotification[] = []
|
||||
let count = 0
|
||||
|
||||
$: context = objectId !== undefined ? $contextByDocStore.get(objectId) : undefined
|
||||
|
||||
$: void updateObjectId(tab)
|
||||
|
||||
async function updateObjectId (tab: WorkbenchTab): Promise<void> {
|
||||
const base = `${window.location.protocol}//${window.location.host}`
|
||||
const url = new URL(concatLink(base, tab.location))
|
||||
const loc = parseLocation(url)
|
||||
|
||||
if (loc.path[2] !== chunterId) {
|
||||
objectId = undefined
|
||||
return
|
||||
}
|
||||
|
||||
const client = getClient()
|
||||
const providers = client.getModel().findAllSync(view.mixin.LinkIdProvider, {})
|
||||
const [id, _class] = decodeObjectURI(loc.path[3])
|
||||
objectId = await parseLinkId(providers, id, _class)
|
||||
}
|
||||
|
||||
const unsubscribe = notificationClient.inboxNotificationsByContext.subscribe((res) => {
|
||||
if (context === undefined) {
|
||||
count = 0
|
||||
return
|
||||
}
|
||||
|
||||
notifications = (res.get(context._id) ?? []).filter((n) => {
|
||||
if (isActivityNotification(n)) return true
|
||||
|
||||
return isMentionNotification(n) && hierarchy.isDerived(n.mentionedInClass, chunter.class.ChatMessage)
|
||||
})
|
||||
})
|
||||
|
||||
$: void getNotificationsCount(context, notifications).then((res) => {
|
||||
count = res
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
unsubscribe()
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if count > 0}
|
||||
<NotifyMarker kind="simple" size="xx-small" />
|
||||
{/if}
|
||||
@@ -52,6 +52,7 @@ import ThreadView from './components/threads/ThreadView.svelte'
|
||||
import ThreadViewPanel from './components/threads/ThreadViewPanel.svelte'
|
||||
import ChatWidget from './components/ChatWidget.svelte'
|
||||
import ChatWidgetTab from './components/ChatWidgetTab.svelte'
|
||||
import WorkbenchTabExtension from './components/WorkbenchTabExtension.svelte'
|
||||
|
||||
import {
|
||||
chunterSpaceLinkFragmentProvider,
|
||||
@@ -59,6 +60,7 @@ import {
|
||||
getMessageLink,
|
||||
getMessageLocation,
|
||||
getThreadLink,
|
||||
locationDataResolver,
|
||||
openChannelInSidebar,
|
||||
openChannelInSidebarAction,
|
||||
openThreadInSidebar,
|
||||
@@ -178,7 +180,8 @@ export default async (): Promise<Resources> => ({
|
||||
ChatMessagePreview,
|
||||
JoinChannelNotificationPresenter,
|
||||
ChatWidget,
|
||||
ChatWidgetTab
|
||||
ChatWidgetTab,
|
||||
WorkbenchTabExtension
|
||||
},
|
||||
activity: {
|
||||
ChannelCreatedMessage,
|
||||
@@ -203,7 +206,8 @@ export default async (): Promise<Resources> => ({
|
||||
CloseChatWidgetTab: closeChatWidgetTab,
|
||||
OpenChannelInSidebar: openChannelInSidebar,
|
||||
CanTranslateMessage: canTranslateMessage,
|
||||
OpenThreadInSidebar: openThreadInSidebar
|
||||
OpenThreadInSidebar: openThreadInSidebar,
|
||||
LocationDataResolver: locationDataResolver
|
||||
},
|
||||
actionImpl: {
|
||||
ArchiveChannel,
|
||||
|
||||
@@ -4,7 +4,8 @@ import {
|
||||
getCurrentResolvedLocation,
|
||||
getLocation,
|
||||
type Location,
|
||||
navigate
|
||||
navigate,
|
||||
languageStore
|
||||
} from '@hcengineering/ui'
|
||||
import { type Ref, type Doc, type Class, generateId } from '@hcengineering/core'
|
||||
import activity, { type ActivityMessage } from '@hcengineering/activity'
|
||||
@@ -16,12 +17,12 @@ import {
|
||||
type ThreadMessage
|
||||
} from '@hcengineering/chunter'
|
||||
import { type DocNotifyContext, notificationId } from '@hcengineering/notification'
|
||||
import workbench, { type Widget, workbenchId } from '@hcengineering/workbench'
|
||||
import { classIcon, getObjectLinkId } from '@hcengineering/view-resources'
|
||||
import workbench, { type Widget, workbenchId, type LocationData } from '@hcengineering/workbench'
|
||||
import { classIcon, getObjectLinkId, parseLinkId } from '@hcengineering/view-resources'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import view, { encodeObjectURI, decodeObjectURI } from '@hcengineering/view'
|
||||
import { createWidgetTab, isElementFromSidebar, sidebarStore } from '@hcengineering/workbench-resources'
|
||||
import { type Asset, translate } from '@hcengineering/platform'
|
||||
import { type Asset, type IntlString, translate } from '@hcengineering/platform'
|
||||
import contact from '@hcengineering/contact'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
@@ -385,3 +386,73 @@ export function closeChatWidgetTab (tab?: ChatWidgetTab): void {
|
||||
removeThreadFromLoc(tab.data.thread)
|
||||
}
|
||||
}
|
||||
|
||||
export async function locationDataResolver (loc: Location): Promise<LocationData> {
|
||||
const point = loc.path[3]
|
||||
|
||||
if (point == null || point === '') {
|
||||
return { name: await translate(chunter.string.Chat, {}, get(languageStore)) }
|
||||
}
|
||||
|
||||
const specialsData: Record<
|
||||
string,
|
||||
{
|
||||
label: IntlString
|
||||
icon: Asset
|
||||
}
|
||||
> = {
|
||||
threads: {
|
||||
label: chunter.string.Threads,
|
||||
icon: chunter.icon.Chunter
|
||||
// icon: chunter.icon.Thread
|
||||
},
|
||||
saved: {
|
||||
label: chunter.string.Saved,
|
||||
icon: chunter.icon.Chunter
|
||||
// icon: chunter.icon.Bookmarks
|
||||
},
|
||||
chunterBrowser: {
|
||||
label: chunter.string.ChunterBrowser,
|
||||
icon: chunter.icon.Chunter
|
||||
// icon: chunter.icon.ChunterBrowser
|
||||
},
|
||||
channels: {
|
||||
label: chunter.string.Channels,
|
||||
icon: chunter.icon.Chunter
|
||||
// icon: chunter.icon.Hashtag
|
||||
}
|
||||
}
|
||||
|
||||
const specialData = specialsData[point]
|
||||
|
||||
if (specialData !== undefined) {
|
||||
return { name: await translate(specialData.label, {}, get(languageStore)), icon: specialData.icon }
|
||||
}
|
||||
|
||||
const client = getClient()
|
||||
const hierarchy = client.getHierarchy()
|
||||
|
||||
const [id, _class] = decodeObjectURI(loc.path[3])
|
||||
const linkProviders = client.getModel().findAllSync(view.mixin.LinkIdProvider, {})
|
||||
const _id: Ref<Doc> | undefined = await parseLinkId(linkProviders, id, _class)
|
||||
|
||||
const object = await client.findOne(_class, { _id })
|
||||
if (object === undefined) return { name: await translate(chunter.string.Chat, {}, get(languageStore)) }
|
||||
|
||||
const titleIntl = client.getHierarchy().getClass(object._class).label
|
||||
const iconMixin = hierarchy.classHierarchyMixin(_class, view.mixin.ObjectIcon)
|
||||
const isDirect = hierarchy.isDerived(_class, chunter.class.DirectMessage)
|
||||
const isChunterSpace = hierarchy.isDerived(_class, chunter.class.ChunterSpace)
|
||||
const name = (await getChannelName(_id, _class, object)) ?? (await translate(titleIntl, {}))
|
||||
|
||||
return {
|
||||
name,
|
||||
icon: chunter.icon.Chunter,
|
||||
iconComponent: isChunterSpace ? iconMixin?.component : undefined,
|
||||
iconProps: {
|
||||
_id: object._id,
|
||||
value: object,
|
||||
size: isDirect ? 'tiny' : 'x-small'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user