Sortable list adjustments (#2427)

Signed-off-by: Sergei Ogorelkov <sergei.ogorelkov@xored.com>
This commit is contained in:
Sergei Ogorelkov 2022-12-07 15:32:03 +06:00 committed by GitHub
parent 231f04f6a5
commit a843530bb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -42,6 +42,9 @@
export let presenterProps: Record<string, any> = {} export let presenterProps: Record<string, any> = {}
export let direction: 'row' | 'column' = 'column' export let direction: 'row' | 'column' = 'column'
export let flipDuration = 200 export let flipDuration = 200
export let isAddButtonHidden = false
export let isAddButtonDisabled = false
export let itemsCount = 0
const client = getClient() const client = getClient()
const hierarchy = client.getHierarchy() const hierarchy = client.getHierarchy()
@ -60,10 +63,10 @@
let isCreating = false let isCreating = false
async function updateModel (modelClassRef: Ref<Class<Doc>>) { async function updateModel (modelClassRef: Ref<Class<Doc>>, props: Record<string, any>) {
try { try {
isModelLoading = true isModelLoading = true
model = await getObjectPresenter(client, modelClassRef, { key: '', props: presenterProps }) model = await getObjectPresenter(client, modelClassRef, { key: '', props })
} finally { } finally {
isModelLoading = false isModelLoading = false
} }
@ -131,16 +134,17 @@
hoveringIndex = null hoveringIndex = null
} }
$: updateModel(_class) $: updateModel(_class, presenterProps)
$: updateObjectFactory(_class) $: updateObjectFactory(_class)
$: itemsQuery.query(_class, query, updateItems, { ...queryOptions, limit: Math.max(queryOptions?.limit ?? 0, 200) }) $: itemsQuery.query(_class, query, updateItems, { ...queryOptions, limit: Math.max(queryOptions?.limit ?? 0, 200) })
$: isLoading = isModelLoading || areItemsloading $: isLoading = isModelLoading || areItemsloading
$: isSortable = hierarchy.getAllAttributes(_class).has('rank') $: isSortable = hierarchy.getAllAttributes(_class).has('rank')
$: itemsCount = items?.length ?? 0
</script> </script>
<div class="flex-col"> <div class="flex-col">
{#if label} {#if label || !isAddButtonHidden}
<div class="flex mb-4"> <div class="flex mb-4">
{#if label} {#if label}
<div class="title-wrapper"> <div class="title-wrapper">
@ -149,11 +153,11 @@
</span> </span>
</div> </div>
{/if} {/if}
{#if objectFactory} {#if !isAddButtonHidden}
<div class="ml-auto"> <div class="ml-auto">
<Button <Button
showTooltip={{ label: presentation.string.Add }} showTooltip={{ label: presentation.string.Add }}
disabled={isLoading} disabled={isAddButtonDisabled || isLoading || !objectFactory}
width="min-content" width="min-content"
icon={IconAdd} icon={IconAdd}
size="small" size="small"

View File

@ -18,6 +18,7 @@
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import Circles from '../icons/Circles.svelte' import Circles from '../icons/Circles.svelte'
export let style = ''
export let isDraggable = false export let isDraggable = false
export let isEditable = false export let isEditable = false
export let isDeletable = false export let isDeletable = false
@ -32,6 +33,7 @@
<div <div
class="root flex background-button-bg-color border-radius-1" class="root flex background-button-bg-color border-radius-1"
{style}
on:dblclick|preventDefault={isEditable && !isEditing ? () => dispatch('edit') : undefined} on:dblclick|preventDefault={isEditable && !isEditing ? () => dispatch('edit') : undefined}
> >
<div class="flex-center ml-2"> <div class="flex-center ml-2">