Merge branch 'rf/flatten' of https://github.com/windmill-labs/windmill into rf/flatten

This commit is contained in:
Faton Ramadani
2023-02-24 18:44:19 +01:00
5 changed files with 64 additions and 29 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { getContext } from 'svelte'
import type { AppEditorContext } from '../types'
import { allItems } from '../utils'
import { allItems, allItemsWithParent } from '../utils'
import PanelSection from './settingsPanel/common/PanelSection.svelte'
import ComponentPanel from './settingsPanel/ComponentPanel.svelte'
import InputsSpecsEditor from './settingsPanel/InputsSpecsEditor.svelte'
@@ -10,9 +10,9 @@
const { selectedComponent, app } = getContext<AppEditorContext>('AppEditorContext')
</script>
{#each allItems($app.grid, $app.subgrids) as gridItem (gridItem.data.id)}
{#each allItemsWithParent($app.grid, $app.subgrids) as [gridItem, parent] (gridItem.data.id)}
{#if gridItem.data.id === $selectedComponent}
<ComponentPanel bind:component={gridItem.data} />
<ComponentPanel {parent} bind:component={gridItem.data} />
{:else if gridItem.data.type === 'tablecomponent'}
<TablePanel bind:component={gridItem.data} />
{/if}

View File

@@ -11,6 +11,8 @@
{#each component.actionButtons as actionButton (actionButton.id)}
{#if actionButton.id === $selectedComponent}
<ComponentPanel
parent={undefined}
noGrid
rowColumns
bind:component={actionButton}
onDelete={() => {

View File

@@ -1,6 +1,6 @@
import { getNextId } from '$lib/components/flows/flowStateUtils'
import type { App, FocusedGrid, GridItem } from '../types'
import { getRecommendedDimensionsByComponent, type AppComponent } from './component'
import { Component, getRecommendedDimensionsByComponent, type AppComponent } from './component'
import gridHelp from '@windmill-labs/svelte-grid/src/utils/helper'
import { gridColumns } from '../gridUtils'
@@ -117,32 +117,48 @@ export function insertNewGridItem(
return id
}
export function deleteGridItem(app: App, id: string) {
const index = app.grid.findIndex((item) => item.id === id)
if (index !== -1) {
app.grid.splice(index, 1)
return
}
const gridItem = findGridItem(app, id)
const keys = Object.keys(app.subgrids ?? {})
if (app.subgrids) {
if (keys.includes(id)) {
for (let i = 0; i < gridItem?.data.numberOfSubgrids; i++) {
delete app.subgrids[`${id}-${i}`]
}
} else {
for (const key of keys) {
const subgrid = app.subgrids[key]
const index = subgrid.findIndex((item) => item.id === id)
if (index !== -1) {
subgrid.splice(index, 1)
return
export function getAllSubgridsAndComponentIds(app: App, component: AppComponent): [string[], string[]] {
const subgrids: string[] = []
let components: string[] = [component.id]
if (app.subgrids && component.numberOfSubgrids) {
for (let i = 0; i < component.numberOfSubgrids; i++) {
const subgrid = app.subgrids[`${component.id}-${i}`]
if (subgrid) {
for (const item of subgrid) {
let [recSubgrids, recComponents] = getAllSubgridsAndComponentIds(app, item.data)
subgrids.push(...recSubgrids)
components.push(...recComponents)
}
}
}
}
return [subgrids, components]
}
export function deleteGridItem(app: App, component: AppComponent, parent: string | undefined): string[] {
let [subgrids, components] = getAllSubgridsAndComponentIds(app, component)
if (app.subgrids) {
subgrids.forEach((id) => {
delete app.subgrids![id]
})
}
if (!parent) {
let index = app.grid.findIndex((x) => x.id == component.id)
if (index > -1) {
app.grid.splice(index, 1)
}
} else {
let grid = app.subgrids![parent]
let index = grid.findIndex((x) => x.id == component.id)
if (index > -1) {
grid.splice(index, 1)
}
}
return components
}
export function duplicateGridItem(

View File

@@ -22,10 +22,13 @@
import { dirtyStore } from '$lib/components/common/confirmationModal/dirtyStore'
import GridTab from './GridTab.svelte'
import { duplicateGridItem } from '../appUtils'
import { deleteGridItem } from '../appUtils'
export let component: AppComponent | undefined
export let component: AppComponent
export let rowColumns = false
export let onDelete: (() => void) | undefined = undefined
export let parent: string | undefined
export let noGrid = false
const { app, staticOutputs, runnableComponents, selectedComponent, worldStore, focusedGrid } =
getContext<AppEditorContext>('AppEditorContext')
@@ -37,17 +40,23 @@
}
function removeGridElement() {
/*
$selectedComponent = undefined
$focusedGrid = undefined
if (component) {
deleteComponent(gridItems, component, $app, $staticOutputs, $runnableComponents)
if (component && !noGrid) {
let ids = deleteGridItem($app, component, parent)
for (const key in ids) {
delete $staticOutputs[key]
delete $runnableComponents[key]
}
}
delete $staticOutputs[component.id]
delete $runnableComponents[component.id]
$app = $app
$staticOutputs = $staticOutputs
$runnableComponents = $runnableComponents
onDelete?.()
*/
}
$: extraLib =

View File

@@ -54,6 +54,14 @@ export function allItems(grid: GridItem[], subgrids: Record<string, GridItem[]>
return [...grid, ...Object.values(subgrids).flat()]
}
export function allItemsWithParent(grid: GridItem[], subgrids: Record<string, GridItem[]> | undefined): [GridItem, string | undefined][] {
const items: [GridItem, string | undefined][] = grid.map((item) => [item, undefined])
if (subgrids == undefined) {
return items
}
return [...items, ...Object.entries(subgrids).flatMap(([k, v]) => v.map((g) => [g, k] as [GridItem, string]))]
}
export async function loadSchema(
workspace: string,
path: string,