-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathConnectorFormWrapper.svelte
More file actions
43 lines (39 loc) · 1.55 KB
/
Copy pathConnectorFormWrapper.svelte
File metadata and controls
43 lines (39 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<script lang="ts">
import type { CreateConnectorStep } from "@rilldata/web-common/features/add-data/manager/steps/types.ts";
import { connectorFormCache } from "@rilldata/web-common/features/add-data/manager/steps/connector.ts";
import { onMount } from "svelte";
import ConnectorForm from "@rilldata/web-common/features/add-data/form/ConnectorForm.svelte";
import type { AddDataStateManager } from "@rilldata/web-common/features/add-data/manager/AddDataStateManager.svelte.ts";
// Wrapper to initialize the ConnectorForm with cached data.
// Has async logic to fetch the .env file. So to ensure we load the form on init, we use this wrapper.
export let stateManager: AddDataStateManager;
export let step: CreateConnectorStep;
export let onSubmit: (
connectorName: string,
connectorFormValues: Record<string, unknown>,
) => void;
export let onBack: () => void;
export let onClose: () => void;
let connectorName: string | null = null;
let cachedEnvBlob: string | null = null;
let cachedFormValues: Record<string, unknown> | null = null;
onMount(async () => {
const { name, formValues, existingEnvBlob } =
await connectorFormCache.getOrCreate(step.schema, step.connectorId);
connectorName = name;
cachedEnvBlob = existingEnvBlob;
cachedFormValues = formValues;
});
</script>
{#if connectorName != null && cachedEnvBlob != null && cachedFormValues != null}
<ConnectorForm
{stateManager}
{step}
{onSubmit}
{onBack}
{onClose}
{connectorName}
{cachedFormValues}
{cachedEnvBlob}
/>
{/if}