mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-26 02:10:07 +00:00
UBERF-8313: Fix select workspace sorting (#6766)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
64d5ceab0f
commit
6b68b7f90a
@ -14,18 +14,18 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import { Analytics } from '@hcengineering/analytics'
|
import { Analytics } from '@hcengineering/analytics'
|
||||||
import { AccountRole, type Doc, type Ref, concatLink } from '@hcengineering/core'
|
import { AccountRole, concatLink, type Doc, type Ref } from '@hcengineering/core'
|
||||||
import { loginId, type LoginInfo, type OtpInfo, type Workspace, type WorkspaceLoginInfo } from '@hcengineering/login'
|
import { loginId, type LoginInfo, type OtpInfo, type Workspace, type WorkspaceLoginInfo } from '@hcengineering/login'
|
||||||
import {
|
import {
|
||||||
OK,
|
OK,
|
||||||
PlatformError,
|
PlatformError,
|
||||||
|
Severity,
|
||||||
|
Status,
|
||||||
getMetadata,
|
getMetadata,
|
||||||
setMetadata,
|
setMetadata,
|
||||||
translate,
|
translate,
|
||||||
unknownError,
|
unknownError,
|
||||||
unknownStatus,
|
unknownStatus
|
||||||
Status,
|
|
||||||
Severity
|
|
||||||
} from '@hcengineering/platform'
|
} from '@hcengineering/platform'
|
||||||
import presentation from '@hcengineering/presentation'
|
import presentation from '@hcengineering/presentation'
|
||||||
import {
|
import {
|
||||||
@ -39,9 +39,9 @@ import {
|
|||||||
} from '@hcengineering/ui'
|
} from '@hcengineering/ui'
|
||||||
import { workbenchId } from '@hcengineering/workbench'
|
import { workbenchId } from '@hcengineering/workbench'
|
||||||
|
|
||||||
import login from './plugin'
|
|
||||||
import { type Pages } from './index'
|
|
||||||
import { LoginEvents } from './analytics'
|
import { LoginEvents } from './analytics'
|
||||||
|
import { type Pages } from './index'
|
||||||
|
import login from './plugin'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a login operation to required workspace with user credentials.
|
* Perform a login operation to required workspace with user credentials.
|
||||||
@ -207,6 +207,16 @@ export async function createWorkspace (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLastVisitDays (it: Workspace): number {
|
||||||
|
return Math.floor((Date.now() - it.lastVisit) / (1000 * 3600 * 24))
|
||||||
|
}
|
||||||
|
function getWorkspaceSize (it: Workspace): number {
|
||||||
|
let sz = 0
|
||||||
|
sz += it.backupInfo?.dataSize ?? 0
|
||||||
|
sz += it.backupInfo?.blobsSize ?? 0
|
||||||
|
return sz
|
||||||
|
}
|
||||||
|
|
||||||
export async function getWorkspaces (): Promise<Workspace[]> {
|
export async function getWorkspaces (): Promise<Workspace[]> {
|
||||||
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
|
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
|
||||||
|
|
||||||
@ -241,7 +251,18 @@ export async function getWorkspaces (): Promise<Workspace[]> {
|
|||||||
if (result.error != null) {
|
if (result.error != null) {
|
||||||
throw new PlatformError(result.error)
|
throw new PlatformError(result.error)
|
||||||
}
|
}
|
||||||
return result.result
|
const workspaces: Workspace[] = result.result
|
||||||
|
|
||||||
|
workspaces.sort((a, b) => {
|
||||||
|
const adays = getLastVisitDays(a)
|
||||||
|
const bdays = getLastVisitDays(b)
|
||||||
|
if (adays === bdays) {
|
||||||
|
return getWorkspaceSize(b) - getWorkspaceSize(a)
|
||||||
|
}
|
||||||
|
return bdays - adays
|
||||||
|
})
|
||||||
|
|
||||||
|
return workspaces
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -37,24 +37,9 @@
|
|||||||
import { workspacesStore } from '../utils'
|
import { workspacesStore } from '../utils'
|
||||||
// import Drag from './icons/Drag.svelte'
|
// import Drag from './icons/Drag.svelte'
|
||||||
|
|
||||||
function getLastVisitDays (it: Workspace): number {
|
|
||||||
return Math.floor((Date.now() - it.lastVisit) / (1000 * 3600 * 24))
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
void getResource(login.function.GetWorkspaces).then(async (f) => {
|
void getResource(login.function.GetWorkspaces).then(async (f) => {
|
||||||
const workspaces = await f()
|
$workspacesStore = await f()
|
||||||
|
|
||||||
workspaces.sort((a, b) => {
|
|
||||||
const adays = getLastVisitDays(a)
|
|
||||||
const bdays = getLastVisitDays(a)
|
|
||||||
if (adays === bdays) {
|
|
||||||
return (b.backupInfo?.backupSize ?? 0) - (a.backupInfo?.backupSize ?? 0)
|
|
||||||
}
|
|
||||||
return bdays - adays
|
|
||||||
})
|
|
||||||
|
|
||||||
$workspacesStore = workspaces
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user