Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datasource deletion (when selected) causing builder crash #12091

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@
import PromptQueryModal from "./_components/PromptQueryModal.svelte"
import SettingsPanel from "./_components/panels/Settings.svelte"
import { helpers } from "@budibase/shared-core"
import { goto } from "@roxi/routify"

let selectedPanel = null
let panelOptions = []

// datasources.selected can return null temporarily on datasource deletion
$: datasource = $datasources.selected || {}
$: datasource = $datasources.selected
$: {
if (!datasource) {
$goto("./datasource")
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh I didn't know you could do this! I assumed reactive statements had to be variable assignments. Cool!

Copy link
Member

@aptkingston aptkingston Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can indeed! You can have any arbitrary code inside a reactive statement like this, and svelte will re-run it when any of the variables used inside the statement change. What svelte determines a "change" worth invalidating reactive statements is either a reassignment (if a normal JS variable) or a store value change (if using a svelte store).


$: getOptions(datasource)

const getOptions = datasource => {
if (!datasource) {
return
}
if (datasource.plus) {
// Google Sheets' integration definition specifies `relationships: false` as it doesn't support relationships like other plus datasources
panelOptions =
Expand Down Expand Up @@ -49,51 +58,53 @@

<PromptQueryModal />

<section>
<Layout noPadding>
<Layout gap="XS" noPadding>
<header>
<svelte:component
this={ICONS[datasource.source]}
height="26"
width="26"
/>
<Heading size="M">{$datasources.selected?.name}</Heading>
</header>
</Layout>
<EditDatasourceConfig {datasource} />
<div class="tabs">
<Tabs size="L" noPadding noHorizPadding selected={selectedPanel}>
{#each panelOptions as panelOption}
<Tab
title={panelOption}
on:click={() => (selectedPanel = panelOption)}
{#if datasource}
<section>
<Layout noPadding>
<Layout gap="XS" noPadding>
<header>
<svelte:component
this={ICONS[datasource.source]}
height="26"
width="26"
/>
{/each}
</Tabs>
</div>
<Heading size="M">{$datasources.selected?.name}</Heading>
</header>
</Layout>
<EditDatasourceConfig {datasource} />
<div class="tabs">
<Tabs size="L" noPadding noHorizPadding selected={selectedPanel}>
{#each panelOptions as panelOption}
<Tab
title={panelOption}
on:click={() => (selectedPanel = panelOption)}
/>
{/each}
</Tabs>
</div>

{#if selectedPanel === null}
<Body>loading...</Body>
{:else if selectedPanel === "Tables"}
<TablesPanel {datasource} />
{:else if selectedPanel === "Relationships"}
<RelationshipsPanel {datasource} />
{:else if selectedPanel === "Queries"}
<QueriesPanel {datasource} />
{:else if selectedPanel === "Headers"}
<RestHeadersPanel {datasource} />
{:else if selectedPanel === "Authentication"}
<RestAuthenticationPanel {datasource} />
{:else if selectedPanel === "Variables"}
<RestVariablesPanel {datasource} />
{:else if selectedPanel === "Settings"}
<SettingsPanel {datasource} />
{:else}
<Body>Something went wrong</Body>
{/if}
</Layout>
</section>
{#if selectedPanel === null}
<Body>loading...</Body>
{:else if selectedPanel === "Tables"}
<TablesPanel {datasource} />
{:else if selectedPanel === "Relationships"}
<RelationshipsPanel {datasource} />
{:else if selectedPanel === "Queries"}
<QueriesPanel {datasource} />
{:else if selectedPanel === "Headers"}
<RestHeadersPanel {datasource} />
{:else if selectedPanel === "Authentication"}
<RestAuthenticationPanel {datasource} />
{:else if selectedPanel === "Variables"}
<RestVariablesPanel {datasource} />
{:else if selectedPanel === "Settings"}
<SettingsPanel {datasource} />
{:else}
<Body>Something went wrong</Body>
{/if}
</Layout>
</section>
{/if}

<style>
section {
Expand Down
Loading