Merge pull request #300 from Budibase/fix-data-components
fix datalist, datatable and chart component
This commit is contained in:
commit
88ab1418bc
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import {onMount} from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { buildStyle } from "../../helpers.js"
|
import { buildStyle } from "../../helpers.js"
|
||||||
export let value = ""
|
export let value = ""
|
||||||
export let textAlign = "left"
|
export let textAlign = "left"
|
||||||
|
@ -7,22 +7,30 @@
|
||||||
export let placeholder = ""
|
export let placeholder = ""
|
||||||
export let suffix = ""
|
export let suffix = ""
|
||||||
export let onChange = val => {}
|
export let onChange = val => {}
|
||||||
|
|
||||||
let centerPlaceholder = textAlign === "center"
|
let centerPlaceholder = textAlign === "center"
|
||||||
|
|
||||||
let style = buildStyle({ width, textAlign })
|
let style = buildStyle({ width, textAlign })
|
||||||
|
|
||||||
function handleChange(val) {
|
function handleChange(val) {
|
||||||
value = val
|
value = val
|
||||||
let _value = value !== "auto" ? value + suffix : value
|
let _value = value !== "auto" ? value + suffix : value
|
||||||
onChange(_value)
|
onChange(_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
$: displayValue = suffix && value && value.endsWith(suffix) ? value.replace(new RegExp(`${suffix}$`), "") : (value || "")
|
$: displayValue =
|
||||||
|
suffix && value && value.endsWith(suffix)
|
||||||
|
? value.replace(new RegExp(`${suffix}$`), "")
|
||||||
|
: value || ""
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<input class:centerPlaceholder type="text" value={displayValue} {placeholder} {style} on:change={e => handleChange(e.target.value)} />
|
<input
|
||||||
|
class:centerPlaceholder
|
||||||
|
type="text"
|
||||||
|
value={displayValue}
|
||||||
|
{placeholder}
|
||||||
|
{style}
|
||||||
|
on:change={e => handleChange(e.target.value)} />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
input {
|
input {
|
||||||
|
@ -43,7 +51,7 @@
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
input::placeholder {
|
input::placeholder {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,11 @@
|
||||||
|
|
||||||
function handleChange(val, idx) {
|
function handleChange(val, idx) {
|
||||||
value.splice(idx, 1, val !== "auto" ? val + suffix : val)
|
value.splice(idx, 1, val !== "auto" ? val + suffix : val)
|
||||||
|
|
||||||
value = value
|
value = value
|
||||||
let _value = value.map(v => (!v.endsWith(suffix) && v !== "auto" ? v + suffix : v))
|
let _value = value.map(v =>
|
||||||
|
!v.endsWith(suffix) && v !== "auto" ? v + suffix : v
|
||||||
|
)
|
||||||
onChange(_value)
|
onChange(_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,5 +46,4 @@
|
||||||
.inputs-group {
|
.inputs-group {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -151,7 +151,7 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="root" on:click|stopPropagation={() => {}}>
|
<div class="root boundary" on:click|stopPropagation={() => {}}>
|
||||||
<button>
|
<button>
|
||||||
<MoreIcon />
|
<MoreIcon />
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import {buildStyle} from "../../helpers.js"
|
import { buildStyle } from "../../helpers.js"
|
||||||
export let value = ""
|
export let value = ""
|
||||||
export let text = ""
|
export let text = ""
|
||||||
export let icon = ""
|
export let icon = ""
|
||||||
|
@ -8,19 +8,24 @@
|
||||||
export let selected = false
|
export let selected = false
|
||||||
export let fontWeight = ""
|
export let fontWeight = ""
|
||||||
|
|
||||||
$: style = buildStyle({padding, fontWeight})
|
$: style = buildStyle({ padding, fontWeight })
|
||||||
$: useIcon = !!icon
|
$: useIcon = !!icon
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flatbutton" {style} class:selected on:click={() => onClick(value || text)}>
|
<div
|
||||||
|
class="flatbutton"
|
||||||
|
{style}
|
||||||
|
class:selected
|
||||||
|
on:click={() => onClick(value || text)}>
|
||||||
{#if useIcon}
|
{#if useIcon}
|
||||||
<i class={icon} />
|
<i class={icon} />
|
||||||
{:else}
|
{:else}
|
||||||
<span>{@html text}</span>
|
<span>
|
||||||
|
{@html text}
|
||||||
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.flatbutton {
|
.flatbutton {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -41,8 +46,8 @@
|
||||||
background: var(--ink-light);
|
background: var(--ink-light);
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
i{
|
i {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -28,10 +28,8 @@
|
||||||
onChange(val)
|
onChange(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const checkSelected = val =>
|
const checkSelected = val =>
|
||||||
isMultiSelect ? value.includes(val) : value === val
|
isMultiSelect ? value.includes(val) : value === val
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flatbutton-group">
|
<div class="flatbutton-group">
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<script>
|
||||||
|
import { backendUiStore } from "builderStore"
|
||||||
|
|
||||||
|
export let value
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="uk-margin block-field">
|
||||||
|
<div class="uk-form-controls">
|
||||||
|
<select class="budibase__input" on:change {value}>
|
||||||
|
{#each $backendUiStore.models as model}
|
||||||
|
<option value={model._id}>{model.name}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount, beforeUpdate } from "svelte"
|
import { onMount, beforeUpdate } from "svelte"
|
||||||
import {buildStyle} from "../../helpers.js"
|
import { buildStyle } from "../../helpers.js"
|
||||||
export let options = []
|
export let options = []
|
||||||
export let value = ""
|
export let value = ""
|
||||||
export let styleBindingProperty
|
export let styleBindingProperty
|
||||||
|
@ -214,10 +214,10 @@
|
||||||
height: auto;
|
height: auto;
|
||||||
padding: 5px 0px;
|
padding: 5px 0px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding-left: 10px
|
padding-left: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
li:hover {
|
li:hover {
|
||||||
background-color:#e6e6e6
|
background-color: #e6e6e6;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import Input from "../common/Input.svelte"
|
import Input from "../common/Input.svelte"
|
||||||
import OptionSelect from "./OptionSelect.svelte"
|
import OptionSelect from "./OptionSelect.svelte"
|
||||||
import Checkbox from "../common/Checkbox.svelte"
|
import Checkbox from "../common/Checkbox.svelte"
|
||||||
|
import ModelSelect from "components/userInterface/ModelSelect.svelte"
|
||||||
|
|
||||||
import { all } from "./propertyCategories.js"
|
import { all } from "./propertyCategories.js"
|
||||||
|
|
||||||
|
@ -273,14 +274,20 @@ export default {
|
||||||
_component: "@budibase/standard-components/datatable",
|
_component: "@budibase/standard-components/datatable",
|
||||||
description: "A component that generates a table from your data.",
|
description: "A component that generates a table from your data.",
|
||||||
icon: "ri-archive-drawer-fill",
|
icon: "ri-archive-drawer-fill",
|
||||||
properties: { design: { ...all } },
|
properties: {
|
||||||
|
design: { ...all },
|
||||||
|
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
||||||
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Form",
|
name: "Form",
|
||||||
description: "A component that generates a form from your data.",
|
description: "A component that generates a form from your data.",
|
||||||
icon: "ri-file-edit-fill",
|
icon: "ri-file-edit-fill",
|
||||||
properties: { design: { ...all } },
|
properties: {
|
||||||
|
design: { ...all },
|
||||||
|
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
||||||
|
},
|
||||||
_component: "@budibase/standard-components/dataform",
|
_component: "@budibase/standard-components/dataform",
|
||||||
template: {
|
template: {
|
||||||
component: "@budibase/materialdesign-components/Form",
|
component: "@budibase/materialdesign-components/Form",
|
||||||
|
@ -294,7 +301,10 @@ export default {
|
||||||
_component: "@budibase/standard-components/datachart",
|
_component: "@budibase/standard-components/datachart",
|
||||||
description: "Shiny chart",
|
description: "Shiny chart",
|
||||||
icon: "ri-bar-chart-fill",
|
icon: "ri-bar-chart-fill",
|
||||||
properties: { design: { ...all } },
|
properties: {
|
||||||
|
design: { ...all },
|
||||||
|
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
||||||
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -302,7 +312,10 @@ export default {
|
||||||
_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",
|
||||||
properties: { design: { ...all } },
|
properties: {
|
||||||
|
design: { ...all },
|
||||||
|
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
||||||
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="uk-margin block-field">
|
<div class="uk-margin block-field">
|
||||||
<label class="uk-form-label">Model</label>
|
|
||||||
<div class="uk-form-controls">
|
<div class="uk-form-controls">
|
||||||
<select class="budibase__input" bind:value>
|
<select class="budibase__input" bind:value>
|
||||||
{#each $backendUiStore.models as model}
|
{#each $backendUiStore.models as model}
|
||||||
|
|
|
@ -20,17 +20,17 @@
|
||||||
height: "400",
|
height: "400",
|
||||||
dataFormat: "json",
|
dataFormat: "json",
|
||||||
dataSource: {
|
dataSource: {
|
||||||
data: $store[model._id] || [],
|
data: $store[model] || [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
const FETCH_RECORDS_URL = `/api/${_instanceId}/all_${model._id}/records`
|
const FETCH_RECORDS_URL = `/api/${_instanceId}/views/all_${model}`
|
||||||
const response = await _bb.api.get(FETCH_RECORDS_URL)
|
const response = await _bb.api.get(FETCH_RECORDS_URL)
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state[model._id] = json
|
state[model] = json
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,13 +10,15 @@
|
||||||
let store = _bb.store
|
let store = _bb.store
|
||||||
|
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
const FETCH_RECORDS_URL = `/api/${_instanceId}/all_${model._id}/records`
|
if (!model || !model.length) return
|
||||||
|
|
||||||
|
const FETCH_RECORDS_URL = `/api/${_instanceId}/views/all_${model}`
|
||||||
const response = await _bb.api.get(FETCH_RECORDS_URL)
|
const response = await _bb.api.get(FETCH_RECORDS_URL)
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state[model._id] = json
|
state[model] = json
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,7 +26,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: data = $store[model._id] || []
|
$: data = $store[model] || []
|
||||||
|
$: if (model) fetchData()
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await fetchData()
|
await fetchData()
|
||||||
|
|
|
@ -10,13 +10,14 @@
|
||||||
let store = _bb.store
|
let store = _bb.store
|
||||||
|
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
const FETCH_RECORDS_URL = `/api/${_instanceId}/all_${model._id}/records`
|
const FETCH_RECORDS_URL = `/api/${_instanceId}/views/all_${model}`
|
||||||
|
|
||||||
const response = await _bb.api.get(FETCH_RECORDS_URL)
|
const response = await _bb.api.get(FETCH_RECORDS_URL)
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state[model._id] = json
|
state[model] = json
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -26,7 +27,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: data = $store[model._id] || []
|
$: data = $store[model] || []
|
||||||
|
$: if (model) fetchData()
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await fetchData()
|
await fetchData()
|
||||||
|
|
Loading…
Reference in New Issue