From 4234931d82709c9fe53c35a2af75475f91aea014 Mon Sep 17 00:00:00 2001 From: Kristina Date: Thu, 3 Oct 2024 15:48:24 +0400 Subject: [PATCH] Fix tabs on desktop and during workspace switch (#6795) Signed-off-by: Kristina Fefelova --- models/all/src/migration.ts | 4 +- models/workbench/package.json | 1 + models/workbench/src/index.ts | 1 + models/workbench/src/migration.ts | 40 +++++++++++++++++++ .../src/components/Workbench.svelte | 1 + .../components/WorkbenchTabPresenter.svelte | 2 +- plugins/workbench-resources/src/workbench.ts | 13 ++++-- 7 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 models/workbench/src/migration.ts diff --git a/models/all/src/migration.ts b/models/all/src/migration.ts index c919fd5334..4366401105 100644 --- a/models/all/src/migration.ts +++ b/models/all/src/migration.ts @@ -51,6 +51,7 @@ import { documentsOperation } from '@hcengineering/model-controlled-documents' import { productsOperation } from '@hcengineering/model-products' import { requestOperation } from '@hcengineering/model-request' import { analyticsCollectorOperation } from '@hcengineering/model-analytics-collector' +import { workbenchOperation } from '@hcengineering/model-workbench' export const migrateOperations: [string, MigrateOperation][] = [ ['core', coreOperation], @@ -90,5 +91,6 @@ export const migrateOperations: [string, MigrateOperation][] = [ ['textEditorOperation', textEditorOperation], // We should call notification migration after activityServer and chunter ['notification', notificationOperation], - ['analyticsCollector', analyticsCollectorOperation] + ['analyticsCollector', analyticsCollectorOperation], + ['workbench', workbenchOperation] ] diff --git a/models/workbench/package.json b/models/workbench/package.json index 1270cc94d9..eaf30fbe28 100644 --- a/models/workbench/package.json +++ b/models/workbench/package.json @@ -35,6 +35,7 @@ "@hcengineering/model-presentation": "^0.6.0", "@hcengineering/model-view": "^0.6.0", "@hcengineering/platform": "^0.6.11", + "@hcengineering/preference": "^0.6.13", "@hcengineering/ui": "^0.6.15", "@hcengineering/view": "^0.6.13", "@hcengineering/workbench": "^0.6.16", diff --git a/models/workbench/src/index.ts b/models/workbench/src/index.ts index d7810e554a..765e7e5d9c 100644 --- a/models/workbench/src/index.ts +++ b/models/workbench/src/index.ts @@ -40,6 +40,7 @@ import presentation from '@hcengineering/model-presentation' import workbench from './plugin' export { workbenchId } from '@hcengineering/workbench' +export { workbenchOperation } from './migration' export type { Application } @Model(workbench.class.Application, core.class.Doc, DOMAIN_MODEL) diff --git a/models/workbench/src/migration.ts b/models/workbench/src/migration.ts new file mode 100644 index 0000000000..d4fb8fdaf3 --- /dev/null +++ b/models/workbench/src/migration.ts @@ -0,0 +1,40 @@ +// +// 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. +// +import { + type MigrateOperation, + type MigrationClient, + type MigrationUpgradeClient, + tryMigrate +} from '@hcengineering/model' +import { DOMAIN_PREFERENCE } from '@hcengineering/preference' +import workbench from '@hcengineering/workbench' + +import { workbenchId } from '.' + +async function removeTabs (client: MigrationClient): Promise { + await client.deleteMany(DOMAIN_PREFERENCE, { _class: workbench.class.WorkbenchTab }) +} + +export const workbenchOperation: MigrateOperation = { + async migrate (client: MigrationClient): Promise { + await tryMigrate(client, workbenchId, [ + { + state: 'remove-wrong-tabs-v1', + func: removeTabs + } + ]) + }, + async upgrade (state: Map>, client: () => Promise): Promise {} +} diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index 5a1302a608..e8ebdf6cd5 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -251,6 +251,7 @@ const doSyncLoc = reduceCalls(async (loc: Location): Promise => { if (workspaceId !== $location.path[1]) { + tabs = [] // Switch of workspace return } diff --git a/plugins/workbench-resources/src/components/WorkbenchTabPresenter.svelte b/plugins/workbench-resources/src/components/WorkbenchTabPresenter.svelte index 12f631dd73..8d661ba9ef 100644 --- a/plugins/workbench-resources/src/components/WorkbenchTabPresenter.svelte +++ b/plugins/workbench-resources/src/components/WorkbenchTabPresenter.svelte @@ -64,7 +64,7 @@ } async function updateTabData (tab: WorkbenchTab): Promise { - const tabLoc = getTabLocation(tab) + const tabLoc = $tabIdStore === tab._id ? getCurrentLocation() : getTabLocation(tab) const alias = tabLoc.path[2] const application = client.getModel().findAllSync(workbench.class.Application, { alias })[0] diff --git a/plugins/workbench-resources/src/workbench.ts b/plugins/workbench-resources/src/workbench.ts index 5ebd726ca5..26215dfaf4 100644 --- a/plugins/workbench-resources/src/workbench.ts +++ b/plugins/workbench-resources/src/workbench.ts @@ -23,7 +23,8 @@ import { navigate, getCurrentLocation } from '@hcengineering/ui' -import { getClient } from '@hcengineering/presentation' +import presentation, { getClient } from '@hcengineering/presentation' +import { getMetadata } from '@hcengineering/platform' import { workspaceStore } from './utils' @@ -44,7 +45,12 @@ locationStore.subscribe((loc) => { if (tab == null) return const tabId = tab._id if (tabId == null || tab._id !== tabId) return - + const tabLoc = getTabLocation(tab) + const tabWs = tabLoc.path[1] + if (workspace !== tabWs) { + return + } + if (loc.path[2] === '' || loc.path[2] == null) return void getClient().update(tab, { location: locationToUrl(loc) }) }) @@ -86,7 +92,8 @@ export function selectTab (_id: Ref): void { export function getTabLocation (tab: WorkbenchTab): Location { const base = `${window.location.protocol}//${window.location.host}` - const url = new URL(concatLink(base, tab.location)) + const front = getMetadata(presentation.metadata.FrontUrl) ?? base + const url = new URL(concatLink(front, tab.location)) return parseLocation(url) }