|
|
@ -2,8 +2,7 @@ |
|
|
import { goto } from "@sveltech/routify" |
|
|
import { goto } from "@sveltech/routify" |
|
|
import { backendUiStore, store } from "builderStore" |
|
|
import { backendUiStore, store } from "builderStore" |
|
|
import { notifier } from "builderStore/store/notifications" |
|
|
import { notifier } from "builderStore/store/notifications" |
|
|
import { Button, Input, Label, ModalContent, Modal } from "@budibase/bbui" |
|
|
import { Input, Label, ModalContent } from "@budibase/bbui" |
|
|
import Spinner from "components/common/Spinner.svelte" |
|
|
|
|
|
import TableDataImport from "../TableDataImport.svelte" |
|
|
import TableDataImport from "../TableDataImport.svelte" |
|
|
import analytics from "analytics" |
|
|
import analytics from "analytics" |
|
|
import screenTemplates from "builderStore/store/screenTemplates" |
|
|
import screenTemplates from "builderStore/store/screenTemplates" |
|
|
@ -22,15 +21,9 @@ |
|
|
let dataImport |
|
|
let dataImport |
|
|
let error = "" |
|
|
let error = "" |
|
|
|
|
|
|
|
|
function resetState() { |
|
|
|
|
|
name = "" |
|
|
|
|
|
dataImport = undefined |
|
|
|
|
|
error = "" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function checkValid(evt) { |
|
|
function checkValid(evt) { |
|
|
const tableName = evt.target.value |
|
|
const tableName = evt.target.value |
|
|
if ($backendUiStore.models?.some(model => model.name === tableName)) { |
|
|
if ($backendUiStore.models?.some((model) => model.name === tableName)) { |
|
|
error = `Table with name ${tableName} already exists. Please choose another name.` |
|
|
error = `Table with name ${tableName} already exists. Please choose another name.` |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
@ -56,8 +49,8 @@ |
|
|
|
|
|
|
|
|
// Create auto screens |
|
|
// Create auto screens |
|
|
const screens = screenTemplates($store, [table]) |
|
|
const screens = screenTemplates($store, [table]) |
|
|
.filter(template => defaultScreens.includes(template.id)) |
|
|
.filter((template) => defaultScreens.includes(template.id)) |
|
|
.map(template => template.create()) |
|
|
.map((template) => template.create()) |
|
|
for (let screen of screens) { |
|
|
for (let screen of screens) { |
|
|
// Record the table that created this screen so we can link it later |
|
|
// Record the table that created this screen so we can link it later |
|
|
screen.autoTableId = table._id |
|
|
screen.autoTableId = table._id |
|
|
@ -74,7 +67,7 @@ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Create autolink to newly created list page |
|
|
// Create autolink to newly created list page |
|
|
const listPage = screens.find(screen => |
|
|
const listPage = screens.find((screen) => |
|
|
screen.props._instanceName.endsWith("List") |
|
|
screen.props._instanceName.endsWith("List") |
|
|
) |
|
|
) |
|
|
await store.createLink(listPage.route, table.name) |
|
|
await store.createLink(listPage.route, table.name) |
|
|
@ -84,23 +77,20 @@ |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
<Button primary wide on:click={modal.show}>Create New Table</Button> |
|
|
<ModalContent |
|
|
<Modal bind:this={modal} on:hide={resetState}> |
|
|
title="Create Table" |
|
|
<ModalContent |
|
|
confirmText="Create" |
|
|
title="Create Table" |
|
|
onConfirm={saveTable} |
|
|
confirmText="Create" |
|
|
disabled={error || !name || (dataImport && !dataImport.valid)}> |
|
|
onConfirm={saveTable} |
|
|
<Input |
|
|
disabled={error || !name || (dataImport && !dataImport.valid)}> |
|
|
data-cy="table-name-input" |
|
|
<Input |
|
|
thin |
|
|
data-cy="table-name-input" |
|
|
label="Table Name" |
|
|
thin |
|
|
on:input={checkValid} |
|
|
label="Table Name" |
|
|
bind:value={name} |
|
|
on:input={checkValid} |
|
|
{error} /> |
|
|
bind:value={name} |
|
|
<div> |
|
|
{error} /> |
|
|
<Label grey extraSmall>Create Table from CSV (Optional)</Label> |
|
|
<div> |
|
|
<TableDataImport bind:dataImport /> |
|
|
<Label grey extraSmall>Create Table from CSV (Optional)</Label> |
|
|
</div> |
|
|
<TableDataImport bind:dataImport /> |
|
|
</ModalContent> |
|
|
</div> |
|
|
|
|
|
</ModalContent> |
|
|
|
|
|
</Modal> |
|
|
|
|
|
|