Merge pull request #324 from mjashanks/new-list-spike
New List Component
This commit is contained in:
commit
fa61c043f9
|
@ -343,7 +343,7 @@ export default {
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "List",
|
name: "Data List",
|
||||||
_component: "@budibase/standard-components/datalist",
|
_component: "@budibase/standard-components/datalist",
|
||||||
description: "Shiny list",
|
description: "Shiny list",
|
||||||
icon: "ri-file-list-fill",
|
icon: "ri-file-list-fill",
|
||||||
|
@ -353,6 +353,17 @@ export default {
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "List",
|
||||||
|
_component: "@budibase/standard-components/list",
|
||||||
|
description: "Shiny list",
|
||||||
|
icon: "ri-file-list-fill",
|
||||||
|
properties: {
|
||||||
|
design: { ...all },
|
||||||
|
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Map",
|
name: "Map",
|
||||||
_component: "@budibase/standard-components/datamap",
|
_component: "@budibase/standard-components/datamap",
|
||||||
|
|
|
@ -14,6 +14,7 @@ export const attachChildren = initialiseOpts => (htmlElement, options) => {
|
||||||
const anchor = options && options.anchor ? options.anchor : null
|
const anchor = options && options.anchor ? options.anchor : null
|
||||||
const force = options ? options.force : false
|
const force = options ? options.force : false
|
||||||
const hydrate = options ? options.hydrate : true
|
const hydrate = options ? options.hydrate : true
|
||||||
|
const context = options && options.context
|
||||||
|
|
||||||
if (!force && treeNode.children.length > 0) return treeNode.children
|
if (!force && treeNode.children.length > 0) return treeNode.children
|
||||||
|
|
||||||
|
@ -37,16 +38,27 @@ export const attachChildren = initialiseOpts => (htmlElement, options) => {
|
||||||
|
|
||||||
const ComponentConstructor = componentLibraries[libName][componentName]
|
const ComponentConstructor = componentLibraries[libName][componentName]
|
||||||
|
|
||||||
const childNodesThisIteration = prepareRenderComponent({
|
const prepareNodes = ctx => {
|
||||||
props: childProps,
|
const childNodesThisIteration = prepareRenderComponent({
|
||||||
parentNode: treeNode,
|
props: childProps,
|
||||||
ComponentConstructor,
|
parentNode: treeNode,
|
||||||
htmlElement,
|
ComponentConstructor,
|
||||||
anchor,
|
htmlElement,
|
||||||
})
|
anchor,
|
||||||
|
context: ctx,
|
||||||
|
})
|
||||||
|
|
||||||
for (let childNode of childNodesThisIteration) {
|
for (let childNode of childNodesThisIteration) {
|
||||||
childNodes.push(childNode)
|
childNodes.push(childNode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(context)) {
|
||||||
|
for (let singleCtx of context) {
|
||||||
|
prepareNodes(singleCtx)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prepareNodes(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,12 @@ export const prepareRenderComponent = ({
|
||||||
anchor,
|
anchor,
|
||||||
props,
|
props,
|
||||||
parentNode,
|
parentNode,
|
||||||
|
context,
|
||||||
}) => {
|
}) => {
|
||||||
const parentContext = (parentNode && parentNode.context) || {}
|
const parentContext = (parentNode && parentNode.context) || {}
|
||||||
|
|
||||||
let nodesToRender = []
|
let nodesToRender = []
|
||||||
const createNodeAndRender = context => {
|
const createNodeAndRender = () => {
|
||||||
let componentContext = parentContext
|
let componentContext = parentContext
|
||||||
if (context) {
|
if (context) {
|
||||||
componentContext = { ...context }
|
componentContext = { ...context }
|
||||||
|
@ -48,6 +49,7 @@ export const prepareRenderComponent = ({
|
||||||
if (typeof propValue === "string") {
|
if (typeof propValue === "string") {
|
||||||
storeBoundProps[prop] = mustache.render(propValue, {
|
storeBoundProps[prop] = mustache.render(propValue, {
|
||||||
state,
|
state,
|
||||||
|
context: componentContext,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,6 +217,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"list": {
|
||||||
|
"description": "A configurable data list that attaches to your backend models.",
|
||||||
|
"data": true,
|
||||||
|
"props": {
|
||||||
|
"model": "models",
|
||||||
|
"layout": {
|
||||||
|
"type": "options",
|
||||||
|
"default": "list",
|
||||||
|
"options": [
|
||||||
|
"list",
|
||||||
|
"grid"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"datamap": {
|
"datamap": {
|
||||||
"description": "shiny chart",
|
"description": "shiny chart",
|
||||||
"data": true,
|
"data": true,
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
<script>
|
||||||
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
|
export let _bb
|
||||||
|
export let _instanceId
|
||||||
|
export let model
|
||||||
|
export let layout = "list"
|
||||||
|
|
||||||
|
let headers = []
|
||||||
|
let store = _bb.store
|
||||||
|
let target
|
||||||
|
|
||||||
|
async function fetchData() {
|
||||||
|
if (!model || !model.length) return
|
||||||
|
|
||||||
|
const FETCH_RECORDS_URL = `/api/${_instanceId}/views/all_${model}`
|
||||||
|
const response = await _bb.api.get(FETCH_RECORDS_URL)
|
||||||
|
if (response.status === 200) {
|
||||||
|
const json = await response.json()
|
||||||
|
|
||||||
|
_bb.attachChildren(target, {
|
||||||
|
hydrate: false,
|
||||||
|
context: json,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
throw new Error("Failed to fetch records.", response)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if (model) fetchData()
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
await fetchData()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<section class:grid={layout === 'grid'} class:list={layout === 'list'}>
|
||||||
|
<div class="data-card" bind:this={target}>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
font-family: Roboto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin: 5px 0 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.data-card {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.data-key {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 20px;
|
||||||
|
text-transform: capitalize;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -18,5 +18,6 @@ export { default as datatable } from "./DataTable.svelte"
|
||||||
export { default as dataform } from "./DataForm.svelte"
|
export { default as dataform } from "./DataForm.svelte"
|
||||||
export { default as datachart } from "./DataChart.svelte"
|
export { default as datachart } from "./DataChart.svelte"
|
||||||
export { default as datalist } from "./DataList.svelte"
|
export { default as datalist } from "./DataList.svelte"
|
||||||
|
export { default as list } from "./List.svelte"
|
||||||
export { default as datasearch } from "./DataSearch.svelte"
|
export { default as datasearch } from "./DataSearch.svelte"
|
||||||
export { default as datamap } from "./DataMap.svelte"
|
export { default as datamap } from "./DataMap.svelte"
|
||||||
|
|
Loading…
Reference in New Issue