diff --git a/packages/builder/src/components/nav/ModelNavigator/CreateTable.svelte b/packages/builder/src/components/nav/ModelNavigator/CreateTable.svelte
index 3c05b0de00..705da1365c 100644
--- a/packages/builder/src/components/nav/ModelNavigator/CreateTable.svelte
+++ b/packages/builder/src/components/nav/ModelNavigator/CreateTable.svelte
@@ -2,19 +2,28 @@
import { goto } from "@sveltech/routify"
import { backendUiStore } from "builderStore"
import { notifier } from "builderStore/store/notifications"
- import { DropdownMenu, Button, Icon, Input, Select } from "@budibase/bbui"
+ import {
+ DropdownMenu,
+ Button,
+ Heading,
+ Icon,
+ Input,
+ Select,
+ Dropzone,
+ } from "@budibase/bbui"
+ import api from "builderStore/api"
import analytics from "analytics"
- export let table
-
let anchor
let dropdown
let name
+ let recordImport = {}
async function saveTable() {
const model = await backendUiStore.actions.models.save({
name,
- schema: {},
+ schema: recordImport.schema || {},
+ recordImport,
})
notifier.success(`Table ${name} created successfully.`)
$goto(`./model/${model._id}`)
@@ -27,6 +36,38 @@
name = ""
dropdown.hide()
}
+
+ function handleFileTooLarge(fileSizeLimit) {
+ notifier.danger(
+ `Files cannot exceed ${fileSizeLimit /
+ BYTES_IN_MB}MB. Please try again with smaller files.`
+ )
+ }
+
+ async function processFiles(fileList) {
+ const fileArray = Array.from(fileList)
+ let data = new FormData()
+ for (var i = 0; i < fileList.length; i++) {
+ data.append("file", fileList[i])
+ }
+
+ const response = await fetch("/api/csv/validate", {
+ method: "POST",
+ body: data,
+ headers: {
+ Accept: "application/json",
+ },
+ })
+
+ recordImport = await response.json()
+
+ if (response.status !== 200) {
+ notifier.danger("CSV Invalid, please try another CSV file")
+ return []
+ }
+
+ return fileArray.map(file => ({ ...file, extension: "csv" }))
+ }
@@ -40,6 +81,9 @@
placeholder="Table Name"
thin
bind:value={name} />
+
+ Create Table from CSV (Optional)
+