Fix tabs on desktop and during workspace switch (#6795)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-10-03 18:48:24 +07:00
committed by GitHub
parent 951fcf2afa
commit 4234931d82
7 changed files with 57 additions and 5 deletions
+3 -1
View File
@@ -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]
]
+1
View File
@@ -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",
+1
View File
@@ -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)
+40
View File
@@ -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<void> {
await client.deleteMany(DOMAIN_PREFERENCE, { _class: workbench.class.WorkbenchTab })
}
export const workbenchOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> {
await tryMigrate(client, workbenchId, [
{
state: 'remove-wrong-tabs-v1',
func: removeTabs
}
])
},
async upgrade (state: Map<string, Set<string>>, client: () => Promise<MigrationUpgradeClient>): Promise<void> {}
}
@@ -251,6 +251,7 @@
const doSyncLoc = reduceCalls(async (loc: Location): Promise<void> => {
if (workspaceId !== $location.path[1]) {
tabs = []
// Switch of workspace
return
}
@@ -64,7 +64,7 @@
}
async function updateTabData (tab: WorkbenchTab): Promise<void> {
const tabLoc = getTabLocation(tab)
const tabLoc = $tabIdStore === tab._id ? getCurrentLocation() : getTabLocation(tab)
const alias = tabLoc.path[2]
const application = client.getModel().findAllSync<Application>(workbench.class.Application, { alias })[0]
+10 -3
View File
@@ -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<WorkbenchTab>): 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)
}