Prevent screen slot or something containing the screen slot from being deleted

This commit is contained in:
Andrew Kingston 2021-10-01 15:01:16 +01:00
parent 877ae757c4
commit 6e9736e79b
1 changed files with 24 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import {
selectedComponent, selectedComponent,
selectedAccessRole, selectedAccessRole,
} from "builderStore" } from "builderStore"
import { notifications } from "@budibase/bbui"
import { import {
datasources, datasources,
integrations, integrations,
@ -25,6 +26,7 @@ import {
findComponentParent, findComponentParent,
findClosestMatchingComponent, findClosestMatchingComponent,
findAllMatchingComponents, findAllMatchingComponents,
findComponent,
} from "../storeUtils" } from "../storeUtils"
import { uuid } from "../uuid" import { uuid } from "../uuid"
import { removeBindings } from "../dataBinding" import { removeBindings } from "../dataBinding"
@ -464,6 +466,28 @@ export const getFrontendStore = () => {
if (!asset) { if (!asset) {
return return
} }
// Fetch full definition
component = findComponent(asset.props, component._id)
// Ensure we aren't deleting the screen slot
if (component._component?.endsWith("/screenslot")) {
notifications.error("You can't delete the screen slot")
return
}
// Ensure we aren't deleting something that contains the screen slot
const screenslot = findComponentType(
component,
"@budibase/standard-components/screenslot"
)
if (screenslot != null) {
notifications.error(
"You can't delete a component that contains the screen slot"
)
return
}
const parent = findComponentParent(asset.props, component._id) const parent = findComponentParent(asset.props, component._id)
if (parent) { if (parent) {
parent._children = parent._children.filter( parent._children = parent._children.filter(