From cd1f9b6baa0dadfb14fee3a586a4b6b164e5e402 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 31 Mar 2023 00:19:14 +0200 Subject: [PATCH] fix(frontend): improve app tables --- .../display/table/AppAggridTable.svelte | 52 +++++++++++------- .../components/display/table/AppTable.svelte | 27 +++++++--- .../display/table/AppTableFooter.svelte | 4 +- .../components/apps/editor/AppEditor.svelte | 1 - .../apps/editor/component/components.ts | 53 +++++++++++-------- .../settingsPanel/InputsSpecsEditor.svelte | 2 +- .../OneOfInputSpecsEditor.svelte | 20 +++++-- 7 files changed, 102 insertions(+), 57 deletions(-) diff --git a/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte b/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte index 4e04691ff3..2b7778578a 100644 --- a/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte +++ b/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte @@ -4,15 +4,15 @@ import 'ag-grid-community/styles/ag-theme-alpine.css' import { getContext, onMount } from 'svelte' - import type { Output } from '../../../rx' import type { AppViewerContext, RichConfiguration, RichConfigurations } from '../../../types' - import InputValue from '../../helpers/InputValue.svelte' import type { AppInput } from '../../../inputType' import RunnableWrapper from '../../helpers/RunnableWrapper.svelte' import { isObject } from '$lib/utils' import Alert from '$lib/components/common/alert/Alert.svelte' - import { initOutput } from '$lib/components/apps/editor/appUtils' + import { initConfig, initOutput } from '$lib/components/apps/editor/appUtils' + import ResolveConfig from '../../helpers/ResolveConfig.svelte' + import { components } from '$lib/components/apps/editor/component' export let id: string export let componentInput: AppInput | undefined @@ -24,12 +24,18 @@ const { worldStore, selectedComponent } = getContext('AppViewerContext') + let resolvedConfig = initConfig( + components['aggridcomponent'].initialData.configuration, + configuration + ) + let outputs = initOutput($worldStore, id, { selectedRowIndex: 0, selectedRow: {}, result: [] as Record[], loading: false, - page: 0 + page: 0, + newChange: { row: 0, column: '', value: undefined } }) let selectedRowIndex = -1 @@ -60,27 +66,32 @@ let clientHeight let clientWidth - let columnDefs: any = undefined - - let allEditable: boolean | undefined = undefined - let pagination: boolean | undefined = undefined - let pageSize: number | undefined = 10 - function onCellValueChanged(event) { if (result) { + console.log(event) + let dataCell = event.newValue try { dataCell = JSON.parse(dataCell) } catch (e) {} + outputs?.newChange?.set({ + row: event.node.rowIndex, + column: event.colDef.field, + value: dataCell + }) result[event.node.rowIndex][event.column.colId] = dataCell } } - - - - +{#each Object.keys(components['aggridcomponent'].initialData.configuration) as key (key)} + +{/each} {#if Array.isArray(result) && result.every(isObject)} @@ -97,13 +108,16 @@ style:width="{clientWidth}px" class="ag-theme-alpine" > - {#key pagination} + {#key resolvedConfig?.pagination} { + outputs?.page.set(event.api.paginationGetCurrentPage()) + }} /> {/key} 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 a5567405b0..bfc3ff9b24 100644 --- a/frontend/src/lib/components/apps/components/display/table/AppTable.svelte +++ b/frontend/src/lib/components/apps/components/display/table/AppTable.svelte @@ -66,10 +66,7 @@ let resolvedConfig = initConfig( components['tablecomponent'].initialData.configuration, configuration - ) as { - search: 'By Component' | 'By Runnable' | 'Disabled' | undefined - manualPagination: boolean - } + ) let selectedRowIndex = -1 @@ -124,7 +121,8 @@ filteredResult = searchInResult(result ?? [], searchValue) } } - $: (result || resolvedConfig.search || searchValue) && setFilteredResult() + $: (result || resolvedConfig.search || searchValue || resolvedConfig.pagination) && + setFilteredResult() $: outputs.page.set($table.getState().pagination.pageIndex) @@ -139,7 +137,20 @@ $options = { ...tableOptions, - manualPagination: resolvedConfig.manualPagination, + ...(resolvedConfig?.pagination?.selected != 'manual' + ? { + initialState: { + pagination: { + pageSize: resolvedConfig?.pagination?.configuration?.auto?.pageSize ?? 20 + } + } + } + : {}), + manualPagination: resolvedConfig?.pagination?.selected == 'manual', + pageCount: + resolvedConfig?.pagination?.selected == 'manual' + ? resolvedConfig?.pagination?.configuration.manual.pageCount ?? -1 + : undefined, data: filteredResult, columns: headers.map((header) => { return { @@ -381,8 +392,8 @@ export let result: Array - export let paginationEnabled: boolean = false export let manualPagination: boolean + export let pageSize: number export let table: Readable> let c = '' export { c as class } @@ -32,7 +32,7 @@ class={twMerge('px-2 py-1 text-xs gap-2 items-center justify-between', c, 'flex flex-row')} {style} > - {#if (paginationEnabled && result.length > (tableOptions.initialState?.pagination?.pageSize ?? 25)) || manualPagination} + {#if result.length > pageSize || manualPagination}