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