Merge pull request #550 from Budibase/backend-type-fix

fix bug with changing types
This commit is contained in:
Martin McKeaveney 2020-08-20 15:55:48 +01:00 committed by GitHub
commit 1c3de76e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 145 deletions

View File

@ -46,6 +46,7 @@
const { type, constraints } = fieldDefinitions[ const { type, constraints } = fieldDefinitions[
event.target.value.toUpperCase() event.target.value.toUpperCase()
] ]
field.type = type field.type = type
field.constraints = constraints field.constraints = constraints
} }
@ -58,9 +59,9 @@
secondary secondary
thin thin
on:change={handleFieldConstraints} on:change={handleFieldConstraints}
bind:value={field.value}> bind:value={field.type}>
{#each Object.values(fieldDefinitions) as field} {#each Object.values(fieldDefinitions) as field}
<option value={field.value}>{field.name}</option> <option value={field.type}>{field.name}</option>
{/each} {/each}
</Select> </Select>
@ -73,28 +74,28 @@
on:change={() => (field.constraints.presence.allowEmpty = required)} /> on:change={() => (field.constraints.presence.allowEmpty = required)} />
</div> </div>
{#if field.value === 'string' && field.constraints} {#if field.type === 'string' && field.constraints}
<NumberBox <NumberBox
label="Max Length" label="Max Length"
bind:value={field.constraints.length.maximum} /> bind:value={field.constraints.length.maximum} />
<ValuesList <ValuesList
label="Categories" label="Categories"
bind:values={field.constraints.inclusion} /> bind:values={field.constraints.inclusion} />
{:else if field.value === 'datetime' && field.constraints} {:else if field.type === 'datetime' && field.constraints}
<DatePicker <DatePicker
label="Min Value" label="Min Value"
bind:value={field.constraints.datetime.earliest} /> bind:value={field.constraints.datetime.earliest} />
<DatePicker <DatePicker
label="Max Value" label="Max Value"
bind:value={field.constraints.datetime.latest} /> bind:value={field.constraints.datetime.latest} />
{:else if field.value === 'number' && field.constraints} {:else if field.type === 'number' && field.constraints}
<NumberBox <NumberBox
label="Min Value" label="Min Value"
bind:value={field.constraints.numericality.greaterThanOrEqualTo} /> bind:value={field.constraints.numericality.greaterThanOrEqualTo} />
<NumberBox <NumberBox
label="Max Value" label="Max Value"
bind:value={field.constraints.numericality.lessThanOrEqualTo} /> bind:value={field.constraints.numericality.lessThanOrEqualTo} />
{:else if field.value === 'link'} {:else if field.type === 'link'}
<div class="field"> <div class="field">
<label>Link</label> <label>Link</label>
<select class="budibase__input" bind:value={field.modelId}> <select class="budibase__input" bind:value={field.modelId}>

View File

@ -21,7 +21,9 @@
$: fields = Object.keys($backendUiStore.selectedModel.schema).filter(key => { $: fields = Object.keys($backendUiStore.selectedModel.schema).filter(key => {
return $backendUiStore.selectedModel.schema[key].type === "number" return $backendUiStore.selectedModel.schema[key].type === "number"
}) })
$: views = $backendUiStore.models.flatMap(model => Object.keys(model.views)) $: views = $backendUiStore.models.flatMap(model =>
Object.keys(model.views || {})
)
function saveView() { function saveView() {
if (views.includes(name)) { if (views.includes(name)) {

View File

@ -3,7 +3,6 @@ export const FIELDS = {
name: "Plain Text", name: "Plain Text",
icon: "ri-text", icon: "ri-text",
type: "string", type: "string",
value: "string",
constraints: { constraints: {
type: "string", type: "string",
length: {}, length: {},
@ -14,7 +13,6 @@ export const FIELDS = {
name: "Number", name: "Number",
icon: "ri-number-1", icon: "ri-number-1",
type: "number", type: "number",
value: "number",
constraints: { constraints: {
type: "number", type: "number",
presence: { allowEmpty: true }, presence: { allowEmpty: true },
@ -25,7 +23,6 @@ export const FIELDS = {
name: "True/False", name: "True/False",
icon: "ri-toggle-line", icon: "ri-toggle-line",
type: "boolean", type: "boolean",
value: "boolean",
constraints: { constraints: {
type: "boolean", type: "boolean",
presence: { allowEmpty: true }, presence: { allowEmpty: true },
@ -40,21 +37,21 @@ export const FIELDS = {
// presence: { allowEmpty: true }, // presence: { allowEmpty: true },
// }, // },
// }, // },
DATETIME: { // DATETIME: {
name: "Date/Time", // name: "Date/Time",
icon: "ri-calendar-event-fill", // icon: "ri-calendar-event-fill",
type: "string", // type: "string",
value: "datetime", // value: "datetime",
constraints: { // constraints: {
type: "string", // type: "string",
length: {}, // length: {},
presence: { allowEmpty: true }, // presence: { allowEmpty: true },
datetime: { // datetime: {
latest: "", // latest: "",
earliest: "", // earliest: "",
}, // },
}, // },
}, // },
// IMAGE: { // IMAGE: {
// name: "File", // name: "File",
// icon: "ri-image-line", // icon: "ri-image-line",
@ -83,123 +80,3 @@ export const FIELDS = {
// }, // },
// }, // },
} }
export const BLOCKS = {
NAME: {
name: "Name",
icon: "ri-text",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
COMPANY: {
name: "Company",
icon: "ri-store-line",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
EMAIL: {
name: "Email",
icon: "ri-mail-line",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
PHONE_NUMBER: {
name: "Phone No.",
icon: "ri-phone-line",
type: "number",
constraints: {
type: "number",
presence: { allowEmpty: true },
numericality: {},
},
},
VALUE: {
name: "Value",
icon: "ri-number-5",
type: "number",
constraints: {
type: "number",
presence: { allowEmpty: true },
numericality: {},
},
},
ACTIVE: {
name: "Active",
icon: "ri-toggle-line",
type: "boolean",
constraints: {
type: "boolean",
presence: { allowEmpty: true },
},
},
URL: {
name: "URL",
icon: "ri-link",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
IMAGE: {
name: "Image URL",
icon: "ri-image-line",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
// PRIORITY: {
// name: "Options",
// icon: "ri-list-check-2",
// type: "options",
// constraints: {
// type: "string",
// presence: { allowEmpty: true },
// inclusion: ["low", "medium", "high"],
// },
// },
END_DATE: {
name: "End Date",
icon: "ri-calendar-event-fill",
type: "string",
constraints: {
type: "string",
length: {},
presence: { allowEmpty: true },
},
},
// AVATAR: {
// name: "Avatar",
// icon: "ri-image-line",
// type: "image",
// constraints: {
// type: "string",
// presence: { allowEmpty: true },
// },
// },
// PDF: {
// name: "PDF",
// icon: "ri-file-line",
// type: "file",
// constraints: {
// type: "string",
// presence: { allowEmpty: true },
// },
// },
}