diff --git a/frontend/src/lib/components/apps/editor/appUtils.ts b/frontend/src/lib/components/apps/editor/appUtils.ts index 47f10a8066..8f05071f14 100644 --- a/frontend/src/lib/components/apps/editor/appUtils.ts +++ b/frontend/src/lib/components/apps/editor/appUtils.ts @@ -1004,3 +1004,25 @@ export function maxHeight( return Math.max(maxRowPerGrid, maxRows) } + +export function isTableAction(id: string, app: App): boolean { + const [tableId, actionId] = id.split('_') + + if (!tableId || !actionId) { + return false + } + + const table = findGridItem(app, tableId) + if ( + !table || + (table.data.type !== 'tablecomponent' && + table.data.type !== 'aggridcomponent' && + table.data.type !== 'aggridcomponentee' && + table.data.type !== 'dbexplorercomponent' && + table.data.type !== 'aggridinfinitecomponent' && + table.data.type !== 'aggridinfinitecomponentee') + ) { + return false + } + return true +} diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte index 1ac791f331..14cf1af3c3 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte @@ -17,12 +17,12 @@ import { ccomponents, components } from '../component' import CssProperty from '../componentsPanel/CssProperty.svelte' import GridTab from './GridTab.svelte' - import { deleteGridItem } from '../appUtils' + import { deleteGridItem, isTableAction } from '../appUtils' import GridPane from './GridPane.svelte' import { slide } from 'svelte/transition' import { push } from '$lib/history' import StylePanel from './StylePanel.svelte' - import { ChevronLeft, ArrowBigUp } from 'lucide-svelte' + import { ChevronLeft, ArrowBigUp, ArrowLeft } from 'lucide-svelte' import GridCondition from './GridCondition.svelte' import { isTriggerable } from './script/utils' import { inferDeps } from '../appUtilsInfer' @@ -42,6 +42,9 @@ import ContextVariables from './ContextVariables.svelte' import EventHandlers from './EventHandlers.svelte' import GridNavbar from './GridNavbar.svelte' + import Badge from '$lib/components/common/badge/Badge.svelte' + import { twMerge } from 'tailwind-merge' + import Popover from '$lib/components/Popover.svelte' export let componentSettings: { item: GridItem; parent: string | undefined } | undefined = undefined @@ -175,6 +178,47 @@ +{#if componentSettings?.item?.id && isTableAction(componentSettings?.item?.id, $app)} +
+
+ + +
Back to table component
+
+
+ + +
+{/if} + {#if componentSettings?.item?.data} {@const component = componentSettings.item.data}
diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/TableActions.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/TableActions.svelte index 8372ace64e..594d915b75 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/TableActions.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/TableActions.svelte @@ -2,13 +2,16 @@ import { Badge } from '$lib/components/common' import Button from '$lib/components/common/button/Button.svelte' import { getNextId } from '$lib/components/flows/idUtils' - import { classNames } from '$lib/utils' + import { classNames, generateRandomString } from '$lib/utils' import { getContext, onMount } from 'svelte' import type { AppViewerContext, BaseAppComponent } from '../../types' import { appComponentFromType } from '../appUtils' import type { ButtonComponent, CheckboxComponent, SelectComponent } from '../component' import PanelSection from './common/PanelSection.svelte' - import { Inspect, List, ToggleRightIcon, Trash } from 'lucide-svelte' + import { GripVertical, Inspect, List, ToggleRightIcon } from 'lucide-svelte' + import { dragHandle, dragHandleZone } from '@windmill-labs/svelte-dnd-action' + import CloseButton from '$lib/components/common/CloseButton.svelte' + import { flip } from 'svelte/animate' export let components: | (BaseAppComponent & (ButtonComponent | CheckboxComponent | SelectComponent))[] @@ -21,9 +24,16 @@ } }) + let items = + components?.map((tab, index) => { + return { value: tab, id: generateRandomString(), originalIndex: index } + }) ?? [] + + $: components = items.map((item) => item.value) + export let id: string - const { selectedComponent, app, errorByComponent } = + const { selectedComponent, app, errorByComponent, hoverStore } = getContext('AppViewerContext') function addComponent(typ: 'buttoncomponent' | 'checkboxcomponent' | 'selectcomponent') { @@ -37,11 +47,21 @@ ...appComponentFromType(typ)(`${id}_${actionId}`), recomputeIds: [] } + + items = [ + ...items, + { + value: newComponent, + id: generateRandomString(), + originalIndex: items.length + } + ] + components = [...components, newComponent] $app = $app } - function deleteComponent(cid: string) { + function deleteComponent(cid: string, index: number) { if (!components) { return } @@ -51,6 +71,20 @@ $selectedComponent = [id] $app = $app + + // Remove the corresponding item from the items array + items = items.filter((item) => item.originalIndex !== index) + } + + function handleConsider(e: CustomEvent): void { + const { items: newItems } = e.detail + + items = newItems + } + function handleFinalize(e: CustomEvent): void { + const { items: newItems } = e.detail + + items = newItems } @@ -59,43 +93,61 @@ {#if components.length == 0} No action buttons {/if} - {#each components as component} - -
{ - $selectedComponent = [component.id] +
+
- - {component.id} - + {#each items as item, index (item.id)} + {@const component = items[index].value} -
- {#if component.type == 'buttoncomponent'} - Button - {:else if component.type == 'selectcomponent'} - Select - {:else if component.type == 'checkboxcomponent'} - Toggle - {/if} -
-
-
-
- {/each} +
+ + +
{ + $selectedComponent = [component.id] + }} + on:mouseover={() => { + $hoverStore = component.id + }} + on:keypress + > +
+ + {component.id} + + +
+ {#if component.type == 'buttoncomponent'} + Button + {:else if component.type == 'selectcomponent'} + Select + {:else if component.type == 'checkboxcomponent'} + Toggle + {/if} +
+
+
+ deleteComponent(component.id, index)} /> +
+
+
+ +
+
+ {/each} + +