prevent duplicate table names
This commit is contained in:
parent
06fef5334e
commit
78aae99e39
|
@ -65,16 +65,18 @@
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<Input label="Name" thin bind:value={field.name} />
|
<Input label="Name" thin bind:value={field.name} />
|
||||||
|
|
||||||
<Select
|
{#if !originalName}
|
||||||
secondary
|
<Select
|
||||||
thin
|
secondary
|
||||||
label="Type"
|
thin
|
||||||
on:change={handleFieldConstraints}
|
label="Type"
|
||||||
bind:value={field.type}>
|
on:change={handleFieldConstraints}
|
||||||
{#each Object.values(fieldDefinitions) as field}
|
bind:value={field.type}>
|
||||||
<option value={field.type}>{field.name}</option>
|
{#each Object.values(fieldDefinitions) as field}
|
||||||
{/each}
|
<option value={field.type}>{field.name}</option>
|
||||||
</Select>
|
{/each}
|
||||||
|
</Select>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if field.type !== 'link'}
|
{#if field.type !== 'link'}
|
||||||
<Toggle
|
<Toggle
|
||||||
|
|
|
@ -20,10 +20,21 @@
|
||||||
let modal
|
let modal
|
||||||
let name
|
let name
|
||||||
let dataImport
|
let dataImport
|
||||||
|
let error = ""
|
||||||
|
|
||||||
function resetState() {
|
function resetState() {
|
||||||
name = ""
|
name = ""
|
||||||
dataImport = undefined
|
dataImport = undefined
|
||||||
|
error = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkValid(evt) {
|
||||||
|
const tableName = evt.target.value
|
||||||
|
if ($backendUiStore.models.some(model => model.name === tableName)) {
|
||||||
|
error = `Table with name ${tableName} already exists. Please choose another name.`
|
||||||
|
return
|
||||||
|
}
|
||||||
|
error = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveTable() {
|
async function saveTable() {
|
||||||
|
@ -61,12 +72,14 @@
|
||||||
title="Create Table"
|
title="Create Table"
|
||||||
confirmText="Create"
|
confirmText="Create"
|
||||||
onConfirm={saveTable}
|
onConfirm={saveTable}
|
||||||
disabled={!name || (dataImport && !dataImport.valid)}>
|
disabled={error || !name || (dataImport && !dataImport.valid)}>
|
||||||
<Input
|
<Input
|
||||||
data-cy="table-name-input"
|
data-cy="table-name-input"
|
||||||
thin
|
thin
|
||||||
label="Table Name"
|
label="Table Name"
|
||||||
bind:value={name} />
|
on:input={checkValid}
|
||||||
|
bind:value={name}
|
||||||
|
{error} />
|
||||||
<div>
|
<div>
|
||||||
<Label grey extraSmall>Create Table from CSV (Optional)</Label>
|
<Label grey extraSmall>Create Table from CSV (Optional)</Label>
|
||||||
<TableDataImport bind:dataImport />
|
<TableDataImport bind:dataImport />
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
let dropdown
|
let dropdown
|
||||||
let editing
|
let editing
|
||||||
let confirmDeleteDialog
|
let confirmDeleteDialog
|
||||||
|
let error = ""
|
||||||
|
let originalName = table.name
|
||||||
|
|
||||||
$: fields = Object.keys(table.schema)
|
$: fields = Object.keys(table.schema)
|
||||||
|
|
||||||
|
@ -39,6 +41,15 @@
|
||||||
notifier.success("Table renamed successfully")
|
notifier.success("Table renamed successfully")
|
||||||
hideEditor()
|
hideEditor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkValid(evt) {
|
||||||
|
const tableName = evt.target.value
|
||||||
|
if (originalName !== tableName && $backendUiStore.models.some(model => model.name === tableName)) {
|
||||||
|
error = `Table with name ${tableName} already exists. Please choose another name.`
|
||||||
|
return
|
||||||
|
}
|
||||||
|
error = ""
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div bind:this={anchor} class="icon" on:click={dropdown.show}>
|
<div bind:this={anchor} class="icon" on:click={dropdown.show}>
|
||||||
|
@ -48,7 +59,11 @@
|
||||||
{#if editing}
|
{#if editing}
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<h5>Edit Table</h5>
|
<h5>Edit Table</h5>
|
||||||
<Input label="Table Name" thin bind:value={table.name} />
|
<Input
|
||||||
|
label="Table Name" thin bind:value={table.name}
|
||||||
|
on:input={checkValid}
|
||||||
|
{error}
|
||||||
|
/>
|
||||||
<Select
|
<Select
|
||||||
label="Primary Display Column"
|
label="Primary Display Column"
|
||||||
thin
|
thin
|
||||||
|
@ -61,7 +76,7 @@
|
||||||
</Select>
|
</Select>
|
||||||
<footer>
|
<footer>
|
||||||
<Button secondary on:click={hideEditor}>Cancel</Button>
|
<Button secondary on:click={hideEditor}>Cancel</Button>
|
||||||
<Button primary on:click={save}>Save</Button>
|
<Button primary disabled={error} on:click={save}>Save</Button>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|
|
@ -36,10 +36,14 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<nav use:cssVars={cssVariables}>
|
<nav use:cssVars={cssVariables}>
|
||||||
<a href="/">
|
{#if logoUrl}
|
||||||
<img class="logo" alt="logo" src={logoUrl} height="48" />
|
<a href="/">
|
||||||
<span>{title}</span>
|
<img class="logo" alt="logo" src={logoUrl} height="48" />
|
||||||
</a>
|
<span>{title}</span>
|
||||||
|
</a>
|
||||||
|
{:else}
|
||||||
|
<div />
|
||||||
|
{/if}
|
||||||
<div class="menu-items" bind:this={itemContainer} />
|
<div class="menu-items" bind:this={itemContainer} />
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue