Add toggle to make autoscreens optional

This commit is contained in:
Andrew Kingston 2021-01-06 16:03:00 +00:00
parent 239f27ccee
commit ff93d30608
1 changed files with 24 additions and 18 deletions

View File

@ -1,8 +1,8 @@
<script> <script>
import { goto, params } 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 { Input, Label, ModalContent } from "@budibase/bbui" import { Input, Label, ModalContent, Toggle } from "@budibase/bbui"
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"
@ -20,6 +20,7 @@
let name let name
let dataImport let dataImport
let error = "" let error = ""
let createAutoscreens = true
function checkValid(evt) { function checkValid(evt) {
const tableName = evt.target.value const tableName = evt.target.value
@ -48,23 +49,25 @@
analytics.captureEvent("Table Created", { name }) analytics.captureEvent("Table Created", { name })
// Create auto screens // Create auto screens
const screens = screenTemplates($store, [table]) if (createAutoscreens) {
.filter(template => defaultScreens.includes(template.id)) const screens = screenTemplates($store, [table])
.map(template => template.create()) .filter(template => defaultScreens.includes(template.id))
for (let screen of screens) { .map(template => template.create())
// Record the table that created this screen so we can link it later for (let screen of screens) {
screen.autoTableId = table._id // Record the table that created this screen so we can link it later
await store.actions.screens.create(screen) screen.autoTableId = table._id
} await store.actions.screens.create(screen)
}
// Create autolink to newly created list screen // Create autolink to newly created list screen
const listScreen = screens.find(screen => const listScreen = screens.find(screen =>
screen.props._instanceName.endsWith("List") screen.props._instanceName.endsWith("List")
) )
await store.actions.components.links.save( await store.actions.components.links.save(
listScreen.routing.route, listScreen.routing.route,
table.name table.name
) )
}
// Navigate to new table // Navigate to new table
$goto(`./table/${table._id}`) $goto(`./table/${table._id}`)
@ -83,6 +86,9 @@
on:input={checkValid} on:input={checkValid}
bind:value={name} bind:value={name}
{error} /> {error} />
<Toggle
text="Create screens to view and edit items in this table"
bind:checked={createAutoscreens} />
<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 />