From 0673e715df0cb08b6b8eef8cdf35b82072f42772 Mon Sep 17 00:00:00 2001 From: Sergei Ogorelkov Date: Thu, 15 Dec 2022 00:17:50 +0600 Subject: [PATCH] SortableList presenter prop (#2437) Signed-off-by: Sergei Ogorelkov --- packages/ui/src/components/Component.svelte | 2 +- .../src/components/TagElementPresenter.svelte | 8 +++++--- plugins/tags-resources/src/plugin.ts | 1 - plugins/tags/src/index.ts | 3 ++- .../src/components/list/SortableList.svelte | 15 ++++++++++----- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/ui/src/components/Component.svelte b/packages/ui/src/components/Component.svelte index c188465edf..d609a78eae 100644 --- a/packages/ui/src/components/Component.svelte +++ b/packages/ui/src/components/Component.svelte @@ -35,7 +35,7 @@ {/if} {:then Ctor} - + {#if $$slots.default} {/if} diff --git a/plugins/tags-resources/src/components/TagElementPresenter.svelte b/plugins/tags-resources/src/components/TagElementPresenter.svelte index a3bbe6ab06..700770b509 100644 --- a/plugins/tags-resources/src/components/TagElementPresenter.svelte +++ b/plugins/tags-resources/src/components/TagElementPresenter.svelte @@ -13,12 +13,14 @@ // limitations under the License. --> @@ -31,9 +33,9 @@ showPopup(EditTagElement, { value, keyTitle }, eventToHTMLElement(evt)) }} > - + {:else} - + {/if} {/if} diff --git a/plugins/tags-resources/src/plugin.ts b/plugins/tags-resources/src/plugin.ts index 1408854f14..4cd9ee1145 100644 --- a/plugins/tags-resources/src/plugin.ts +++ b/plugins/tags-resources/src/plugin.ts @@ -19,7 +19,6 @@ import { Filter } from '@hcengineering/view' export default mergeIds(tagsId, tags, { component: { - TagElementPresenter: '' as AnyComponent, CategoryPresenter: '' as AnyComponent, TagElementCountPresenter: '' as AnyComponent }, diff --git a/plugins/tags/src/index.ts b/plugins/tags/src/index.ts index 0144852664..d2f4684189 100644 --- a/plugins/tags/src/index.ts +++ b/plugins/tags/src/index.ts @@ -106,7 +106,8 @@ const tagsPlugin = plugin(tagsId, { TagsCategoryBar: '' as AnyComponent, TagsAttributeEditor: '' as AnyComponent, TagsPresenter: '' as AnyComponent, - LabelsPresenter: '' as AnyComponent + LabelsPresenter: '' as AnyComponent, + TagElementPresenter: '' as AnyComponent }, category: { NoCategory: '' as Ref diff --git a/plugins/view-resources/src/components/list/SortableList.svelte b/plugins/view-resources/src/components/list/SortableList.svelte index 744027d780..9704aaf6b0 100644 --- a/plugins/view-resources/src/components/list/SortableList.svelte +++ b/plugins/view-resources/src/components/list/SortableList.svelte @@ -17,7 +17,7 @@ import { getResource, IntlString } from '@hcengineering/platform' import presentation, { createQuery, getClient } from '@hcengineering/presentation' import { calcRank, DocWithRank } from '@hcengineering/task' - import { Button, Component, IconAdd, Label, Loading } from '@hcengineering/ui' + import { AnyComponent, Button, Component, IconAdd, Label, Loading } from '@hcengineering/ui' import view, { AttributeModel, ObjectFactory } from '@hcengineering/view' import { flip } from 'svelte/animate' import { getObjectPresenter } from '../../utils' @@ -26,7 +26,7 @@ How to use: We must add presenter for the "_class" via "AttributePresenter" mixin - to be able display the rows list. + or pass it through "presenter" prop to be able display the rows list. To create a new items, we should add "ObjectFactory" mixin also. @@ -39,6 +39,7 @@ export let label: IntlString | undefined = undefined export let query: DocumentQuery = {} export let queryOptions: FindOptions | undefined = undefined + export let presenter: AnyComponent | undefined = undefined export let presenterProps: Record = {} export let direction: 'row' | 'column' = 'column' export let flipDuration = 200 @@ -134,7 +135,7 @@ hoveringIndex = null } - $: updateModel(_class, presenterProps) + $: !presenter && updateModel(_class, presenterProps) $: updateObjectFactory(_class) $: itemsQuery.query(_class, query, updateItems, { ...queryOptions, limit: Math.max(queryOptions?.limit ?? 0, 200) }) @@ -171,7 +172,7 @@ {#if isLoading} - {:else if model && items} + {:else if (presenter || model) && items} {@const isVertical = direction === 'column'}
{#each items as item, index (item._id)} @@ -189,7 +190,11 @@ on:drop={() => handleDrop(index)} on:dragend={resetDrag} > - + {#if presenter} + + {:else if model} + + {/if}
{/each}