TSK-1200: Fix Applications with wrong state (#2992)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-04-16 12:49:13 +07:00 committed by GitHub
parent 549353468a
commit 986f130dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 63 deletions

View File

@ -51,46 +51,34 @@
export let createComponent: AnyComponent | undefined export let createComponent: AnyComponent | undefined
export let createComponentProps: Record<string, any> = {} export let createComponentProps: Record<string, any> = {}
export let isCreationDisabled = false export let isCreationDisabled = false
export let descriptors: Ref<ViewletDescriptor>[] | undefined = [view.viewlet.Table] export let descriptors: Ref<ViewletDescriptor>[] | undefined = undefined
let search = '' let search = ''
let viewlet: WithLookup<Viewlet> | undefined let viewlet: WithLookup<Viewlet> | undefined
$: query = viewlet?.baseQuery ?? {}
$: searchQuery = search === '' ? query : { ...query, $search: search }
$: resultQuery = searchQuery
const preferenceQuery = createQuery() const preferenceQuery = createQuery()
let preference: ViewletPreference | undefined let preference: ViewletPreference | undefined
let loading = true
let viewlets: WithLookup<Viewlet>[] = [] let viewlets: WithLookup<Viewlet>[] = []
const viewletQuery = createQuery() const viewletQuery = createQuery()
let vl = false
$: { $: viewletQuery.query(
vl = true view.class.Viewlet,
viewletQuery.query( {
view.class.Viewlet, attachTo: _class,
{ variant: { $exists: false },
attachTo: _class, ...(descriptors !== undefined ? { descriptor: { $in: descriptors } } : {})
variant: { $exists: false }, },
descriptor: { $in: descriptors ?? [view.viewlet.Table] } (res) => {
}, viewlets = res
(res) => { },
vl = false {
viewlets = res lookup: {
}, descriptor: view.class.ViewletDescriptor
{
lookup: {
descriptor: view.class.ViewletDescriptor
}
} }
) }
} )
let key = makeViewletKey() let key = makeViewletKey()
@ -100,22 +88,15 @@
}) })
) )
$: update(_class, $activeViewlet[key], viewlets) $: {
const newViewlet = viewlets.find((viewlet) => viewlet?._id === $activeViewlet[key]) ?? viewlets[0]
async function update ( if (viewlet?._id !== newViewlet?._id) {
_class: Ref<Class<Doc>>,
active: Ref<Viewlet> | null,
viewlets: WithLookup<Viewlet>[]
): Promise<void> {
if (vl === false) {
preference = undefined preference = undefined
viewlet = viewlets.find((viewlet) => viewlet?._id === active) ?? viewlets[0]
setActiveViewletId(viewlet?._id)
} }
viewlet = newViewlet
} }
$: if (viewlet !== undefined) { $: if (viewlet !== undefined) {
setActiveViewletId(viewlet._id)
preferenceQuery.query( preferenceQuery.query(
view.class.ViewletPreference, view.class.ViewletPreference,
{ {
@ -123,12 +104,17 @@
}, },
(res) => { (res) => {
preference = res[0] preference = res[0]
loading = false
}, },
{ limit: 1 } { limit: 1 }
) )
} else {
preferenceQuery.unsubscribe()
} }
$: query = viewlet?.baseQuery ?? {}
$: searchQuery = search === '' ? query : { ...query, $search: search }
$: resultQuery = searchQuery
function showCreateDialog () { function showCreateDialog () {
if (createComponent === undefined) return if (createComponent === undefined) return
showPopup(createComponent, createComponentProps, 'top') showPopup(createComponent, createComponentProps, 'top')
@ -167,9 +153,13 @@
size={'small'} size={'small'}
on:select={(result) => { on:select={(result) => {
if (result.detail !== undefined) { if (result.detail !== undefined) {
if (viewlet?._id === result.detail.id) return if (viewlet?._id === result.detail.id) {
return
}
viewlet = viewlets.find((vl) => vl._id === result.detail.id) viewlet = viewlets.find((vl) => vl._id === result.detail.id)
if (viewlet) setActiveViewletId(viewlet._id) if (viewlet) {
setActiveViewletId(viewlet._id)
}
} }
}} }}
/> />
@ -189,9 +179,9 @@
</div> </div>
</div> </div>
{#if loading} {#if !viewlet?.$lookup?.descriptor?.component || viewlet?.attachTo !== _class || (preference !== undefined && viewlet?._id !== preference.attachedTo)}}
<Loading /> <Loading />
{:else if viewlet?.$lookup?.descriptor?.component} {:else}
<FilterBar <FilterBar
{_class} {_class}
query={searchQuery} query={searchQuery}
@ -200,21 +190,19 @@
resultQuery = { ...query, ...e.detail } resultQuery = { ...query, ...e.detail }
}} }}
/> />
{#key viewlet?._id} <Component
<Component is={viewlet.$lookup.descriptor.component}
is={viewlet.$lookup.descriptor.component} props={{
props={{ _class,
_class, space,
space, options: viewlet.options,
options: viewlet.options, config: preference?.config ?? viewlet.config,
config: preference?.config ?? viewlet.config, viewlet,
viewlet, viewOptions,
viewOptions, viewOptionsConfig: viewlet.viewOptions?.other,
viewOptionsConfig: viewlet.viewOptions?.other, createItemDialog: createComponent,
createItemDialog: createComponent, createItemLabel: createLabel,
createItemLabel: createLabel, query: resultQuery
query: resultQuery }}
}} />
/>
{/key}
{/if} {/if}

View File

@ -542,7 +542,7 @@ abstract class MongoAdapterBase implements DbAdapter {
find (domain: Domain): StorageIterator { find (domain: Domain): StorageIterator {
const coll = this.db.collection<Doc>(domain) const coll = this.db.collection<Doc>(domain)
const iterator = coll.find({}, {}).batchSize(100) const iterator = coll.find({}, { sort: { _id: 1 } }).batchSize(100)
return { return {
next: async () => { next: async () => {