1
0
Fork 0
mirror of synced 2024-09-21 03:43:21 +12:00
budibase/packages/builder/src/components/integration/index.svelte

199 lines
4.9 KiB
Svelte
Raw Normal View History

2020-12-19 07:19:43 +13:00
<script>
2021-01-15 09:51:03 +13:00
import Editor from "./QueryEditor.svelte"
2021-01-14 03:11:53 +13:00
import FieldsBuilder from "./QueryFieldsBuilder.svelte"
2022-08-26 04:30:47 +12:00
import {
Label,
Input,
Divider,
Layout,
Icon,
Button,
ActionButton,
} from "@budibase/bbui"
2021-01-07 01:28:51 +13:00
2020-12-19 07:19:43 +13:00
const QueryTypes = {
SQL: "sql",
2021-01-12 10:01:21 +13:00
JSON: "json",
FIELDS: "fields",
2022-08-26 04:30:47 +12:00
FLOW: "flow",
2020-12-19 07:19:43 +13:00
}
export let query
2021-02-19 07:55:08 +13:00
export let datasource
2021-01-14 03:11:53 +13:00
export let schema
2021-01-15 03:22:24 +13:00
export let editable = true
export let height = 500
2021-01-12 06:18:22 +13:00
2021-02-20 03:31:07 +13:00
$: urlDisplay =
schema.urlDisplay &&
`${datasource.config.url}${
query.fields.path ? "/" + query.fields.path : ""
}${query.fields.queryString ? "?" + query.fields.queryString : ""}`
2021-02-19 07:55:08 +13:00
2021-01-12 06:18:22 +13:00
function updateQuery({ detail }) {
2021-01-14 05:39:47 +13:00
query.fields[schema.type] = detail.value
2021-01-12 06:18:22 +13:00
}
2020-12-19 07:19:43 +13:00
</script>
2021-01-14 05:39:47 +13:00
{#if schema}
2021-01-19 04:37:32 +13:00
{#key query._id}
{#if schema.type === QueryTypes.SQL}
<Editor
editorHeight={height}
2021-01-19 04:37:32 +13:00
label="Query"
mode="sql"
on:change={updateQuery}
readOnly={!editable}
2021-02-02 00:51:53 +13:00
value={query.fields.sql}
parameters={query.parameters}
/>
2021-01-19 04:37:32 +13:00
{:else if schema.type === QueryTypes.JSON}
<Editor
editorHeight={height}
2021-01-19 04:37:32 +13:00
label="Query"
mode="json"
on:change={updateQuery}
readOnly={!editable}
2021-02-02 00:51:53 +13:00
value={query.fields.json}
parameters={query.parameters}
/>
2021-01-19 04:37:32 +13:00
{:else if schema.type === QueryTypes.FIELDS}
<FieldsBuilder bind:fields={query.fields} {schema} {editable} />
2021-02-19 07:55:08 +13:00
{#if schema.urlDisplay}
<div class="url-row">
<Label small>URL</Label>
<Input thin outline disabled value={urlDisplay} />
</div>
{/if}
2022-08-26 04:30:47 +12:00
{:else if schema.type === QueryTypes.FLOW}
<br />
{#if !query.fields.steps}
<div class="controls">
<Button
secondary
slot="buttons"
on:click={() => {
query.fields.steps = [
{
key: "$match",
value: "{\n\t\n}",
},
]
}}>Add stage</Button
>
</div>
<br />
{:else}
{#each query.fields.steps as step, index}
<div class="block">
<div class="subblock">
<Divider noMargin />
<div class="blockSection">
<div class="block-options">
Stage {index + 1}
<ActionButton on:click={() => {}} icon="DeleteOutline" />
</div>
<Layout noPadding gap="S">
<div class="fields">
<div class="block-field">
<Input
value={step.key}
on:change={({ detail }) => {
query.fields.steps[index].key = detail
}}
/>
<Editor
editorHeight={height / 2}
mode="json"
value={step.value}
on:change={({ detail }) => {
query.fields.steps[index].value = detail
}}
/>
</div>
</div>
</Layout>
</div>
</div>
<div class="separator" />
{#if index === query.fields.steps.length - 1}
<Icon
hoverable
name="AddCircle"
size="S"
on:click={() => {
query.fields.steps = [
...query.fields.steps,
{
key: "$match",
value: "{\n\t\n}",
},
]
}}
/>
<br />
{/if}
</div>
{/each}
{/if}
2021-01-19 04:37:32 +13:00
{/if}
{/key}
2021-01-12 23:28:41 +13:00
{/if}
2021-02-19 07:55:08 +13:00
<style>
2021-02-20 03:31:07 +13:00
.url-row {
display: grid;
grid-template-columns: 20% 1fr;
grid-gap: var(--spacing-l);
align-items: center;
}
2022-08-26 04:30:47 +12:00
.blockSection {
padding: var(--spacing-xl);
}
.block {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
margin-top: -6px;
}
.subblock {
width: 480px;
font-size: 16px;
background-color: var(--background);
border: 1px solid var(--spectrum-global-color-gray-300);
border-radius: 4px 4px 4px 4px;
}
.block-options {
justify-content: space-between;
display: flex;
align-items: center;
padding-bottom: 24px;
}
.fields {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
gap: var(--spacing-s);
}
.block-field {
display: grid;
grid-gap: 5px;
}
.separator {
width: 1px;
height: 25px;
border-left: 1px dashed var(--grey-4);
color: var(--grey-4);
/* center horizontally */
align-self: center;
}
.controls {
display: flex;
align-items: center;
justify-content: right;
}
2021-02-19 07:55:08 +13:00
</style>