Flatten JSON schema in apps to allow filtering and display of nested values
This commit is contained in:
parent
8dd916afb9
commit
7b20aa31d1
|
@ -4,6 +4,7 @@
|
|||
import CellRenderer from "./CellRenderer.svelte"
|
||||
import SelectEditRenderer from "./SelectEditRenderer.svelte"
|
||||
import { cloneDeep } from "lodash"
|
||||
import { deepGet } from "../utils/helpers"
|
||||
|
||||
/**
|
||||
* The expected schema is our normal couch schemas for our tables.
|
||||
|
@ -318,7 +319,7 @@
|
|||
{customRenderers}
|
||||
{row}
|
||||
schema={schema[field]}
|
||||
value={row[field]}
|
||||
value={deepGet(row, field)}
|
||||
on:clickrelationship
|
||||
>
|
||||
<slot />
|
||||
|
|
|
@ -76,3 +76,6 @@ export { default as clickOutside } from "./Actions/click_outside"
|
|||
|
||||
// Stores
|
||||
export { notifications, createNotificationStore } from "./Stores/notifications"
|
||||
|
||||
// Utils
|
||||
export * from "./utils/helpers"
|
||||
|
|
|
@ -6,3 +6,27 @@ export const generateID = () => {
|
|||
}
|
||||
|
||||
export const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1)
|
||||
|
||||
/**
|
||||
* Gets a key within an object. The key supports dot syntax for retrieving deep
|
||||
* fields - e.g. "a.b.c".
|
||||
* Exact matches of keys with dots in them take precedence over nested keys of
|
||||
* the same path - e.g. getting "a.b" from { "a.b": "foo", a: { b: "bar" } }
|
||||
* will return "foo" over "bar".
|
||||
* @param obj the object
|
||||
* @param key the key
|
||||
*/
|
||||
export const deepGet = (obj, key) => {
|
||||
if (!obj || !key) {
|
||||
return null
|
||||
}
|
||||
if (obj[key] != null) {
|
||||
return obj[key]
|
||||
}
|
||||
const split = key.split(".")
|
||||
let value = obj
|
||||
for (let i = 0; i < split.length; i++) {
|
||||
value = value?.[split[i]]
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { NoEmptyFilterStrings } from "../constants/lucene"
|
||||
import { deepGet } from "@budibase/bbui"
|
||||
|
||||
/**
|
||||
* Removes any fields that contain empty strings that would cause inconsistent
|
||||
|
@ -205,21 +206,3 @@ export const luceneLimit = (docs, limit) => {
|
|||
}
|
||||
return docs.slice(0, numLimit)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a key within an object. The key supports dot syntax for retrieving deep
|
||||
* fields - e.g. "a.b.c".
|
||||
* @param obj the object
|
||||
* @param key the key
|
||||
*/
|
||||
const deepGet = (obj, key) => {
|
||||
if (!obj || !key) {
|
||||
return null
|
||||
}
|
||||
const split = key.split(".")
|
||||
let value = obj
|
||||
for (let i = 0; i < split.length; i++) {
|
||||
value = value?.[split[i]]
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ export const fetchDatasourceSchema = async dataSource => {
|
|||
for (let i = 0; i < keysToSchema.length; i++) {
|
||||
schema = schema[keysToSchema[i]].schema
|
||||
}
|
||||
return convertJSONSchemaToTableSchema(schema)
|
||||
return convertJSONSchemaToTableSchema(schema, true)
|
||||
}
|
||||
|
||||
// Tables, views and links can be fetched by table ID
|
||||
|
|
Loading…
Reference in New Issue