Fix datasource selection after import and add maxmimum files support to dropzone

This commit is contained in:
Rory Powell 2021-12-02 16:51:13 +00:00
parent cadd3cf259
commit 9d5866e747
3 changed files with 130 additions and 117 deletions

View File

@ -21,6 +21,7 @@
export let gallery = true export let gallery = true
export let error = null export let error = null
export let fileTags = [] export let fileTags = []
export let maximum = null
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const imageExtensions = [ const imageExtensions = [
@ -187,6 +188,7 @@
{/each} {/each}
{/if} {/if}
{/if} {/if}
{#if !maximum || (maximum && value?.length < maximum)}
<div <div
class="spectrum-Dropzone" class="spectrum-Dropzone"
class:is-invalid={!!error} class:is-invalid={!!error}
@ -297,6 +299,7 @@
{/if} {/if}
</div> </div>
</div> </div>
{/if}
</div> </div>
<style> <style>

View File

@ -13,6 +13,7 @@
export let handleFileTooLarge = undefined export let handleFileTooLarge = undefined
export let gallery = true export let gallery = true
export let fileTags = [] export let fileTags = []
export let maximum = undefined
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = e => {
@ -31,6 +32,7 @@
{handleFileTooLarge} {handleFileTooLarge}
{gallery} {gallery}
{fileTags} {fileTags}
{maximum}
on:change={onChange} on:change={onChange}
/> />
</Field> </Field>

View File

@ -14,16 +14,17 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import analytics, { Events } from "analytics" import analytics, { Events } from "analytics"
import { datasources, queries } from "stores/backend" import { datasources, queries } from "stores/backend"
import { writable } from "svelte/store"
export let modal export let modal
export let datasourceId export let datasourceId
export let createDatasource = false export let createDatasource = false
let data = { const data = writable({
url: "", url: "",
raw: "", raw: "",
file: "", file: undefined,
} })
let lastTouched = "url" let lastTouched = "url"
@ -32,12 +33,12 @@
// parse the file into memory and send as string // parse the file into memory and send as string
if (lastTouched === "file") { if (lastTouched === "file") {
dataString = await data.file[0].text() dataString = await $data.file.text()
} else if (lastTouched === "url") { } else if (lastTouched === "url") {
const response = await fetch(data.url) const response = await fetch($data.url)
dataString = await response.text() dataString = await response.text()
} else if (lastTouched === "raw") { } else if (lastTouched === "raw") {
dataString = data.raw dataString = $data.raw
} }
return dataString return dataString
@ -56,7 +57,10 @@
datasourceId, datasourceId,
} }
await queries.import(body) const importResult = await queries.import(body)
if (!datasourceId) {
datasourceId = importResult.datasourceId
}
// reload // reload
await datasources.fetch() await datasources.fetch()
@ -93,7 +97,7 @@
<Tabs selected="Link"> <Tabs selected="Link">
<Tab title="Link"> <Tab title="Link">
<Input <Input
bind:value={data.url} bind:value={$data.url}
on:change={() => (lastTouched = "url")} on:change={() => (lastTouched = "url")}
label="Enter a URL" label="Enter a URL"
placeholder="e.g. https://petstore.swagger.io/v2/swagger.json" placeholder="e.g. https://petstore.swagger.io/v2/swagger.json"
@ -102,14 +106,18 @@
<Tab title="File"> <Tab title="File">
<Dropzone <Dropzone
gallery={false} gallery={false}
bind:value={data.file} value={$data.file ? [$data.file] : []}
on:change={() => (lastTouched = "file")} on:change={e => {
$data.file = e.detail?.[0]
lastTouched = "file"
}}
fileTags={["OpenAPI 2.0", "Swagger 2.0", "cURL", "YAML", "JSON"]} fileTags={["OpenAPI 2.0", "Swagger 2.0", "cURL", "YAML", "JSON"]}
maximum={1}
/> />
</Tab> </Tab>
<Tab title="Raw Text"> <Tab title="Raw Text">
<TextArea <TextArea
bind:value={data.raw} bind:value={$data.raw}
on:change={() => (lastTouched = "raw")} on:change={() => (lastTouched = "raw")}
label={"Paste raw text"} label={"Paste raw text"}
placeholder={'e.g. curl --location --request GET "https://example.com"'} placeholder={'e.g. curl --location --request GET "https://example.com"'}