Give up on attempting to get jest to work with BBUI, change strategy for showing notifications when deleting invalid components

This commit is contained in:
Andrew Kingston 2021-10-04 16:50:52 +01:00
parent 9e74acfec0
commit b0b0268b7d
3 changed files with 22 additions and 13 deletions

View File

@ -8,7 +8,6 @@ import {
selectedComponent, selectedComponent,
selectedAccessRole, selectedAccessRole,
} from "builderStore" } from "builderStore"
import { notifications } from "@budibase/bbui"
import { import {
datasources, datasources,
integrations, integrations,
@ -16,7 +15,6 @@ import {
database, database,
tables, tables,
} from "stores/backend" } from "stores/backend"
import { fetchComponentLibDefinitions } from "../loadComponentLibraries" import { fetchComponentLibDefinitions } from "../loadComponentLibraries"
import api from "../api" import api from "../api"
import { FrontendTypes } from "constants" import { FrontendTypes } from "constants"
@ -472,8 +470,7 @@ export const getFrontendStore = () => {
// Ensure we aren't deleting the screen slot // Ensure we aren't deleting the screen slot
if (component._component?.endsWith("/screenslot")) { if (component._component?.endsWith("/screenslot")) {
notifications.error("You can't delete the screen slot") throw "You can't delete the screen slot"
return
} }
// Ensure we aren't deleting something that contains the screen slot // Ensure we aren't deleting something that contains the screen slot
@ -482,10 +479,7 @@ export const getFrontendStore = () => {
"@budibase/standard-components/screenslot" "@budibase/standard-components/screenslot"
) )
if (screenslot != null) { if (screenslot != null) {
notifications.error( throw "You can't delete a component that contains the screen slot"
"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)

View File

@ -6,7 +6,13 @@
import { Screen } from "builderStore/store/screenTemplates/utils/Screen" import { Screen } from "builderStore/store/screenTemplates/utils/Screen"
import { FrontendTypes } from "constants" import { FrontendTypes } from "constants"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { ProgressCircle, Layout, Heading, Body } from "@budibase/bbui" import {
ProgressCircle,
Layout,
Heading,
Body,
notifications,
} from "@budibase/bbui"
import ErrorSVG from "assets/error.svg?raw" import ErrorSVG from "assets/error.svg?raw"
import { findComponent, findComponentPath } from "builderStore/storeUtils" import { findComponent, findComponentPath } from "builderStore/storeUtils"
@ -166,10 +172,15 @@
confirmDeleteDialog.show() confirmDeleteDialog.show()
} }
const deleteComponent = () => { const deleteComponent = async () => {
store.actions.components.delete({ _id: idToDelete }) try {
await store.actions.components.delete({ _id: idToDelete })
} catch (error) {
notifications.error(error)
}
idToDelete = null idToDelete = null
} }
const cancelDeleteComponent = () => { const cancelDeleteComponent = () => {
idToDelete = null idToDelete = null
} }

View File

@ -3,7 +3,7 @@
import { store, currentAsset } from "builderStore" import { store, currentAsset } from "builderStore"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { findComponentParent } from "builderStore/storeUtils" import { findComponentParent } from "builderStore/storeUtils"
import { ActionMenu, MenuItem, Icon } from "@budibase/bbui" import { ActionMenu, MenuItem, Icon, notifications } from "@budibase/bbui"
export let component export let component
@ -51,7 +51,11 @@
} }
const deleteComponent = async () => { const deleteComponent = async () => {
await store.actions.components.delete(component) try {
await store.actions.components.delete(component)
} catch (error) {
notifications.error(error)
}
} }
const storeComponentForCopy = (cut = false) => { const storeComponentForCopy = (cut = false) => {