From a450ac53011884b46f54ebe87ede45dd59e835e5 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 1 Nov 2023 11:30:35 +0100 Subject: [PATCH] feat: improve inputs handling for large list on apps --- .../components/display/table/AppTable.svelte | 23 ++++- .../components/inputs/AppSliderInputs.svelte | 1 + .../apps/components/layout/AppList.svelte | 86 +++++++++++-------- .../apps/components/layout/ListWrapper.svelte | 23 ++--- .../apps/components/layout/RowWrapper.svelte | 25 ++---- .../components/apps/editor/GridEditor.svelte | 1 - .../apps/editor/SubGridEditor.svelte | 3 +- frontend/src/lib/components/apps/rx.ts | 1 - .../components/apps/svelte-grid/Grid.svelte | 22 ++--- .../apps/svelte-grid/MoveResize.svelte | 46 ++++++---- 10 files changed, 123 insertions(+), 108 deletions(-) diff --git a/frontend/src/lib/components/apps/components/display/table/AppTable.svelte b/frontend/src/lib/components/apps/components/display/table/AppTable.svelte index 4694bde19a..a7750a4333 100644 --- a/frontend/src/lib/components/apps/components/display/table/AppTable.svelte +++ b/frontend/src/lib/components/apps/components/display/table/AppTable.svelte @@ -423,10 +423,29 @@ {#each actionButtons as actionButton, actionIndex (actionButton?.id)} { + on:set={(e) => { + const { id, value } = e.detail + if (!inputs[id]) { + inputs[id] = { [rowIndex]: value } + } else { + inputs[id] = { ...inputs[id], [rowIndex]: value } + } + outputs?.inputs.set(inputs, true) + }} + on:remove={(e) => { + const id = e.detail + if (inputs?.[id] == undefined) { + return + } + if (rowIndex == 0) { + delete inputs[id] + inputs = { ...inputs } + } else { + delete inputs[id][rowIndex] + inputs[id] = { ...inputs[id] } + } outputs?.inputs.set(inputs, true) }} > diff --git a/frontend/src/lib/components/apps/components/inputs/AppSliderInputs.svelte b/frontend/src/lib/components/apps/components/inputs/AppSliderInputs.svelte index 81d0e59e6e..c4043aab20 100644 --- a/frontend/src/lib/components/apps/components/inputs/AppSliderInputs.svelte +++ b/frontend/src/lib/components/apps/components/inputs/AppSliderInputs.svelte @@ -67,6 +67,7 @@ // } const num = isNaN(+values[0]) ? null : +values[0] outputs?.result.set(num) + if (iterContext && listInputs) { listInputs.set(id, num) } diff --git a/frontend/src/lib/components/apps/components/layout/AppList.svelte b/frontend/src/lib/components/apps/components/layout/AppList.svelte index f2495c5d8a..7943e9880c 100644 --- a/frontend/src/lib/components/apps/components/layout/AppList.svelte +++ b/frontend/src/lib/components/apps/components/layout/AppList.svelte @@ -22,7 +22,7 @@ export let render: boolean export let initializing: boolean | undefined - const { app, focusedGrid, selectedComponent, worldStore, connectingInput, allIdsInPath } = + const { app, focusedGrid, selectedComponent, worldStore, connectingInput, allIdsInPath, mode } = getContext('AppViewerContext') let page = 0 @@ -69,19 +69,17 @@ initialData: Array | undefined = [], page: number = 0 ) { - const sanitizedData = Array.isArray(initialData) ? initialData : [] - + const l = initialData ? initialData.length : 0 if (mode === 'auto') { const pageSize: number = configuration.auto.pageSize ?? 0 - const data = sanitizedData?.slice(0 + page * pageSize, pageSize + page * pageSize) ?? [] - const shouldDisplayPagination = pageSize < sanitizedData?.length ?? false - const total = Math.ceil(sanitizedData.length / pageSize ?? 0) + const shouldDisplayPagination = pageSize < l ?? false + const total = Math.ceil(l / pageSize ?? 0) return { - data, shouldDisplayPagination, indexOffset: page * pageSize, - disableNext: pageSize > 0 && (page + 1) * pageSize >= sanitizedData?.length, + maxIndex: (page + 1) * pageSize - 1, + disableNext: pageSize > 0 && (page + 1) * pageSize >= l, total: total } } else { @@ -90,8 +88,8 @@ return { shouldDisplayPagination: true, - data: sanitizedData ?? [], indexOffset: 0, + maxIndex: l, disableNext: page + 1 >= pageCount, total: total } @@ -139,43 +137,61 @@ bind:loading >
{#if $app.subgrids?.[`${id}-0`]} - {#if Array.isArray(pagination.data) && pagination.data.length > 0} - {#each pagination?.data ?? [] as value, index} + {#if Array.isArray(result) && result.length > 0} + {#each result ?? [] as value, index (index)} + {@const inRange = index <= pagination.maxIndex && index >= pagination.indexOffset}
{ + on:set={(e) => { + const { id, value } = e.detail + if (!inputs[id]) { + inputs[id] = { [index]: value } + } else { + inputs[id] = { ...inputs[id], [index]: value } + } + outputs?.inputs.set(inputs, true) + }} + on:remove={(e) => { + const id = e.detail + if (inputs?.[id] == undefined) { + return + } + if (index == 0) { + delete inputs[id] + inputs = { ...inputs } + } else { + delete inputs[id][index] + inputs[id] = { ...inputs[id] } + } outputs?.inputs.set(inputs, true) }} - bind:inputs {value} - index={index + pagination.indexOffset} + {index} > {/each} {:else} - {}} disabled value={undefined} index={0}> + {#if !Array.isArray(result)} @@ -200,7 +216,9 @@ {/if}
{#if pagination.shouldDisplayPagination} -
+