Update row detail autoscreen to use new data provider and safe bindings
This commit is contained in:
parent
d88c91c11a
commit
a3d57b3f82
|
@ -37,7 +37,7 @@ const createScreen = table => {
|
||||||
.customProps({
|
.customProps({
|
||||||
theme: "spectrum--lightest",
|
theme: "spectrum--lightest",
|
||||||
size: "spectrum--medium",
|
size: "spectrum--medium",
|
||||||
datasource: {
|
dataSource: {
|
||||||
label: table.name,
|
label: table.name,
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
type: "table",
|
type: "table",
|
||||||
|
|
|
@ -25,7 +25,7 @@ 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, formId) {
|
function generateTitleContainer(table, title, formId, repeaterId) {
|
||||||
// have to override style for this, its missing margin
|
// have to override style for this, its missing margin
|
||||||
const saveButton = makeSaveButton(table, formId).normalStyle({
|
const saveButton = makeSaveButton(table, formId).normalStyle({
|
||||||
background: "#000000",
|
background: "#000000",
|
||||||
|
@ -61,10 +61,9 @@ function generateTitleContainer(table, title, formId) {
|
||||||
onClick: [
|
onClick: [
|
||||||
{
|
{
|
||||||
parameters: {
|
parameters: {
|
||||||
providerId: formId,
|
|
||||||
rowId: `{{ ${makePropSafe(formId)}._id }}`,
|
|
||||||
revId: `{{ ${makePropSafe(formId)}._rev }}`,
|
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
|
rowId: `{{ ${makePropSafe(repeaterId)}.${makePropSafe("_id")} }}`,
|
||||||
|
revId: `{{ ${makePropSafe(repeaterId)}.${makePropSafe("_rev")} }}`,
|
||||||
},
|
},
|
||||||
"##eventHandlerType": "Delete Row",
|
"##eventHandlerType": "Delete Row",
|
||||||
},
|
},
|
||||||
|
@ -84,18 +83,33 @@ function generateTitleContainer(table, title, formId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const createScreen = table => {
|
const createScreen = table => {
|
||||||
const screen = new Screen()
|
const provider = new Component("@budibase/standard-components/dataprovider")
|
||||||
.component("@budibase/standard-components/rowdetail")
|
.instanceName(`Data Provider`)
|
||||||
.table(table._id)
|
.customProps({
|
||||||
.instanceName(`${table.name} - Detail`)
|
dataSource: {
|
||||||
.route(rowDetailUrl(table))
|
label: table.name,
|
||||||
|
name: `all_${table._id}`,
|
||||||
|
tableId: table._id,
|
||||||
|
type: "table",
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
_id: `{{ ${makePropSafe("url")}.${makePropSafe("id")} }}`,
|
||||||
|
},
|
||||||
|
limit: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
const repeater = new Component("@budibase/standard-components/list")
|
||||||
|
.instanceName("Repeater")
|
||||||
|
.customProps({
|
||||||
|
dataProvider: `{{ literal ${makePropSafe(provider._json._id)} }}`,
|
||||||
|
})
|
||||||
|
|
||||||
const form = makeMainForm()
|
const form = makeMainForm()
|
||||||
.instanceName("Form")
|
.instanceName("Form")
|
||||||
.customProps({
|
.customProps({
|
||||||
theme: "spectrum--lightest",
|
theme: "spectrum--lightest",
|
||||||
size: "spectrum--medium",
|
size: "spectrum--medium",
|
||||||
datasource: {
|
dataSource: {
|
||||||
label: table.name,
|
label: table.name,
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
type: "table",
|
type: "table",
|
||||||
|
@ -116,14 +130,24 @@ const createScreen = table => {
|
||||||
|
|
||||||
// Add all children to the form
|
// Add all children to the form
|
||||||
const formId = form._json._id
|
const formId = form._json._id
|
||||||
const rowDetailId = screen._json.props._id
|
const repeaterId = repeater._json._id
|
||||||
const heading = table.primaryDisplay
|
const heading = table.primaryDisplay
|
||||||
? `{{ ${makePropSafe(rowDetailId)}.${makePropSafe(table.primaryDisplay)} }}`
|
? `{{ ${makePropSafe(repeaterId)}.${makePropSafe(table.primaryDisplay)} }}`
|
||||||
: null
|
: null
|
||||||
form
|
form
|
||||||
.addChild(makeBreadcrumbContainer(table.name, heading || "Edit"))
|
.addChild(makeBreadcrumbContainer(table.name, heading || "Edit"))
|
||||||
.addChild(generateTitleContainer(table, heading || "Edit Row", formId))
|
.addChild(
|
||||||
|
generateTitleContainer(table, heading || "Edit Row", formId, repeaterId)
|
||||||
|
)
|
||||||
.addChild(fieldGroup)
|
.addChild(fieldGroup)
|
||||||
|
|
||||||
return screen.addChild(form).json()
|
repeater.addChild(form)
|
||||||
|
provider.addChild(repeater)
|
||||||
|
|
||||||
|
return new Screen()
|
||||||
|
.component("@budibase/standard-components/container")
|
||||||
|
.instanceName(`${table.name} - Detail`)
|
||||||
|
.route(rowDetailUrl(table))
|
||||||
|
.addChild(provider)
|
||||||
|
.json()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import sanitizeUrl from "./utils/sanitizeUrl"
|
||||||
import { newRowUrl } from "./newRowScreen"
|
import { newRowUrl } from "./newRowScreen"
|
||||||
import { Screen } from "./utils/Screen"
|
import { Screen } from "./utils/Screen"
|
||||||
import { Component } from "./utils/Component"
|
import { Component } from "./utils/Component"
|
||||||
|
import { makePropSafe } from "@budibase/string-templates"
|
||||||
|
|
||||||
export default function(tables) {
|
export default function(tables) {
|
||||||
return tables.map(table => {
|
return tables.map(table => {
|
||||||
|
@ -83,7 +84,7 @@ const createScreen = table => {
|
||||||
|
|
||||||
const grid = new Component("@budibase/standard-components/datagrid")
|
const grid = new Component("@budibase/standard-components/datagrid")
|
||||||
.customProps({
|
.customProps({
|
||||||
dataProvider: `{{ literal ${provider._json._id} }}`,
|
dataProvider: `{{ literal ${makePropSafe(provider._json._id)} }}`,
|
||||||
editable: false,
|
editable: false,
|
||||||
theme: "alpine",
|
theme: "alpine",
|
||||||
height: "540",
|
height: "540",
|
||||||
|
@ -117,10 +118,8 @@ const createScreen = table => {
|
||||||
|
|
||||||
return new Screen()
|
return new Screen()
|
||||||
.component("@budibase/standard-components/container")
|
.component("@budibase/standard-components/container")
|
||||||
.mainType("div")
|
|
||||||
.route(rowListUrl(table))
|
.route(rowListUrl(table))
|
||||||
.instanceName(`${table.name} - List`)
|
.instanceName(`${table.name} - List`)
|
||||||
.name("")
|
|
||||||
.addChild(mainContainer)
|
.addChild(mainContainer)
|
||||||
.json()
|
.json()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue