Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-6469: Rework workspace creation to more informative #5291

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/ui/src/components/Loading.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
</script>

<div class="spinner-container" class:fullSize={!shrink}>
<div data-label={label} class="inner" class:labeled={label !== ''}>
<div data-label={label} class="inner flex-row-center" class:labeled={label !== ''}>
<Spinner {size} />
<slot />
</div>
</div>

Expand Down
3 changes: 3 additions & 0 deletions plugins/login-resources/src/components/SelectWorkspace.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<div class="flex flex-col flex-grow">
<span class="label overflow-label flex-center">
{wsName}
{#if workspace.creating === true}
({workspace.createProgress}%)
{/if}
</span>
{#if isAdmin && wsName !== workspace.workspace}
<span class="text-xs flex-center">
Expand Down
11 changes: 10 additions & 1 deletion plugins/login-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
import { type IntlString } from '@hcengineering/platform'
import InviteLink from './components/InviteLink.svelte'
import LoginApp from './components/LoginApp.svelte'
import { changePassword, getWorkspaces, leaveWorkspace, selectWorkspace, sendInvite, getEnpoint } from './utils'
import {
changePassword,
getWorkspaces,
leaveWorkspace,
selectWorkspace,
sendInvite,
getEnpoint,
fetchWorkspace
} from './utils'
/*!
* Anticrm Platform™ Login Plugin
* © 2020, 2021 Anticrm Platform Contributors.
Expand All @@ -34,6 +42,7 @@ export default async () => ({
LeaveWorkspace: leaveWorkspace,
ChangePassword: changePassword,
SelectWorkspace: selectWorkspace,
FetchWorkspace: fetchWorkspace,
GetWorkspaces: getWorkspaces,
SendInvite: sendInvite,
GetEndpoint: getEnpoint
Expand Down
49 changes: 49 additions & 0 deletions plugins/login-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,55 @@ export async function selectWorkspace (workspace: string): Promise<[Status, Work
}
}

export async function fetchWorkspace (workspace: string): Promise<[Status, WorkspaceLoginInfo | undefined]> {
const accountsUrl = getMetadata(login.metadata.AccountsUrl)

if (accountsUrl === undefined) {
throw new Error('accounts url not specified')
}

const overrideToken = getMetadata(login.metadata.OverrideLoginToken)
const email = fetchMetadataLocalStorage(login.metadata.LoginEmail) ?? ''
if (overrideToken !== undefined) {
const endpoint = getMetadata(login.metadata.OverrideEndpoint)
if (endpoint !== undefined) {
return [OK, { token: overrideToken, endpoint, email, workspace, confirmed: true }]
}
}

const token = getMetadata(presentation.metadata.Token)
if (token === undefined) {
return [unknownStatus('Please login'), undefined]
}

const request = {
method: 'getWorkspaceInfo',
params: [token]
}

try {
const response = await fetch(accountsUrl, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify(request)
})
const result = await response.json()
if (result.error == null) {
Analytics.handleEvent('Fetch workspace')
Analytics.setTag('workspace', workspace)
} else {
await handleStatusError('Fetch workspace error', result.error)
}
return [result.error ?? OK, result.result]
} catch (err: any) {
Analytics.handleError(err)
return [unknownError(err), undefined]
}
}

export function setLoginInfo (loginInfo: WorkspaceLoginInfo): void {
const tokens: Record<string, string> = fetchMetadataLocalStorage(login.metadata.LoginTokens) ?? {}
tokens[loginInfo.workspace] = loginInfo.token
Expand Down
6 changes: 6 additions & 0 deletions plugins/login/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ export interface Workspace {
workspace: string // workspace Url
workspaceName?: string // A company name
workspaceId: string // A unique identifier for the workspace

creating?: boolean
createProgress?: number
}

/**
* @public
*/
export interface WorkspaceLoginInfo extends LoginInfo {
workspace: string
creating?: boolean
createProgress?: number
}

/**
Expand Down Expand Up @@ -76,6 +81,7 @@ export default plugin(loginId, {
LeaveWorkspace: '' as Resource<(email: string) => Promise<void>>,
ChangePassword: '' as Resource<(oldPassword: string, password: string) => Promise<void>>,
SelectWorkspace: '' as Resource<(workspace: string) => Promise<[Status, WorkspaceLoginInfo | undefined]>>,
FetchWorkspace: '' as Resource<(workspace: string) => Promise<[Status, WorkspaceLoginInfo | undefined]>>,
GetWorkspaces: '' as Resource<() => Promise<Workspace[]>>,
GetEndpoint: '' as Resource<() => Promise<string>>
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/workbench-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"PleaseUpdate": "Please update",
"ServerUnderMaintenance": "Server is under maintenance",
"MobileNotSupported": "Sorry, mobile devices support coming soon. In the meantime, please use Desktop",
"LogInAnyway": "Log in anyway"
"LogInAnyway": "Log in anyway",
"WorkspaceCreating": "Creation in progress..."
}
}
3 changes: 2 additions & 1 deletion plugins/workbench-assets/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"PleaseUpdate": "Por favor, actualice",
"ServerUnderMaintenance": "El servidor está en mantenimiento",
"MobileNotSupported": "Disculpa, el soporte para dispositivos móviles estará disponible próximamente. Mientras tanto, por favor usa el escritorio.",
"LogInAnyway": "Iniciar sesión de todas formas"
"LogInAnyway": "Iniciar sesión de todas formas",
"WorkspaceCreating": "Creation in progress..."
}
}
3 changes: 2 additions & 1 deletion plugins/workbench-assets/lang/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"PleaseUpdate": "Atualize",
"ServerUnderMaintenance": "Servidor em manutenção",
"MobileNotSupported": "Desculpe, o suporte para dispositivos móveis estará disponível em breve. Enquanto isso, por favor, use o Desktop.",
"LogInAnyway": "Entrar de qualquer maneira"
"LogInAnyway": "Entrar de qualquer maneira",
"WorkspaceCreating": "Creation in progress..."
}
}
3 changes: 2 additions & 1 deletion plugins/workbench-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"PleaseUpdate": "Пожалуйста, обновите приложение",
"ServerUnderMaintenance": "Обслуживание сервера",
"MobileNotSupported": "Простите, поддержка мобильных устройств скоро будет доступна. Пока воспользуйтесь компьютером.",
"LogInAnyway": "Все равно войти"
"LogInAnyway": "Все равно войти",
"WorkspaceCreating": "Пространство создается..."
}
}
12 changes: 10 additions & 2 deletions plugins/workbench-resources/src/components/WorkbenchApp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import { connect, disconnect, versionError } from '../connect'

import { workbenchId } from '@hcengineering/workbench'
import workbench from '../plugin'
import { onDestroy } from 'svelte'
import workbench from '../plugin'
import { workspaceCreating } from '../utils'

const isNeedUpgrade = window.location.host === ''

Expand All @@ -54,7 +55,14 @@
{:else}
{#key $location.path[1]}
{#await connect(getMetadata(workbench.metadata.PlatformTitle) ?? 'Platform')}
<Loading />
<Loading>
{#if ($workspaceCreating ?? -1) > 0}
<div class="ml-1">
<Label label={workbench.string.WorkspaceCreating} />
{$workspaceCreating} %
</div>
{/if}
</Loading>
{:then client}
{#if !client && versionError}
<div class="version-wrapper">
Expand Down
18 changes: 18 additions & 0 deletions plugins/workbench-resources/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
setMetadataLocalStorage
} from '@hcengineering/ui'
import plugin from './plugin'
import { workspaceCreating } from './utils'

export let versionError: string | undefined = ''

Expand Down Expand Up @@ -63,6 +64,7 @@ export async function connect (title: string): Promise<Client | undefined> {
}
const tokens: Record<string, string> = fetchMetadataLocalStorage(login.metadata.LoginTokens) ?? {}
let token = tokens[ws]

if (token === undefined && getMetadata(presentation.metadata.Token) !== undefined) {
const selectWorkspace = await getResource(login.function.SelectWorkspace)
const loginInfo = await ctx.with('select-workspace', {}, async () => (await selectWorkspace(ws))[1])
Expand All @@ -73,6 +75,22 @@ export async function connect (title: string): Promise<Client | undefined> {
}
}
setMetadata(presentation.metadata.Token, token)

const fetchWorkspace = await getResource(login.function.FetchWorkspace)
let loginInfo = await ctx.with('select-workspace', {}, async () => (await fetchWorkspace(ws))[1])
if (loginInfo?.creating === true) {
while (true) {
workspaceCreating.set(loginInfo?.createProgress ?? 0)
loginInfo = await ctx.with('select-workspace', {}, async () => (await fetchWorkspace(ws))[1])
workspaceCreating.set(loginInfo?.createProgress)
if (loginInfo?.creating === false) {
workspaceCreating.set(-1)
break
}
await new Promise<void>((resolve) => setTimeout(resolve, 1000))
}
}

document.cookie =
encodeURIComponent(presentation.metadata.Token.replaceAll(':', '-')) + '=' + encodeURIComponent(token) + '; path=/'

Expand Down
3 changes: 2 additions & 1 deletion plugins/workbench-resources/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export default mergeIds(workbenchId, workbench, {
NewVersionAvailable: '' as IntlString,
PleaseUpdate: '' as IntlString,
MobileNotSupported: '' as IntlString,
LogInAnyway: '' as IntlString
LogInAnyway: '' as IntlString,
WorkspaceCreating: '' as IntlString
},
metadata: {
MobileAllowed: '' as Metadata<boolean>
Expand Down
2 changes: 2 additions & 0 deletions plugins/workbench-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import view from '@hcengineering/view'
import workbench, { type Application, type NavigatorModel } from '@hcengineering/workbench'
import { writable } from 'svelte/store'

export const workspaceCreating = writable<number | undefined>(undefined)

export function getSpecialSpaceClass (model: NavigatorModel): Array<Ref<Class<Space>>> {
const spaceResult = model.spaces.map((x) => x.spaceClass)
const result = (model.specials ?? [])
Expand Down
5 changes: 4 additions & 1 deletion pods/account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//

import account, { ACCOUNT_DB, type AccountMethod, accountId } from '@hcengineering/account'
import account, { ACCOUNT_DB, type AccountMethod, accountId, cleanInProgressWorkspaces } from '@hcengineering/account'
import accountEn from '@hcengineering/account/lang/en.json'
import accountRu from '@hcengineering/account/lang/ru.json'
import { registerProviders } from '@hcengineering/auth-providers'
Expand Down Expand Up @@ -93,6 +93,9 @@ export function serveAccount (measureCtx: MeasureContext, methods: Record<string
void client.then((p: MongoClient) => {
const db = p.db(ACCOUNT_DB)
registerProviders(measureCtx, app, router, db, productId, serverSecret, frontURL)

// We need to clean workspace with creating === true, since server is restarted.
void cleanInProgressWorkspaces(db, productId)
})

const extractToken = (header: IncomingHttpHeaders): string | undefined => {
Expand Down
Loading