Files
windmill/frontend/src/lib/components/apps/editor/settingsPanel/DeleteComponent.svelte
T
Faton Ramadani 5bae66aec3 fix(frontend): Handle empty error message in toast + hide GridEditorM… (#3664)
* fix(frontend): Handle empty error message in toast + hide GridEditorMenu when the component is not visible

* fix(frontend): Handle empty error message in toast + hide GridEditorMenu when the component is not visible

* fix(frontend): use the right id
2024-05-02 19:09:45 +02:00

62 lines
1.6 KiB
Svelte

<script lang="ts">
import { getContext } from 'svelte'
import type { AppEditorContext, AppViewerContext } from '../../types'
import { deleteGridItem, findComponentSettings } from '../appUtils'
import { push } from '$lib/history'
export let onDelete: (() => void) | undefined = undefined
export let noGrid = false
const {
app,
runnableComponents,
selectedComponent,
worldStore,
focusedGrid,
errorByComponent,
componentControl
} = getContext<AppViewerContext>('AppViewerContext')
const { history, movingcomponents } = getContext<AppEditorContext>('AppEditorContext')
export function removeGridElement() {
const id = $selectedComponent?.[0]
const componentSetting = findComponentSettings($app, id)
push(history, $app)
const onDeleteComponentControl = id ? $componentControl[id]?.onDelete : undefined
if (onDeleteComponentControl) {
onDeleteComponentControl()
}
if (onDelete) {
onDelete()
}
if (id) {
delete $worldStore.outputsById[id]
delete $errorByComponent[id]
if ($movingcomponents?.includes(id)) {
$movingcomponents = $movingcomponents.filter((_id) => _id !== id)
}
}
$selectedComponent = undefined
$focusedGrid = undefined
if (componentSetting?.item && !noGrid) {
let ids = deleteGridItem($app, componentSetting?.item.data, componentSetting?.parent)
for (const key of ids) {
delete $runnableComponents[key]
}
}
if (componentSetting?.item?.data?.id) {
delete $runnableComponents[componentSetting?.item?.data?.id]
}
$app = $app
$runnableComponents = $runnableComponents
onDelete?.()
}
</script>