Enable component nesting validation for new apps

This commit is contained in:
Andrew Kingston 2023-06-26 10:39:38 +01:00
parent 8bfb909280
commit 5f407259dc
4 changed files with 23 additions and 6 deletions

View File

@ -61,6 +61,9 @@ const INITIAL_FRONTEND_STATE = {
showNotificationAction: false, showNotificationAction: false,
sidePanel: false, sidePanel: false,
}, },
features: {
componentValidation: false,
},
errors: [], errors: [],
hasAppPackage: false, hasAppPackage: false,
libraries: null, libraries: null,
@ -145,6 +148,10 @@ export const getFrontendStore = () => {
navigation: application.navigation || {}, navigation: application.navigation || {},
usedPlugins: application.usedPlugins || [], usedPlugins: application.usedPlugins || [],
hasLock, hasLock,
features: {
...INITIAL_FRONTEND_STATE.features,
...application.features,
},
initialised: true, initialised: true,
})) }))
screenHistoryStore.reset() screenHistoryStore.reset()
@ -280,9 +287,12 @@ export const getFrontendStore = () => {
} }
}, },
save: async screen => { save: async screen => {
// Validate screen structure const state = get(store)
// Temporarily disabled to accommodate migration issues
// store.actions.screens.validate(screen) // Validate screen structure if the app supports it
if (state.features?.componentValidation) {
store.actions.screens.validate(screen)
}
// Check screen definition for any component settings which need updated // Check screen definition for any component settings which need updated
store.actions.screens.enrichEmptySettings(screen) store.actions.screens.enrichEmptySettings(screen)
@ -293,7 +303,6 @@ export const getFrontendStore = () => {
const routesResponse = await API.fetchAppRoutes() const routesResponse = await API.fetchAppRoutes()
// If plugins changed we need to fetch the latest app metadata // If plugins changed we need to fetch the latest app metadata
const state = get(store)
let usedPlugins = state.usedPlugins let usedPlugins = state.usedPlugins
if (savedScreen.pluginAdded) { if (savedScreen.pluginAdded) {
const { application } = await API.fetchAppPackage(state.appId) const { application } = await API.fetchAppPackage(state.appId)

View File

@ -2216,7 +2216,7 @@
"name": "Form", "name": "Form",
"icon": "Form", "icon": "Form",
"hasChildren": true, "hasChildren": true,
"illegalChildren": ["section", "form"], "illegalChildren": ["section", "form", "formblock"],
"actions": [ "actions": [
"ValidateForm", "ValidateForm",
"ClearForm", "ClearForm",
@ -2304,7 +2304,7 @@
"name": "Form Step", "name": "Form Step",
"icon": "AssetsAdded", "icon": "AssetsAdded",
"hasChildren": true, "hasChildren": true,
"illegalChildren": ["section", "form", "form step"], "illegalChildren": ["section", "form", "formstep", "formblock"],
"styles": ["size"], "styles": ["size"],
"size": { "size": {
"width": 400, "width": 400,

View File

@ -308,6 +308,9 @@ async function performAppCreate(ctx: UserCtx) {
customTheme: { customTheme: {
buttonBorderRadius: "16px", buttonBorderRadius: "16px",
}, },
features: {
componentValidation: true,
},
} }
// If we used a template or imported an app there will be an existing doc. // If we used a template or imported an app there will be an existing doc.

View File

@ -20,6 +20,7 @@ export interface App extends Document {
navigation?: AppNavigation navigation?: AppNavigation
automationErrors?: AppMetadataErrors automationErrors?: AppMetadataErrors
icon?: AppIcon icon?: AppIcon
features?: AppFeatures
} }
export interface AppInstance { export interface AppInstance {
@ -60,3 +61,7 @@ export interface AppIcon {
name: string name: string
color: string color: string
} }
export interface AppFeatures {
componentValidation?: boolean
}