Improve select workpace (#2487)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2022-12-30 14:43:26 +06:00 committed by GitHub
parent 27bdd26d06
commit 314635b149
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 12 deletions

View File

@ -19,27 +19,45 @@
navigateToWorkspace,
selectWorkspace,
setLoginInfo,
Workspace
Workspace,
WorkspaceLoginInfo
} from '@hcengineering/login-resources'
import { getEmbeddedLabel } from '@hcengineering/platform'
import { Loading, locationToUrl, Menu, navigate } from '@hcengineering/ui'
import { fetchMetadataLocalStorage, Loading, locationToUrl, Menu, navigate } from '@hcengineering/ui'
import { workbenchId } from '@hcengineering/workbench'
import { onMount } from 'svelte'
import workbench from '../plugin'
let workspaces: Workspace[] = []
import { workspacesStore } from '../utils'
onMount(() => {
getWorkspaces().then((ws: Workspace[]) => {
workspaces = ws
$workspacesStore = ws
})
})
async function getLoginIngo (ws: string): Promise<WorkspaceLoginInfo | undefined> {
const tokens: Record<string, string> = fetchMetadataLocalStorage(login.metadata.LoginTokens) ?? {}
const endpoint = fetchMetadataLocalStorage(login.metadata.LoginEndpoint)
const email = fetchMetadataLocalStorage(login.metadata.LoginEmail)
const token = tokens[ws]
if (token && email && endpoint) {
return {
token,
endpoint,
email,
workspace: ws
}
} else {
const loginInfo = (await selectWorkspace(ws))[1]
return loginInfo
}
}
$: actions = [
...workspaces.map((w) => ({
...$workspacesStore.map((w) => ({
label: getEmbeddedLabel(w.workspace),
action: async () => {
const loginInfo = (await selectWorkspace(w.workspace))[1]
const loginInfo = await getLoginIngo(w.workspace)
navigateToWorkspace(w.workspace, loginInfo)
},
isSubmenuRightClicking: true,
@ -49,7 +67,7 @@
{
label: workbench.string.OpenInNewTab,
action: async () => {
const loginInfo = (await selectWorkspace(w.workspace))[1]
const loginInfo = await getLoginIngo(w.workspace)
if (!loginInfo) {
return
@ -72,8 +90,8 @@
]
</script>
{#if workspaces.length}
{#if $workspacesStore.length}
<Menu {actions} on:update on:close />
{:else}
<Loading />
<div class="antiPopup"><Loading /></div>
{/if}

View File

@ -47,7 +47,7 @@
import { getContext, onDestroy, onMount, tick } from 'svelte'
import { subscribeMobile } from '../mobile'
import workbench from '../plugin'
import { doNavigate } from '../utils'
import { doNavigate, workspacesStore } from '../utils'
import AccountPopup from './AccountPopup.svelte'
import AppItem from './AppItem.svelte'
import Applications from './Applications.svelte'
@ -55,6 +55,7 @@
import NavHeader from './NavHeader.svelte'
import Navigator from './Navigator.svelte'
import SpaceView from './SpaceView.svelte'
import { getWorkspaces, Workspace } from '@hcengineering/login-resources'
export let client: Client
let contentPanel: HTMLElement
@ -84,6 +85,10 @@
apps = result
})
getWorkspaces().then((ws: Workspace[]) => {
$workspacesStore = ws
})
let panelInstance: PanelInstance
let visibileNav: boolean = true

View File

@ -24,6 +24,8 @@ import { closePanel, getCurrentLocation, navigate } from '@hcengineering/ui'
import { getClient } from '@hcengineering/presentation'
import type { Application } from '@hcengineering/workbench'
import preference from '@hcengineering/preference'
import { writable } from 'svelte/store'
import { Workspace } from '@hcengineering/login-resources'
export function classIcon (client: Client, _class: Ref<Class<Obj>>): Asset | undefined {
return client.getHierarchy().getClass(_class).icon
@ -135,3 +137,5 @@ export async function showApplication (app: Application): Promise<void> {
await client.remove(current)
}
}
export const workspacesStore = writable<Workspace[]>([])

View File

@ -23,7 +23,6 @@ test.describe('login test', () => {
expect(await button.isEnabled()).toBe(true)
await button.click()
await page.waitForNavigation()
await page.click('text=sanity-ws')
})