forked from tsai/budibase
committed by
GitHub
22 changed files with 279 additions and 74 deletions
@ -0,0 +1,15 @@ |
|||||
|
<script> |
||||
|
import { ActionButton, Modal } from "@budibase/bbui" |
||||
|
import ImportModal from "../modals/ImportModal.svelte" |
||||
|
|
||||
|
export let tableId |
||||
|
|
||||
|
let modal |
||||
|
</script> |
||||
|
|
||||
|
<ActionButton icon="DataUpload" size="S" quiet on:click={modal.show}> |
||||
|
Import |
||||
|
</ActionButton> |
||||
|
<Modal bind:this={modal}> |
||||
|
<ImportModal {tableId} on:updaterows /> |
||||
|
</Modal> |
||||
@ -0,0 +1,43 @@ |
|||||
|
<script> |
||||
|
import { ModalContent, Label, notifications, Body } from "@budibase/bbui" |
||||
|
import TableDataImport from "../../TableNavigator/TableDataImport.svelte" |
||||
|
import api from "builderStore/api" |
||||
|
import { createEventDispatcher } from "svelte" |
||||
|
|
||||
|
const dispatch = createEventDispatcher() |
||||
|
|
||||
|
export let tableId |
||||
|
let dataImport |
||||
|
|
||||
|
$: valid = dataImport?.csvString != null && dataImport?.valid |
||||
|
|
||||
|
async function importData() { |
||||
|
const response = await api.post(`/api/tables/${tableId}/import`, { |
||||
|
dataImport, |
||||
|
}) |
||||
|
if (response.status !== 200) { |
||||
|
const error = await response.text() |
||||
|
notifications.error(`Unable to import data - ${error}`) |
||||
|
} else { |
||||
|
notifications.success("Rows successfully imported.") |
||||
|
} |
||||
|
dispatch("updaterows") |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<ModalContent |
||||
|
title="Import Data" |
||||
|
confirmText="Import" |
||||
|
onConfirm={importData} |
||||
|
disabled={!valid} |
||||
|
> |
||||
|
<Body |
||||
|
>Import rows to an existing table from a CSV. Only columns from the CSV |
||||
|
which exist in the table will be imported.</Body |
||||
|
> |
||||
|
<Label grey extraSmall>CSV to import</Label> |
||||
|
<TableDataImport bind:dataImport bind:existingTableId={tableId} /> |
||||
|
</ModalContent> |
||||
|
|
||||
|
<style> |
||||
|
</style> |
||||
Loading…
Reference in new issue