Fixing an issue with deleting DS+ - also making sure if no screens/children found it correctly displays the pre-empt error.

This commit is contained in:
mike12345567 2025-02-10 18:25:36 +00:00
parent aaee61c1c2
commit 73fd7d2e5d
2 changed files with 14 additions and 3 deletions

View File

@ -8,6 +8,10 @@ import {
import { getProdAppID } from "./conversions" import { getProdAppID } from "./conversions"
import { DatabaseQueryOpts, VirtualDocumentType } from "@budibase/types" import { DatabaseQueryOpts, VirtualDocumentType } from "@budibase/types"
const EXTERNAL_TABLE_ID_REGEX = new RegExp(
`^${DocumentType.DATASOURCE_PLUS}_(.+)__(.+)$`
)
/** /**
* If creating DB allDocs/query params with only a single top level ID this can be used, this * If creating DB allDocs/query params with only a single top level ID this can be used, this
* is usually the case as most of our docs are top level e.g. tables, automations, users and so on. * is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
@ -64,6 +68,11 @@ export function getQueryIndex(viewName: ViewName) {
return `database/${viewName}` return `database/${viewName}`
} }
export const isExternalTableId = (id: string): boolean => {
const matches = id.match(EXTERNAL_TABLE_ID_REGEX)
return !!id && matches !== null
}
/** /**
* Check if a given ID is that of a table. * Check if a given ID is that of a table.
*/ */
@ -72,7 +81,7 @@ export const isTableId = (id: string): boolean => {
return ( return (
!!id && !!id &&
(id.startsWith(`${DocumentType.TABLE}${SEPARATOR}`) || (id.startsWith(`${DocumentType.TABLE}${SEPARATOR}`) ||
id.startsWith(`${DocumentType.DATASOURCE_PLUS}${SEPARATOR}`)) isExternalTableId(id))
) )
} }

View File

@ -151,6 +151,8 @@
const screenCount = affectedScreens.length const screenCount = affectedScreens.length
let message = `Removing ${source?.name} ` let message = `Removing ${source?.name} `
let initialLength = message.length let initialLength = message.length
const hasChanged = () => message.length !== initialLength
if (sourceType === SourceType.TABLE) { if (sourceType === SourceType.TABLE) {
const views = "views" in source ? Object.values(source?.views ?? []) : [] const views = "views" in source ? Object.values(source?.views ?? []) : []
message += `will delete its data${ message += `will delete its data${
@ -169,10 +171,10 @@
initialLength !== message.length initialLength !== message.length
? ", and break connected screens:" ? ", and break connected screens:"
: "will break connected screens:" : "will break connected screens:"
} else { } else if (hasChanged()) {
message += "." message += "."
} }
return message.length !== initialLength ? message : "" return hasChanged() ? message : ""
} }
</script> </script>