Update form screen templates to include row actions and use a form block instead of multi step form block

This commit is contained in:
Andrew Kingston 2024-09-07 19:02:36 +01:00
parent 6172fddc40
commit 902112d5a7
No known key found for this signature in database
5 changed files with 63 additions and 27 deletions

View File

@ -123,15 +123,18 @@
} }
const createFormScreen = async type => { const createFormScreen = async type => {
const screenTemplates = selectedTablesAndViews.flatMap(tableOrView => const screenTemplates = (
screenTemplating.form({ await Promise.all(
screens, selectedTablesAndViews.map(tableOrView =>
tableOrView, screenTemplating.form({
type, screens,
permissions: permissions[tableOrView.id], tableOrView,
}) type,
) permissions: permissions[tableOrView.id],
})
)
)
).flat()
const newScreens = await createScreens(screenTemplates) const newScreens = await createScreens(screenTemplates)
if (type === "update" || type === "create") { if (type === "update" || type === "create") {

View File

@ -24,9 +24,9 @@ export class BaseStructure {
if (this._children.length !== 0) { if (this._children.length !== 0) {
for (let child of this._children) { for (let child of this._children) {
if (this._isScreen) { if (this._isScreen) {
structure.props._children.push(child.json()) structure.props._children.push(child.json?.() || child)
} else { } else {
structure._children.push(child.json()) structure._children.push(child.json?.() || child)
} }
} }
} }

View File

@ -1,5 +1,6 @@
import { Helpers } from "@budibase/bbui" import { Helpers } from "@budibase/bbui"
import { BaseStructure } from "./BaseStructure" import { BaseStructure } from "./BaseStructure"
import { componentStore } from "stores/builder"
export class Component extends BaseStructure { export class Component extends BaseStructure {
constructor(name, _id = Helpers.uuid()) { constructor(name, _id = Helpers.uuid()) {

View File

@ -4,15 +4,22 @@ import { rowActions, selectedScreen, componentStore } from "stores/builder"
import { Helpers } from "@budibase/bbui" import { Helpers } from "@budibase/bbui"
import { findComponent } from "helpers/components" import { findComponent } from "helpers/components"
export const getRowActionButtonTemplates = async ({ screen, component }) => { export const getRowActionButtonTemplates = async ({
if (!component) { screen,
return [] component,
instance,
}) => {
// Find root component instance if not specified
if (!instance) {
if (!component) {
return []
}
if (!screen) {
screen = get(selectedScreen)
}
const id = component._rootId
instance = findComponent(screen?.props, id)
} }
if (!screen) {
screen = get(selectedScreen)
}
const id = component._rootId
const instance = findComponent(screen?.props, id)
if (!instance) { if (!instance) {
return [] return []
} }

View File

@ -1,6 +1,9 @@
import { Screen } from "./Screen" import { Screen } from "./Screen"
import { Component } from "../Component" import { Component } from "../Component"
import getValidRoute from "./getValidRoute" import getValidRoute from "./getValidRoute"
import { componentStore } from "stores/builder"
import { Helpers } from "@budibase/bbui"
import { getRowActionButtonTemplates } from "templates/rowActions"
export const getTypeSpecificRoute = (tableOrView, type) => { export const getTypeSpecificRoute = (tableOrView, type) => {
if (type === "create") { if (type === "create") {
@ -32,27 +35,49 @@ const getActionType = type => {
} }
} }
const form = ({ tableOrView, type, permissions, screens }) => { const getTitle = type => {
if (type === "create") {
return "Create row"
} else if (type === "update") {
return "Update row"
}
return "Row details"
}
const form = async ({ tableOrView, type, permissions, screens }) => {
const id = Helpers.uuid()
const typeSpecificRoute = getTypeSpecificRoute(tableOrView, type) const typeSpecificRoute = getTypeSpecificRoute(tableOrView, type)
const role = getRole(permissions, type) const role = getRole(permissions, type)
const multistepFormBlock = new Component( let formBlock = new Component("@budibase/standard-components/formblock", id)
"@budibase/standard-components/multistepformblock"
)
.customProps({ .customProps({
actionType: getActionType(type),
dataSource: tableOrView.tableSelectFormat, dataSource: tableOrView.tableSelectFormat,
steps: [{}], actionType: getActionType(type),
title: getTitle(type),
rowId: type === "new" ? undefined : `{{ url.id }}`, rowId: type === "new" ? undefined : `{{ url.id }}`,
}) })
.instanceName(`${tableOrView.name} - Multistep Form block`) .instanceName(`${tableOrView.name} - Form block`)
.json()
// Add default button config
componentStore.migrateSettings(formBlock)
// Add row action buttons if required
if (type !== "create") {
const rowActionButtons = await getRowActionButtonTemplates({
instance: formBlock,
})
if (rowActionButtons.length) {
formBlock.buttons = [...(formBlock.buttons || []), ...rowActionButtons]
}
}
const template = new Screen() const template = new Screen()
.route(getValidRoute(screens, typeSpecificRoute, role)) .route(getValidRoute(screens, typeSpecificRoute, role))
.instanceName(`${tableOrView.name} - Form`) .instanceName(`${tableOrView.name} - Form`)
.role(role) .role(role)
.autoTableId(tableOrView.id) .autoTableId(tableOrView.id)
.addChild(multistepFormBlock) .addChild(formBlock)
.json() .json()
return [ return [