Adding some basic UI around the key/value data type.
This commit is contained in:
parent
e996d4cc9d
commit
18b742ede5
|
@ -9,6 +9,7 @@
|
||||||
DatePicker,
|
DatePicker,
|
||||||
ModalContent,
|
ModalContent,
|
||||||
Context,
|
Context,
|
||||||
|
Modal,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
|
@ -32,12 +33,14 @@
|
||||||
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
|
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
|
||||||
import { getBindings } from "components/backend/DataTable/formula"
|
import { getBindings } from "components/backend/DataTable/formula"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
import JSONSchemaModal from "./JSONSchemaModal.svelte"
|
||||||
|
|
||||||
const AUTO_TYPE = "auto"
|
const AUTO_TYPE = "auto"
|
||||||
const FORMULA_TYPE = FIELDS.FORMULA.type
|
const FORMULA_TYPE = FIELDS.FORMULA.type
|
||||||
const LINK_TYPE = FIELDS.LINK.type
|
const LINK_TYPE = FIELDS.LINK.type
|
||||||
const STRING_TYPE = FIELDS.STRING.type
|
const STRING_TYPE = FIELDS.STRING.type
|
||||||
const NUMBER_TYPE = FIELDS.NUMBER.type
|
const NUMBER_TYPE = FIELDS.NUMBER.type
|
||||||
|
const JSON_TYPE = FIELDS.JSON.type
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const PROHIBITED_COLUMN_NAMES = ["type", "_id", "_rev", "tableId"]
|
const PROHIBITED_COLUMN_NAMES = ["type", "_id", "_rev", "tableId"]
|
||||||
|
@ -63,6 +66,7 @@
|
||||||
let confirmDeleteDialog
|
let confirmDeleteDialog
|
||||||
let deletion
|
let deletion
|
||||||
let deleteColName
|
let deleteColName
|
||||||
|
let jsonSchemaModal
|
||||||
|
|
||||||
$: checkConstraints(field)
|
$: checkConstraints(field)
|
||||||
$: required = !!field?.constraints?.presence || primaryDisplay
|
$: required = !!field?.constraints?.presence || primaryDisplay
|
||||||
|
@ -83,6 +87,7 @@
|
||||||
// used to select what different options can be displayed for column type
|
// used to select what different options can be displayed for column type
|
||||||
$: canBeSearched =
|
$: canBeSearched =
|
||||||
field.type !== LINK_TYPE &&
|
field.type !== LINK_TYPE &&
|
||||||
|
field.type !== JSON_TYPE &&
|
||||||
field.subtype !== AUTO_COLUMN_SUB_TYPES.CREATED_BY &&
|
field.subtype !== AUTO_COLUMN_SUB_TYPES.CREATED_BY &&
|
||||||
field.subtype !== AUTO_COLUMN_SUB_TYPES.UPDATED_BY &&
|
field.subtype !== AUTO_COLUMN_SUB_TYPES.UPDATED_BY &&
|
||||||
field.type !== FORMULA_TYPE
|
field.type !== FORMULA_TYPE
|
||||||
|
@ -173,6 +178,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openJsonSchemaEditor() {
|
||||||
|
jsonSchemaModal.show()
|
||||||
|
}
|
||||||
|
|
||||||
function confirmDelete() {
|
function confirmDelete() {
|
||||||
confirmDeleteDialog.show()
|
confirmDeleteDialog.show()
|
||||||
deletion = true
|
deletion = true
|
||||||
|
@ -400,6 +409,10 @@
|
||||||
getOptionLabel={option => option[1].name}
|
getOptionLabel={option => option[1].name}
|
||||||
getOptionValue={option => option[0]}
|
getOptionValue={option => option[0]}
|
||||||
/>
|
/>
|
||||||
|
{:else if field.type === JSON_TYPE}
|
||||||
|
<Button primary text on:click={openJsonSchemaEditor}
|
||||||
|
>Open schema editor</Button
|
||||||
|
>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div slot="footer">
|
<div slot="footer">
|
||||||
|
@ -408,6 +421,9 @@
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
|
<Modal bind:this={jsonSchemaModal}>
|
||||||
|
<JSONSchemaModal on:save={({ detail }) => console.log(detail)} />
|
||||||
|
</Modal>
|
||||||
<ConfirmDialog
|
<ConfirmDialog
|
||||||
bind:this={confirmDeleteDialog}
|
bind:this={confirmDeleteDialog}
|
||||||
okText="Delete Column"
|
okText="Delete Column"
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
<script>
|
||||||
|
import Editor from "../../../integration/QueryEditor.svelte"
|
||||||
|
import {
|
||||||
|
ModalContent,
|
||||||
|
Tabs,
|
||||||
|
Tab,
|
||||||
|
Button,
|
||||||
|
Input,
|
||||||
|
Select,
|
||||||
|
} from "@budibase/bbui"
|
||||||
|
import { onMount, createEventDispatcher } from "svelte"
|
||||||
|
|
||||||
|
export let onConfirm = undefined
|
||||||
|
export let schema = {}
|
||||||
|
|
||||||
|
let dispatcher = createEventDispatcher()
|
||||||
|
let mode = "Key/Value"
|
||||||
|
let json
|
||||||
|
let fieldCount = 0
|
||||||
|
let fieldKeys = {},
|
||||||
|
fieldTypes = {}
|
||||||
|
let keyValueOptions = ["String", "Number", "Boolean", "Object", "Array"]
|
||||||
|
|
||||||
|
$: invalid = false
|
||||||
|
|
||||||
|
function onJsonUpdate({ detail }) {
|
||||||
|
// TODO: make request
|
||||||
|
const input = detail.value
|
||||||
|
console.log(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveSchema() {
|
||||||
|
for (let i of Object.keys(fieldKeys)) {
|
||||||
|
const key = fieldKeys[i]
|
||||||
|
schema[key] = {
|
||||||
|
type: fieldTypes[i],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dispatcher("save", schema)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (!schema) {
|
||||||
|
schema = {}
|
||||||
|
}
|
||||||
|
let i = 0
|
||||||
|
for (let [key, value] of Object.entries(schema)) {
|
||||||
|
fieldKeys[i] = key
|
||||||
|
fieldTypes[i] = value.type
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
fieldCount = i
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ModalContent
|
||||||
|
title={"Key/Value Schema Editor"}
|
||||||
|
confirmText="Save Column"
|
||||||
|
onConfirm={saveSchema}
|
||||||
|
disabled={invalid}
|
||||||
|
size="L"
|
||||||
|
>
|
||||||
|
<Tabs selected={mode} noPadding>
|
||||||
|
<Tab title="Key/Value">
|
||||||
|
{#each Array(fieldCount) as _, i}
|
||||||
|
<div class="horizontal">
|
||||||
|
<Input outline label="Key" bind:value={fieldKeys[i]} />
|
||||||
|
<Select
|
||||||
|
label="Type"
|
||||||
|
options={keyValueOptions}
|
||||||
|
bind:value={fieldTypes[i]}
|
||||||
|
getOptionValue={field => field.toLowerCase()}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
<div class:add-field-btn={fieldCount !== 0}>
|
||||||
|
<Button primary text on:click={() => fieldCount++}>Add Field</Button>
|
||||||
|
</div>
|
||||||
|
</Tab>
|
||||||
|
<Tab title="JSON">
|
||||||
|
<Editor mode="json" on:change={onJsonUpdate} value={json} />
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
</ModalContent>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.horizontal {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 30% 1fr;
|
||||||
|
grid-gap: var(--spacing-s);
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-field-btn {
|
||||||
|
margin-top: var(--spacing-xl);
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -89,6 +89,14 @@ export const FIELDS = {
|
||||||
presence: false,
|
presence: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
JSON: {
|
||||||
|
name: "Key/Value",
|
||||||
|
type: "json",
|
||||||
|
constraints: {
|
||||||
|
type: "object",
|
||||||
|
presence: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AUTO_COLUMN_SUB_TYPES = {
|
export const AUTO_COLUMN_SUB_TYPES = {
|
||||||
|
|
Loading…
Reference in New Issue