-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15439 from Budibase/BUDI-8986/validate-screen-dat…
…asources Validate screen relationship datasource settings
- Loading branch information
Showing
6 changed files
with
123 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { makePropSafe } from "@budibase/string-templates" | ||
import { UIBinding } from "@budibase/types" | ||
|
||
export function extractRelationships(bindings: UIBinding[]) { | ||
return ( | ||
bindings | ||
// Get only link bindings | ||
.filter(x => x.fieldSchema?.type === "link") | ||
// Filter out bindings provided by forms | ||
.filter(x => !x.component?.endsWith("/form")) | ||
.map(binding => { | ||
const { providerId, readableBinding, fieldSchema } = binding || {} | ||
const { name, tableId } = fieldSchema || {} | ||
const safeProviderId = makePropSafe(providerId) | ||
return { | ||
providerId, | ||
label: readableBinding, | ||
fieldName: name, | ||
tableId, | ||
type: "link", | ||
// These properties will be enriched by the client library and provide | ||
// details of the parent row of the relationship field, from context | ||
rowId: `{{ ${safeProviderId}.${makePropSafe("_id")} }}`, | ||
rowTableId: `{{ ${safeProviderId}.${makePropSafe("tableId")} }}`, | ||
} | ||
}) | ||
) | ||
} | ||
|
||
export function extractFields(bindings: UIBinding[]) { | ||
return bindings | ||
.filter( | ||
x => | ||
x.fieldSchema?.type === "attachment" || | ||
(x.fieldSchema?.type === "array" && x.tableId) | ||
) | ||
.map(binding => { | ||
const { providerId, readableBinding, runtimeBinding } = binding | ||
const { name, type, tableId } = binding.fieldSchema! | ||
return { | ||
providerId, | ||
label: readableBinding, | ||
fieldName: name, | ||
fieldType: type, | ||
tableId, | ||
type: "field", | ||
value: `{{ literal ${runtimeBinding} }}`, | ||
} | ||
}) | ||
} | ||
|
||
export function extractJSONArrayFields(bindings: UIBinding[]) { | ||
return bindings | ||
.filter( | ||
x => | ||
x.fieldSchema?.type === "jsonarray" || | ||
(x.fieldSchema?.type === "json" && x.fieldSchema?.subtype === "array") | ||
) | ||
.map(binding => { | ||
const { providerId, readableBinding, runtimeBinding, tableId } = binding | ||
const { name, type, prefixKeys, subtype } = binding.fieldSchema! | ||
return { | ||
providerId, | ||
label: readableBinding, | ||
fieldName: name, | ||
fieldType: type, | ||
tableId, | ||
prefixKeys, | ||
type: type === "jsonarray" ? "jsonarray" : "queryarray", | ||
subtype, | ||
value: `{{ literal ${runtimeBinding} }}`, | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export type UIDatasourceType = "table" | "view" | "viewV2" | "query" | "custom" | ||
export type UIDatasourceType = | ||
| "table" | ||
| "view" | ||
| "viewV2" | ||
| "query" | ||
| "custom" | ||
| "link" |