UBER-513: Fix desktop app navigation (#3459)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-06-26 21:03:12 +07:00 committed by GitHub
parent 7e7e67632b
commit 70d78e50b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 53 additions and 21 deletions

View File

@ -3,7 +3,7 @@
import { onDestroy } from 'svelte'
import type { AnyComponent } from '../../types'
// import { applicationShortcutKey } from '../../utils'
import { getCurrentLocation, location, navigate } from '../../location'
import { getCurrentLocation, location, navigate, locationStorageKeyId } from '../../location'
import { Theme } from '@hcengineering/theme'
import Component from '../Component.svelte'
@ -35,9 +35,9 @@
}
if (application === undefined) {
let last = loc.path[1] !== undefined ? localStorage.getItem(`platform_last_loc_${loc.path[1]}`) : null
let last = loc.path[1] !== undefined ? localStorage.getItem(`${locationStorageKeyId}_${loc.path[1]}`) : null
if (last === null) {
last = localStorage.getItem('platform_last_loc')
last = localStorage.getItem(locationStorageKeyId)
}
let useDefault = true
if (last !== null) {

View File

@ -40,7 +40,7 @@ export type {
export { themeStore } from '@hcengineering/theme'
// export { applicationShortcutKey } from './utils'
export { getCurrentLocation, locationToUrl, navigate, location } from './location'
export { getCurrentLocation, locationToUrl, navigate, location, setLocationStorageKey } from './location'
export { default as EditBox } from './components/EditBox.svelte'
export { default as Label } from './components/Label.svelte'

View File

@ -148,6 +148,15 @@ export function getCurrentLocation (): PlatformLocation {
return getRawCurrentLocation()
}
/**
* @public
*/
export let locationStorageKeyId = 'platform_last_loc'
export function setLocationStorageKey (storageKey: string): void {
locationStorageKeyId = storageKey
}
export function navigate (location: PlatformLocation, store = true): boolean {
closePopup()
const cur = locationToUrl(getCurrentLocation())
@ -157,9 +166,9 @@ export function navigate (location: PlatformLocation, store = true): boolean {
if (!embeddedPlatform) {
history.pushState(null, '', url)
}
localStorage.setItem('platform_last_loc', JSON.stringify(location))
localStorage.setItem(locationStorageKeyId, JSON.stringify(location))
if (location.path[1] !== undefined) {
localStorage.setItem(`platform_last_loc_${location.path[1]}`, JSON.stringify(location))
localStorage.setItem(`${locationStorageKeyId}_${location.path[1]}`, JSON.stringify(location))
}
}
locationWritable.set(location)

View File

@ -29,7 +29,8 @@ import {
fetchMetadataLocalStorage,
getCurrentLocation,
navigate,
setMetadataLocalStorage
setMetadataLocalStorage,
locationStorageKeyId
} from '@hcengineering/ui'
import { workbenchId } from '@hcengineering/workbench'
@ -333,7 +334,7 @@ export function navigateToWorkspace (workspace: string, loginInfo?: WorkspaceLog
// Json parse error could be ignored
}
}
const last = localStorage.getItem(`platform_last_loc_${workspace}`)
const last = localStorage.getItem(`${locationStorageKeyId}_${workspace}`)
if (last !== null) {
navigate(JSON.parse(last))
} else {

View File

@ -25,7 +25,8 @@
navigate,
resolvedLocationStore,
setMetadataLocalStorage,
IconCheck
IconCheck,
locationStorageKeyId
} from '@hcengineering/ui'
import { workbenchId } from '@hcengineering/workbench'
import { onMount } from 'svelte'
@ -72,7 +73,7 @@
closePopup()
closePopup()
if (ws !== getCurrentLocation().path[1]) {
const last = localStorage.getItem(`platform_last_loc_${ws}`)
const last = localStorage.getItem(`${locationStorageKeyId}_${ws}`)
if (last !== null) {
navigate(JSON.parse(last))
} else navigate({ path: [workbenchId, ws] })

View File

@ -21,6 +21,7 @@
import { IntlString, broadcastEvent, getMetadata, getResource } from '@hcengineering/platform'
import { ActionContext, createQuery, getClient } from '@hcengineering/presentation'
import setting from '@hcengineering/setting'
import { locationStorageKeyId } from '@hcengineering/ui'
import {
AnyComponent,
CompAndProps,
@ -107,7 +108,7 @@
let panelInstance: PanelInstance
let popupInstance: Popup
let visibileNav: boolean = true
let visibileNav: boolean = getMetadata(workbench.metadata.NavigationExpandedDefault) ?? true
async function toggleNav (): Promise<void> {
visibileNav = !visibileNav
closeTooltip()
@ -288,7 +289,7 @@
const fragment = loc.fragment
let navigateDone = false
if (app === undefined) {
const last = localStorage.getItem(`platform_last_loc_${loc.path[1]}`)
const last = localStorage.getItem(`${locationStorageKeyId}_${loc.path[1]}`)
if (last != null) {
const lastValue = JSON.parse(last)
navigateDone = navigate(lastValue)
@ -332,7 +333,7 @@
space === undefined &&
((navigatorModel?.spaces?.length ?? 0) > 0 || (navigatorModel?.specials?.length ?? 0) > 0)
) {
const last = localStorage.getItem(`platform_last_loc_${app}`)
const last = localStorage.getItem(`${locationStorageKeyId}_${app}`)
if (last !== null) {
const newLocation: Location = JSON.parse(last)
if (newLocation.path[3] != null) {
@ -363,7 +364,7 @@
}
}
if (app !== undefined) {
localStorage.setItem(`platform_last_loc_${app}`, originalLoc)
localStorage.setItem(`${locationStorageKeyId}_${app}`, originalLoc)
}
currentQuery = loc.query
if (fragment !== currentFragment) {
@ -514,9 +515,11 @@
visibileNav = false
navFloat = true
} else if ($deviceInfo.docWidth > 1024 && navFloat) {
if (getMetadata(workbench.metadata.NavigationExpandedDefault) === undefined) {
navFloat = false
visibileNav = true
}
}
const checkOnHide = (): void => {
if (visibileNav && $deviceInfo.docWidth <= 1024) visibileNav = false
}

View File

@ -139,7 +139,9 @@ export default plugin(workbenchId, {
ExcludedApplications: '' as Metadata<Ref<Application>[]>,
DefaultApplication: '' as Metadata<string>,
DefaultSpace: '' as Metadata<Ref<Space>>,
DefaultSpecial: '' as Metadata<string>
DefaultSpecial: '' as Metadata<string>,
// Default for navigation expanded state
NavigationExpandedDefault: '' as Metadata<boolean>
},
actionImpl: {
Navigate: '' as ViewAction<{

View File

@ -625,9 +625,8 @@ export async function restore (
model: 'upgrade'
})) as unknown as CoreClient & BackupClient
async function processDomain (c: Domain): Promise<boolean> {
try {
for (const c of domains) {
console.log('loading server changeset for', c)
const changeset = await loadDigest(storage, snapshots, c, date)
// We need to load full changeset from server
const serverChangeset = new Map<Ref<Doc>, string>()
@ -798,6 +797,23 @@ export async function restore (
await connection.clean(c, part)
}
}
return true
} catch (err: any) {
console.log('error', err)
return false
}
}
try {
for (const c of domains) {
console.log('loading server changeset for', c)
let retry = 3
while (retry > 0) {
retry--
if (await processDomain(c)) {
break
}
}
}
} finally {
await connection.close()

View File

@ -130,7 +130,7 @@ class ElasticDataAdapter implements DbAdapter {
if (e?.meta?.body?.error?.type === 'index_not_found_exception') {
return undefined
}
console.error(e)
console.error('elastic error:', e)
throw new PlatformError(e)
}
},