-
- {#each fields as field}
-
- {#if !(schema[field].type === 'boolean' && !wide)}
-
- {/if}
- {#if schema[field].type === 'options'}
-
- {:else if schema[field].type === 'datetime'}
-
- {:else if schema[field].type === 'boolean'}
-
- {:else if schema[field].type === 'number'}
-
- {:else if schema[field].type === 'string'}
-
- {:else if schema[field].type === 'attachment'}
-
- {:else if schema[field].type === 'link'}
-
- {/if}
-
- {/each}
-
diff --git a/packages/standard-components/src/NewRow.svelte b/packages/standard-components/src/NewRow.svelte
new file mode 100644
index 0000000000..fe63fd27dd
--- /dev/null
+++ b/packages/standard-components/src/NewRow.svelte
@@ -0,0 +1,37 @@
+
+
+
diff --git a/packages/standard-components/src/RecordDetail.svelte b/packages/standard-components/src/RowDetail.svelte
similarity index 71%
rename from packages/standard-components/src/RecordDetail.svelte
rename to packages/standard-components/src/RowDetail.svelte
index 61ac79f4e7..a974bc9d1a 100644
--- a/packages/standard-components/src/RecordDetail.svelte
+++ b/packages/standard-components/src/RowDetail.svelte
@@ -20,6 +20,7 @@
if (response.status === 200) {
const allRecords = await response.json()
if (allRecords.length > 0) return allRecords[0]
+ return { modelId: model }
}
}
@@ -33,31 +34,35 @@
let record
// if srcdoc, then we assume this is the builder preview
if (pathParts.length === 0 || pathParts[0] === "srcdoc") {
- record = await fetchFirstRecord()
- } else {
- const id = pathParts[pathParts.length - 1]
- const GET_RECORD_URL = `/api/${model}/records/${id}`
+ if (model) record = await fetchFirstRecord()
+ } else if (_bb.routeParams().id) {
+ const GET_RECORD_URL = `/api/${model}/records/${_bb.routeParams().id}`
const response = await _bb.api.get(GET_RECORD_URL)
if (response.status === 200) {
record = await response.json()
+ } else {
+ throw new Error("Failed to fetch record.", response)
}
+ } else {
+ throw new Exception("Record ID was not supplied to RowDetail")
}
if (record) {
// Fetch model schema so we can check for linked records
- const model = await fetchModel(record.modelId)
- for (let key of Object.keys(model.schema)) {
- if (model.schema[key].type === "link") {
+ const modelObj = await fetchModel(record.modelId)
+ for (let key of Object.keys(modelObj.schema)) {
+ if (modelObj.schema[key].type === "link") {
record[key] = Array.isArray(record[key]) ? record[key].length : 0
}
}
+ record._model = modelObj
+
_bb.attachChildren(target, {
- hydrate: false,
context: record,
})
} else {
- throw new Error("Failed to fetch record.", response)
+ _bb.attachChildren(target)
}
}
diff --git a/packages/standard-components/src/index.js b/packages/standard-components/src/index.js
index 0ce5088cb8..c5a3c6085a 100644
--- a/packages/standard-components/src/index.js
+++ b/packages/standard-components/src/index.js
@@ -26,7 +26,8 @@ export { default as embed } from "./Embed.svelte"
export { default as stackedlist } from "./StackedList.svelte"
export { default as card } from "./Card.svelte"
export { default as cardhorizontal } from "./CardHorizontal.svelte"
-export { default as recorddetail } from "./RecordDetail.svelte"
+export { default as rowdetail } from "./RowDetail.svelte"
+export { default as newrow } from "./NewRow.svelte"
export { default as datepicker } from "./DatePicker.svelte"
export * from "./Chart"
export { default as icon } from "./Icon.svelte"