Add import to existing DS and add cookie support to curl import
This commit is contained in:
parent
409f799c3e
commit
5d1efb3024
|
@ -80,7 +80,11 @@
|
|||
|
||||
<Modal bind:this={importModal}>
|
||||
{#if integration.type === "REST"}
|
||||
<ImportRestQueriesModal {integration} {modal} createDatasource={true} />
|
||||
<ImportRestQueriesModal
|
||||
navigateDatasource={true}
|
||||
createDatasource={true}
|
||||
onCancel={() => modal.show()}
|
||||
/>
|
||||
{/if}
|
||||
</Modal>
|
||||
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
import { datasources, queries } from "stores/backend"
|
||||
import { writable } from "svelte/store"
|
||||
|
||||
export let modal
|
||||
export let navigateDatasource = false
|
||||
export let datasourceId
|
||||
export let createDatasource = false
|
||||
export let onCancel
|
||||
|
||||
const data = writable({
|
||||
url: "",
|
||||
|
@ -67,7 +68,10 @@
|
|||
await queries.fetch()
|
||||
await datasources.select(datasourceId)
|
||||
|
||||
$goto(`./datasource/${datasourceId}`)
|
||||
if (navigateDatasource) {
|
||||
$goto(`./datasource/${datasourceId}`)
|
||||
}
|
||||
|
||||
notifications.success(`Imported successfully.`)
|
||||
analytics.captureEvent(Events.QUERIES.REST.IMPORTED, {
|
||||
importType: lastTouched,
|
||||
|
@ -84,7 +88,7 @@
|
|||
|
||||
<ModalContent
|
||||
onConfirm={() => importQueries()}
|
||||
onCancel={() => modal.show()}
|
||||
{onCancel}
|
||||
confirmText={"Import"}
|
||||
cancelText="Back"
|
||||
size="L"
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
import CreateExternalTableModal from "./modals/CreateExternalTableModal.svelte"
|
||||
import ICONS from "components/backend/DatasourceNavigator/icons"
|
||||
import { capitalise } from "helpers"
|
||||
import ImportRestQueriesModal from "components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte"
|
||||
|
||||
let importQueriesModal
|
||||
let relationshipModal
|
||||
let createExternalTableModal
|
||||
let selectedFromRelationship, selectedToRelationship
|
||||
|
@ -131,6 +133,15 @@
|
|||
/>
|
||||
</Modal>
|
||||
|
||||
<Modal bind:this={importQueriesModal}>
|
||||
{#if datasource.source === "REST"}
|
||||
<ImportRestQueriesModal
|
||||
createDatasource={false}
|
||||
datasourceId={datasource._id}
|
||||
/>
|
||||
{/if}
|
||||
</Modal>
|
||||
|
||||
<Modal bind:this={createExternalTableModal}>
|
||||
<CreateExternalTableModal {datasource} />
|
||||
</Modal>
|
||||
|
@ -246,7 +257,14 @@
|
|||
<Divider />
|
||||
<div class="query-header">
|
||||
<Heading size="S">Queries</Heading>
|
||||
<Button secondary on:click={() => $goto("./new")}>Add Query</Button>
|
||||
<div class="query-buttons">
|
||||
{#if datasource.source === "REST"}
|
||||
<Button secondary on:click={() => importQueriesModal.show()}
|
||||
>Import</Button
|
||||
>
|
||||
{/if}
|
||||
<Button secondary on:click={() => $goto("./new")}>Add Query</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="query-list">
|
||||
{#each $queries.list.filter(query => query.datasourceId === datasource._id) as query}
|
||||
|
@ -293,6 +311,11 @@
|
|||
margin: 0 0 var(--spacing-s) 0;
|
||||
}
|
||||
|
||||
.query-buttons {
|
||||
display: flex;
|
||||
gap: var(--spacing-l);
|
||||
}
|
||||
|
||||
.query-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
|
|
@ -27,6 +27,17 @@ const parseBody = (curl: any) => {
|
|||
return undefined
|
||||
}
|
||||
|
||||
const parseCookie = (curl: any) => {
|
||||
if (curl.cookies){
|
||||
return Object.entries(curl.cookies).reduce((acc, entry) => {
|
||||
const [key, value] = entry
|
||||
return acc + `${key}=${value}; `
|
||||
}, "")
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Curl
|
||||
* https://curl.se/docs/manpage.html
|
||||
|
@ -61,6 +72,11 @@ export class Curl extends ImportSource {
|
|||
const headers = this.curl.headers
|
||||
const requestBody = parseBody(this.curl)
|
||||
|
||||
const cookieHeader = parseCookie(this.curl)
|
||||
if (cookieHeader) {
|
||||
headers["Cookie"] = cookieHeader
|
||||
}
|
||||
|
||||
const query = this.constructQuery(
|
||||
datasourceId,
|
||||
name,
|
||||
|
|
Loading…
Reference in New Issue