mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
Make visibleIf async in SpecialNavModel (#2684)
Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com>
This commit is contained in:
parent
96f0fef450
commit
8f0f69f144
@ -90,7 +90,7 @@ export default mergeIds(chunterId, chunter, {
|
||||
Random: '' as Ref<Channel>
|
||||
},
|
||||
function: {
|
||||
ChunterBrowserVisible: '' as Resource<(spaces: Space[]) => boolean>
|
||||
ChunterBrowserVisible: '' as Resource<(spaces: Space[]) => Promise<boolean>>
|
||||
},
|
||||
filter: {
|
||||
CommentsFilter: '' as Resource<(tx: DisplayTx, _class?: Ref<Doc>) => boolean>,
|
||||
|
@ -32,6 +32,6 @@ export default mergeIds(workbenchId, workbench, {
|
||||
HiddenApplication: '' as IntlString
|
||||
},
|
||||
function: {
|
||||
HasArchiveSpaces: '' as Resource<(spaces: Space[]) => boolean>
|
||||
HasArchiveSpaces: '' as Resource<(spaces: Space[]) => Promise<boolean>>
|
||||
}
|
||||
})
|
||||
|
@ -187,7 +187,7 @@ export async function DeleteMessageFromSaved (message: ChunterMessage): Promise<
|
||||
|
||||
export const userSearch = writable('')
|
||||
|
||||
export function chunterBrowserVisible (spaces: Space[]): boolean {
|
||||
export async function chunterBrowserVisible (spaces: Space[]): Promise<boolean> {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -107,20 +107,27 @@
|
||||
requestIndex: number
|
||||
): Promise<[Map<string, SpecialNavModel[]>, number]> {
|
||||
const result = new Map<string, SpecialNavModel[]>()
|
||||
const promises = specials.map(async (sp) => {
|
||||
const pos = sp.position ?? 'top'
|
||||
let visible = true
|
||||
if (sp.visibleIf !== undefined) {
|
||||
const f = await getResource(sp.visibleIf)
|
||||
visible = f(spaces)
|
||||
}
|
||||
if (visible) {
|
||||
const list = result.get(pos) ?? []
|
||||
list.push(sp)
|
||||
result.set(pos, list)
|
||||
}
|
||||
})
|
||||
await Promise.all(promises)
|
||||
|
||||
const spHandlers = await Promise.all(
|
||||
specials.map(async (sp) => {
|
||||
const pos = sp.position ?? 'top'
|
||||
let visible = true
|
||||
if (sp.visibleIf !== undefined) {
|
||||
const f = await getResource(sp.visibleIf)
|
||||
visible = await f(spaces)
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (visible) {
|
||||
const list = result.get(pos) ?? []
|
||||
list.push(sp)
|
||||
result.set(pos, list)
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
spHandlers.forEach((spHandler) => spHandler())
|
||||
|
||||
return [result, requestIndex]
|
||||
}
|
||||
</script>
|
||||
|
@ -23,7 +23,7 @@ import SpecialView from './components/SpecialView.svelte'
|
||||
import WorkbenchApp from './components/WorkbenchApp.svelte'
|
||||
import { doNavigate } from './utils'
|
||||
|
||||
function hasArchiveSpaces (spaces: Space[]): boolean {
|
||||
async function hasArchiveSpaces (spaces: Space[]): Promise<boolean> {
|
||||
return spaces.find((sp) => sp.archived) !== undefined
|
||||
}
|
||||
export { default as SpaceBrowser } from './components/SpaceBrowser.svelte'
|
||||
|
@ -79,7 +79,7 @@ export interface SpecialNavModel {
|
||||
componentProps?: Record<string, string>
|
||||
// If not top and bottom, position will be sorted alphabetically.
|
||||
position?: 'top' | 'bottom' | string // undefined == 'top
|
||||
visibleIf?: Resource<(spaces: Space[]) => boolean>
|
||||
visibleIf?: Resource<(spaces: Space[]) => Promise<boolean>>
|
||||
// If defined, will be used to find spaces for visibleIf
|
||||
spaceClass?: Ref<Class<Space>>
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user