Merge pull request #414 from mjashanks/master

#383 rename Model > Table (ui only) & #290 field name validation
This commit is contained in:
Michael Shanks 2020-07-02 21:25:44 +01:00 committed by GitHub
commit 83b1ace561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 23 deletions

View File

@ -37,7 +37,7 @@
<div class="heading"> <div class="heading">
{#if !showFieldView} {#if !showFieldView}
<i class="ri-list-settings-line button--toggled" /> <i class="ri-list-settings-line button--toggled" />
<h3 class="budibase__title--3">Create / Edit Model</h3> <h3 class="budibase__title--3">Create / Edit Table</h3>
{:else} {:else}
<i class="ri-file-list-line button--toggled" /> <i class="ri-file-list-line button--toggled" />
<h3 class="budibase__title--3">Create / Edit Field</h3> <h3 class="budibase__title--3">Create / Edit Field</h3>

View File

@ -19,19 +19,19 @@
...rest, ...rest,
}, },
}) })
notifier.success(`${model.name} model created.`) notifier.success(`${model.name} table created.`)
} }
</script> </script>
<section transition:fade> <section transition:fade>
<header> <header>
<h2>Create New Model</h2> <h2>Create New Table</h2>
<p>Before you can view your model, you need to set it up.</p> <p>Before you can view your table, you need to set it up.</p>
</header> </header>
<div class="block-row"> <div class="block-row">
<span class="block-row-title">Fields</span> <span class="block-row-title">Fields</span>
<p>Blocks are pre-made fields and help you build your model quicker.</p> <p>Blocks are pre-made fields and help you build your table quicker.</p>
<div class="blocks"> <div class="blocks">
{#each Object.values(FIELDS) as field} {#each Object.values(FIELDS) as field}
<Block <Block
@ -45,7 +45,7 @@
<div class="block-row"> <div class="block-row">
<span class="block-row-title">Blocks</span> <span class="block-row-title">Blocks</span>
<p>Blocks are pre-made fields and help you build your model quicker.</p> <p>Blocks are pre-made fields and help you build your table quicker.</p>
<div class="blocks"> <div class="blocks">
{#each Object.values(BLOCKS) as field} {#each Object.values(BLOCKS) as field}
<Block <Block
@ -58,8 +58,8 @@
</div> </div>
<div class="block-row"> <div class="block-row">
<span class="block-row-title">Models</span> <span class="block-row-title">Tables</span>
<p>Blocks are pre-made fields and help you build your model quicker.</p> <p>Blocks are pre-made fields and help you build your table quicker.</p>
<div class="blocks"> <div class="blocks">
{#each Object.values(MODELS) as model} {#each Object.values(MODELS) as model}
<Block <Block

View File

@ -53,7 +53,7 @@
bind:value={$backendUiStore.tabs.NAVIGATION_PANEL}> bind:value={$backendUiStore.tabs.NAVIGATION_PANEL}>
{#if selectedTab === 'NAVIGATE'} {#if selectedTab === 'NAVIGATE'}
<Button purple wide on:click={setupForNewModel}> <Button purple wide on:click={setupForNewModel}>
Create New Model Create New Table
</Button> </Button>
<div class="hierarchy-items-container"> <div class="hierarchy-items-container">
{#each $backendUiStore.models as model} {#each $backendUiStore.models as model}

View File

@ -52,7 +52,35 @@
}) })
} }
function validate() {
let errors = []
for (let field of Object.values($backendUiStore.draftModel.schema)) {
const restrictedFieldNames = ["type", "modelId"]
if (field.name.startsWith("_")) {
errors.push(`field '${field.name}' - name cannot begin with '_''`)
} else if (restrictedFieldNames.includes(field.name)) {
errors.push(`field '${field.name}' - is a restricted name, please rename`)
} else if (!field.name || !field.name.trim()) {
errors.push("field name cannot be blank")
}
}
if (!$backendUiStore.draftModel.name) {
errors.push("Table name cannot be blank")
}
return errors
}
async function saveModel() { async function saveModel() {
const errors = validate()
if (errors.length > 0) {
notifier.danger(
errors.join("/n")
)
return
}
await backendUiStore.actions.models.save({ await backendUiStore.actions.models.save({
model: $backendUiStore.draftModel, model: $backendUiStore.draftModel,
}) })

View File

@ -313,7 +313,7 @@ export default {
icon: "ri-archive-drawer-fill", icon: "ri-archive-drawer-fill",
properties: { properties: {
design: { ...all }, design: { ...all },
settings: [{ label: "Model", key: "model", control: ModelSelect }], settings: [{ label: "Table", key: "model", control: ModelSelect }],
}, },
children: [], children: [],
}, },
@ -331,7 +331,7 @@ export default {
design: { ...all }, design: { ...all },
settings: [ settings: [
{ {
label: "Model", label: "Table",
key: "model", key: "model",
control: ModelSelect, control: ModelSelect,
}, },
@ -351,7 +351,7 @@ export default {
design: { ...all }, design: { ...all },
settings: [ settings: [
{ {
label: "Model", label: "Table",
key: "model", key: "model",
control: ModelSelect, control: ModelSelect,
}, },
@ -368,7 +368,7 @@ export default {
properties: { properties: {
design: { ...all }, design: { ...all },
settings: [ settings: [
{ label: "Model", key: "model", control: ModelSelect }, { label: "Table", key: "model", control: ModelSelect },
{ {
label: "Chart Type", label: "Chart Type",
key: "type", key: "type",
@ -399,18 +399,18 @@ export default {
icon: "ri-file-list-fill", icon: "ri-file-list-fill",
properties: { properties: {
design: { ...all }, design: { ...all },
settings: [{ label: "Model", key: "model", control: ModelSelect }], settings: [{ label: "Table", key: "model", control: ModelSelect }],
}, },
children: [], children: [],
}, },
{ {
name: "List", name: "List",
_component: "@budibase/standard-components/list", _component: "@budibase/standard-components/list",
description: "Renders all children once per record, of a given model", description: "Renders all children once per record, of a given table",
icon: "ri-file-list-fill", icon: "ri-file-list-fill",
properties: { properties: {
design: { ...all }, design: { ...all },
settings: [{ label: "Model", key: "model", control: ModelSelect }], settings: [{ label: "Table", key: "model", control: ModelSelect }],
}, },
children: [], children: [],
}, },
@ -422,7 +422,7 @@ export default {
icon: "ri-profile-line", icon: "ri-profile-line",
properties: { properties: {
design: { ...all }, design: { ...all },
settings: [{ label: "Model", key: "model", control: ModelSelect }], settings: [{ label: "Table", key: "model", control: ModelSelect }],
}, },
children: [], children: [],
}, },

View File

@ -28,7 +28,7 @@
{:else if $backendUiStore.selectedDatabase._id && selectedModel.name} {:else if $backendUiStore.selectedDatabase._id && selectedModel.name}
<ModelDataTable /> <ModelDataTable />
{:else} {:else}
<i style="color: var(--grey-4)">create your first model to start building</i> <i style="color: var(--grey-4)">create your first table to start building</i>
{/if} {/if}
<style> <style>

View File

@ -22,5 +22,5 @@
</script> </script>
{#if $backendUiStore.models.length === 0} {#if $backendUiStore.models.length === 0}
Please create a model Please create a table
{:else}Please select a model{/if} {:else}Please select a table{/if}

View File

@ -196,21 +196,21 @@
} }
}, },
"datatable": { "datatable": {
"description": "an HTML table that fetches data from a model or view and displays it.", "description": "an HTML table that fetches data from a table or view and displays it.",
"data": true, "data": true,
"props": { "props": {
"model": "models" "model": "models"
} }
}, },
"dataform": { "dataform": {
"description": "an HTML table that fetches data from a model or view and displays it.", "description": "an HTML table that fetches data from a table or view and displays it.",
"data": true, "data": true,
"props": { "props": {
"model": "models" "model": "models"
} }
}, },
"dataformwide": { "dataformwide": {
"description": "an HTML table that fetches data from a model or view and displays it.", "description": "an HTML table that fetches data from a table or view and displays it.",
"data": true, "data": true,
"props": { "props": {
"model": "models" "model": "models"