Update screen templates to work with latest bindings

This commit is contained in:
Andrew Kingston 2021-01-19 18:51:51 +00:00
parent 7e7219856d
commit 2ec4272558
8 changed files with 48 additions and 54 deletions

View File

@ -15,21 +15,9 @@ const allTemplates = tables => [
emptyRowDetailScreen, emptyRowDetailScreen,
] ]
// Recurses through a component tree and generates new unique ID's
const makeUniqueIds = component => {
if (!component) {
return
}
component._id = uuid()
if (component._children) {
component._children.forEach(makeUniqueIds)
}
}
// Allows us to apply common behaviour to all create() functions // Allows us to apply common behaviour to all create() functions
const createTemplateOverride = (frontendState, create) => () => { const createTemplateOverride = (frontendState, create) => () => {
const screen = create() const screen = create()
makeUniqueIds(screen.props)
screen.name = screen.props._id screen.name = screen.props._id
screen.routing.route = screen.routing.route.toLowerCase() screen.routing.route = screen.routing.route.toLowerCase()
return screen return screen

View File

@ -21,26 +21,29 @@ export default function(tables) {
export const newRowUrl = table => sanitizeUrl(`/${table.name}/new/row`) export const newRowUrl = table => sanitizeUrl(`/${table.name}/new/row`)
export const NEW_ROW_TEMPLATE = "NEW_ROW_TEMPLATE" export const NEW_ROW_TEMPLATE = "NEW_ROW_TEMPLATE"
function generateTitleContainer(table) { function generateTitleContainer(table, providerId) {
return makeTitleContainer("New Row").addChild(makeSaveButton(table)) return makeTitleContainer("New Row").addChild(
makeSaveButton(table, providerId)
)
} }
const createScreen = table => { const createScreen = table => {
const dataform = new Component( const screen = new Screen()
"@budibase/standard-components/dataformwide"
).instanceName("Form")
const container = makeMainContainer()
.addChild(makeBreadcrumbContainer(table.name, "New"))
.addChild(generateTitleContainer(table))
.addChild(dataform)
return new Screen()
.component("@budibase/standard-components/newrow") .component("@budibase/standard-components/newrow")
.table(table._id) .table(table._id)
.route(newRowUrl(table)) .route(newRowUrl(table))
.instanceName(`${table.name} - New`) .instanceName(`${table.name} - New`)
.name("") .name("")
.addChild(container)
.json() const dataform = new Component(
"@budibase/standard-components/dataformwide"
).instanceName("Form")
const providerId = screen._json.props._id
const container = makeMainContainer()
.addChild(makeBreadcrumbContainer(table.name, "New"))
.addChild(generateTitleContainer(table, providerId))
.addChild(dataform)
return screen.addChild(container).json()
} }

View File

@ -25,9 +25,9 @@ export default function(tables) {
export const ROW_DETAIL_TEMPLATE = "ROW_DETAIL_TEMPLATE" export const ROW_DETAIL_TEMPLATE = "ROW_DETAIL_TEMPLATE"
export const rowDetailUrl = table => sanitizeUrl(`/${table.name}/:id`) export const rowDetailUrl = table => sanitizeUrl(`/${table.name}/:id`)
function generateTitleContainer(table, title) { function generateTitleContainer(table, title, providerId) {
// have to override style for this, its missing margin // have to override style for this, its missing margin
const saveButton = makeSaveButton(table).normalStyle({ const saveButton = makeSaveButton(table, providerId).normalStyle({
background: "#000000", background: "#000000",
"border-width": "0", "border-width": "0",
"border-style": "None", "border-style": "None",
@ -60,8 +60,8 @@ function generateTitleContainer(table, title) {
onClick: [ onClick: [
{ {
parameters: { parameters: {
rowId: "{{ data._id }}", rowId: `{{ ${providerId}._id }}`,
revId: "{{ data._rev }}", revId: `{{ ${providerId}._rev }}`,
tableId: table._id, tableId: table._id,
}, },
"##eventHandlerType": "Delete Row", "##eventHandlerType": "Delete Row",
@ -82,21 +82,22 @@ function generateTitleContainer(table, title) {
} }
const createScreen = (table, heading) => { const createScreen = (table, heading) => {
const dataform = new Component( const screen = new Screen()
"@budibase/standard-components/dataformwide"
).instanceName("Form")
const container = makeMainContainer()
.addChild(makeBreadcrumbContainer(table.name, heading || "Edit"))
.addChild(generateTitleContainer(table, heading || "Edit Row"))
.addChild(dataform)
return new Screen()
.component("@budibase/standard-components/rowdetail") .component("@budibase/standard-components/rowdetail")
.table(table._id) .table(table._id)
.instanceName(`${table.name} - Detail`) .instanceName(`${table.name} - Detail`)
.route(rowDetailUrl(table)) .route(rowDetailUrl(table))
.name("") .name("")
.addChild(container)
.json() const dataform = new Component(
"@budibase/standard-components/dataformwide"
).instanceName("Form")
const providerId = screen._json.props._id
const container = makeMainContainer()
.addChild(makeBreadcrumbContainer(table.name, heading || "Edit"))
.addChild(generateTitleContainer(table, heading || "Edit Row", providerId))
.addChild(dataform)
return screen.addChild(container).json()
} }

View File

@ -1,4 +1,4 @@
import { v4 } from "uuid" import { uuid } from "builderStore/uuid"
import { BaseStructure } from "./BaseStructure" import { BaseStructure } from "./BaseStructure"
export class Component extends BaseStructure { export class Component extends BaseStructure {
@ -6,7 +6,7 @@ export class Component extends BaseStructure {
super(false) super(false)
this._children = [] this._children = []
this._json = { this._json = {
_id: v4(), _id: uuid(),
_component: name, _component: name,
_styles: { _styles: {
normal: {}, normal: {},

View File

@ -1,4 +1,5 @@
import { BaseStructure } from "./BaseStructure" import { BaseStructure } from "./BaseStructure"
import { uuid } from "builderStore/uuid"
export class Screen extends BaseStructure { export class Screen extends BaseStructure {
constructor() { constructor() {
@ -6,7 +7,7 @@ export class Screen extends BaseStructure {
this._json = { this._json = {
layoutId: "layout_private_master", layoutId: "layout_private_master",
props: { props: {
_id: "", _id: uuid(),
_component: "", _component: "",
_styles: { _styles: {
normal: {}, normal: {},

View File

@ -78,7 +78,7 @@ export function makeBreadcrumbContainer(tableName, text, capitalise = false) {
.addChild(identifierText) .addChild(identifierText)
} }
export function makeSaveButton(table) { export function makeSaveButton(table, providerId) {
return new Component("@budibase/standard-components/button") return new Component("@budibase/standard-components/button")
.normalStyle({ .normalStyle({
background: "#000000", background: "#000000",
@ -100,8 +100,7 @@ export function makeSaveButton(table) {
onClick: [ onClick: [
{ {
parameters: { parameters: {
contextPath: "data", providerId,
tableId: table._id,
}, },
"##eventHandlerType": "Save Row", "##eventHandlerType": "Save Row",
}, },

View File

@ -44,13 +44,13 @@
<option value={provider._id}>{provider._instanceName}</option> <option value={provider._id}>{provider._instanceName}</option>
{/each} {/each}
</Select> </Select>
{/if}
{#if parameters.contextPath} {#if parameters.providerId}
<SaveFields <SaveFields
parameterFields={parameters.fields} parameterFields={parameters.fields}
{schemaFields} {schemaFields}
on:fieldschanged={onFieldsChanged} /> on:fieldschanged={onFieldsChanged} />
{/if}
{/if} {/if}
</div> </div>

View File

@ -426,6 +426,8 @@
"icon": "ri-profile-line", "icon": "ri-profile-line",
"hasChildren": true, "hasChildren": true,
"styleable": true, "styleable": true,
"dataProvider": true,
"datasourceSetting": "table",
"settings": [ "settings": [
{ {
"type": "table", "type": "table",