Update table autoscreens to use grid layout

This commit is contained in:
Andrew Kingston 2024-08-20 14:58:07 +01:00
parent 9385bc878b
commit 7e5f43dd6d
No known key found for this signature in database
5 changed files with 90 additions and 49 deletions

View File

@ -54,4 +54,28 @@ export class Component extends BaseStructure {
getId() { getId() {
return this._json._id return this._json._id
} }
gridDesktopColSpan(start, end) {
this._json._styles.normal["--grid-desktop-col-start"] = start
this._json._styles.normal["--grid-desktop-col-end"] = end
return this
}
gridDesktopRowSpan(start, end) {
this._json._styles.normal["--grid-desktop-row-start"] = start
this._json._styles.normal["--grid-desktop-row-end"] = end
return this
}
gridMobileColSpan(start, end) {
this._json._styles.normal["--grid-mobile-col-start"] = start
this._json._styles.normal["--grid-mobile-col-end"] = end
return this
}
gridMobileRowSpan(start, end) {
this._json._styles.normal["--grid-mobile-row-start"] = start
this._json._styles.normal["--grid-mobile-row-end"] = end
return this
}
} }

View File

@ -9,16 +9,21 @@ const inline = ({ tableOrView, permissions, screens }) => {
.customProps({ .customProps({
text: tableOrView.name, text: tableOrView.name,
}) })
.gridDesktopColSpan(1, 13)
.gridDesktopRowSpan(1, 3)
const tableBlock = new Component("@budibase/standard-components/gridblock") const tableBlock = new Component("@budibase/standard-components/gridblock")
.instanceName(`${tableOrView.name} - Table`) .instanceName(`${tableOrView.name} - Table`)
.customProps({ .customProps({
table: tableOrView.datasourceSelectFormat, table: tableOrView.datasourceSelectFormat,
}) })
.gridDesktopColSpan(1, 13)
.gridDesktopRowSpan(3, 21)
const screenTemplate = new Screen() const screenTemplate = new Screen()
.route(getValidRoute(screens, tableOrView.name, permissions.write)) .route(getValidRoute(screens, tableOrView.name, permissions.write))
.instanceName(`${tableOrView.name} - List`) .instanceName(`${tableOrView.name} - List`)
.customProps({ layout: "grid" })
.role(permissions.write) .role(permissions.write)
.autoTableId(tableOrView.id) .autoTableId(tableOrView.id)
.addChild(heading) .addChild(heading)

View File

@ -33,26 +33,22 @@ const modal = ({ tableOrView, permissions, screens }) => {
type: "cta", type: "cta",
}) })
buttonGroup.instanceName(`${tableOrView.name} - Create`).customProps({ buttonGroup
.instanceName(`${tableOrView.name} - Create`)
.customProps({
hAlign: "right", hAlign: "right",
buttons: [createButton.json()], buttons: [createButton.json()],
}) })
.gridDesktopColSpan(7, 13)
const tableHeader = new Component("@budibase/standard-components/container") .gridDesktopRowSpan(1, 3)
.instanceName("Heading container")
.customProps({
direction: "row",
hAlign: "stretch",
})
const heading = new Component("@budibase/standard-components/heading") const heading = new Component("@budibase/standard-components/heading")
.instanceName("Table heading") .instanceName("Table heading")
.customProps({ .customProps({
text: tableOrView.name, text: tableOrView.name,
}) })
.gridDesktopColSpan(1, 7)
tableHeader.addChild(heading) .gridDesktopRowSpan(1, 3)
tableHeader.addChild(buttonGroup)
const createFormBlock = new Component( const createFormBlock = new Component(
"@budibase/standard-components/formblock" "@budibase/standard-components/formblock"
@ -134,13 +130,17 @@ const modal = ({ tableOrView, permissions, screens }) => {
], ],
}) })
.instanceName(`${tableOrView.name} - Table`) .instanceName(`${tableOrView.name} - Table`)
.gridDesktopColSpan(1, 13)
.gridDesktopRowSpan(3, 21)
const template = new Screen() const template = new Screen()
.route(getValidRoute(screens, tableOrView.name, permissions.write)) .route(getValidRoute(screens, tableOrView.name, permissions.write))
.instanceName(`${tableOrView.name} - List and details`) .instanceName(`${tableOrView.name} - List and details`)
.customProps({ layout: "grid" })
.role(permissions.write) .role(permissions.write)
.autoTableId(tableOrView.id) .autoTableId(tableOrView.id)
.addChild(tableHeader) .addChild(buttonGroup)
.addChild(heading)
.addChild(tableBlock) .addChild(tableBlock)
.addChild(createRowModal) .addChild(createRowModal)
.addChild(detailsModal) .addChild(detailsModal)

View File

@ -4,6 +4,7 @@ import { capitalise } from "helpers"
import { makePropSafe as safe } from "@budibase/string-templates" import { makePropSafe as safe } from "@budibase/string-templates"
import getValidRoute from "../getValidRoute" import getValidRoute from "../getValidRoute"
import { Helpers } from "@budibase/bbui" import { Helpers } from "@budibase/bbui"
import { head } from "lodash"
const getTableScreenTemplate = ({ const getTableScreenTemplate = ({
route, route,
@ -11,11 +12,12 @@ const getTableScreenTemplate = ({
createScreenRoute, createScreenRoute,
tableOrView, tableOrView,
permissions, permissions,
gridLayout,
}) => { }) => {
const newButton = new Component("@budibase/standard-components/button") const buttonGroup = new Component("@budibase/standard-components/buttongroup")
.instanceName("New button") const createButton = new Component("@budibase/standard-components/button")
.customProps({
text: "Create row", createButton.customProps({
onClick: [ onClick: [
{ {
"##eventHandlerType": "Navigate To", "##eventHandlerType": "Navigate To",
@ -25,22 +27,26 @@ const getTableScreenTemplate = ({
}, },
}, },
], ],
text: "Create row",
type: "cta",
}) })
buttonGroup
.instanceName(`${tableOrView.name} - Create`)
.customProps({
hAlign: "right",
buttons: [createButton.json()],
})
.gridDesktopColSpan(7, 13)
.gridDesktopRowSpan(1, 3)
const heading = new Component("@budibase/standard-components/heading") const heading = new Component("@budibase/standard-components/heading")
.instanceName("Table heading") .instanceName("Table heading")
.customProps({ .customProps({
text: tableOrView.name, text: tableOrView.name,
}) })
.gridDesktopColSpan(1, 7)
const tableHeader = new Component("@budibase/standard-components/container") .gridDesktopRowSpan(1, 3)
.instanceName("Heading container")
.customProps({
direction: "row",
hAlign: "stretch",
})
.addChild(heading)
.addChild(newButton)
const updateScreenRouteSegments = updateScreenRoute.split(":id") const updateScreenRouteSegments = updateScreenRoute.split(":id")
if (updateScreenRouteSegments.length !== 2) { if (updateScreenRouteSegments.length !== 2) {
@ -67,14 +73,18 @@ const getTableScreenTemplate = ({
}, },
], ],
}) })
.gridDesktopColSpan(1, 13)
.gridDesktopRowSpan(3, 21)
const template = new Screen() const template = new Screen()
.route(route) .route(route)
.instanceName(`${tableOrView.name} - List`) .instanceName(`${tableOrView.name} - List`)
.customProps({ layout: gridLayout ? "grid" : "flex" })
.role(permissions.write) .role(permissions.write)
.autoTableId(tableOrView.id) .autoTableId(tableOrView.id)
.addChild(tableHeader)
.addChild(tableBlock) .addChild(tableBlock)
.addChild(heading)
.addChild(buttonGroup)
.json() .json()
return { return {
@ -300,6 +310,7 @@ const newScreen = ({ tableOrView, permissions, screens }) => {
createScreenRoute, createScreenRoute,
permissions, permissions,
tableOrView, tableOrView,
gridLayout: true,
}) })
const updateScreenTemplate = getUpdateScreenTemplate({ const updateScreenTemplate = getUpdateScreenTemplate({
@ -307,6 +318,7 @@ const newScreen = ({ tableOrView, permissions, screens }) => {
tableScreenRoute, tableScreenRoute,
tableOrView, tableOrView,
permissions, permissions,
gridLayout: false,
}) })
const createScreenTemplate = getCreateScreenTemplate({ const createScreenTemplate = getCreateScreenTemplate({
@ -314,6 +326,7 @@ const newScreen = ({ tableOrView, permissions, screens }) => {
tableScreenRoute, tableScreenRoute,
tableOrView, tableOrView,
permissions, permissions,
gridLayout: false,
}) })
return [tableScreenTemplate, updateScreenTemplate, createScreenTemplate] return [tableScreenTemplate, updateScreenTemplate, createScreenTemplate]

View File

@ -31,27 +31,22 @@ const sidePanel = ({ tableOrView, permissions, screens }) => {
type: "cta", type: "cta",
}) })
buttonGroup.instanceName(`${tableOrView.name} - Create`).customProps({ buttonGroup
.instanceName(`${tableOrView.name} - Create`)
.customProps({
hAlign: "right", hAlign: "right",
buttons: [createButton.json()], buttons: [createButton.json()],
}) })
.gridDesktopColSpan(7, 13)
const tableHeader = new Component("@budibase/standard-components/container") .gridDesktopRowSpan(1, 3)
.instanceName("Heading container")
.customProps({
layout: "flex",
direction: "row",
hAlign: "stretch",
})
const heading = new Component("@budibase/standard-components/heading") const heading = new Component("@budibase/standard-components/heading")
.instanceName("Table heading") .instanceName("Table heading")
.customProps({ .customProps({
text: tableOrView.name, text: tableOrView.name,
}) })
.gridDesktopColSpan(1, 7)
tableHeader.addChild(heading) .gridDesktopRowSpan(1, 3)
tableHeader.addChild(buttonGroup)
const createFormBlock = new Component( const createFormBlock = new Component(
"@budibase/standard-components/formblock" "@budibase/standard-components/formblock"
@ -131,13 +126,17 @@ const sidePanel = ({ tableOrView, permissions, screens }) => {
], ],
}) })
.instanceName(`${tableOrView.name} - Table`) .instanceName(`${tableOrView.name} - Table`)
.gridDesktopColSpan(1, 13)
.gridDesktopRowSpan(3, 21)
const template = new Screen() const template = new Screen()
.route(getValidRoute(screens, tableOrView.name, permissions.write)) .route(getValidRoute(screens, tableOrView.name, permissions.write))
.instanceName(`${tableOrView.name} - List and details`) .instanceName(`${tableOrView.name} - List and details`)
.customProps({ layout: "grid" })
.role(permissions.write) .role(permissions.write)
.autoTableId(tableOrView.id) .autoTableId(tableOrView.id)
.addChild(tableHeader) .addChild(heading)
.addChild(buttonGroup)
.addChild(tableBlock) .addChild(tableBlock)
.addChild(createRowSidePanel) .addChild(createRowSidePanel)
.addChild(detailsSidePanel) .addChild(detailsSidePanel)