Making it so that schema always shows up for future work towards global variables and making it so that tabs selected can be bound to.

This commit is contained in:
mike12345567 2021-12-09 18:41:07 +00:00
parent 6535e61165
commit adbbafbd53
2 changed files with 79 additions and 56 deletions

View File

@ -11,6 +11,8 @@
export let quiet = false export let quiet = false
export let emphasized = false export let emphasized = false
let thisSelected = undefined
let _id = id() let _id = id()
const tab = writable({ title: selected, id: _id, emphasized }) const tab = writable({ title: selected, id: _id, emphasized })
setContext("tab", tab) setContext("tab", tab)
@ -20,9 +22,18 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: { $: {
if ($tab.title !== selected) { if (thisSelected !== selected) {
selected = $tab.title thisSelected = selected
dispatch("select", selected) dispatch("select", thisSelected)
} else if ($tab.title !== thisSelected) {
thisSelected = $tab.title
dispatch("select", thisSelected)
}
if ($tab.title !== thisSelected) {
tab.update(state => {
state.title = thisSelected
return state
})
} }
} }

View File

@ -124,6 +124,7 @@
notifications.info("Request did not return any data.") notifications.info("Request did not return any data.")
} else { } else {
response.info = response.info || { code: 200 } response.info = response.info || { code: 200 }
schema = response.schema
notifications.success("Request sent successfully.") notifications.success("Request sent successfully.")
} }
} catch (err) { } catch (err) {
@ -243,7 +244,7 @@
<div class="bottom"> <div class="bottom">
<Layout paddingY="S" gap="S"> <Layout paddingY="S" gap="S">
<Divider size="S" /> <Divider size="S" />
{#if !response} {#if !response && Object.keys(schema).length === 0}
<Heading size="M">Response</Heading> <Heading size="M">Response</Heading>
<div class="placeholder"> <div class="placeholder">
<div class="placeholder-internal"> <div class="placeholder-internal">
@ -254,20 +255,30 @@
</div> </div>
</div> </div>
{:else} {:else}
<Tabs selected="JSON" quiet noPadding noHorizPadding> <Tabs
selected={!response ? "Schema" : "JSON"}
quiet
noPadding
noHorizPadding
>
{#if response}
<Tab title="JSON"> <Tab title="JSON">
<div> <div>
<JSONPreview height="300" data={response.rows[0]} /> <JSONPreview height="300" data={response.rows[0]} />
</div> </div>
</Tab> </Tab>
{/if}
{#if schema || response}
<Tab title="Schema"> <Tab title="Schema">
<KeyValueBuilder <KeyValueBuilder
bind:object={response.schema} bind:object={schema}
name="schema" name="schema"
headings headings
options={SchemaTypeOptions} options={SchemaTypeOptions}
/> />
</Tab> </Tab>
{/if}
{#if response}
<Tab title="Raw"> <Tab title="Raw">
<TextArea disabled value={response.extra?.raw} height="300" /> <TextArea disabled value={response.extra?.raw} height="300" />
</Tab> </Tab>
@ -307,6 +318,7 @@
>Save query</Button >Save query</Button
> >
</div> </div>
{/if}
</Tabs> </Tabs>
{/if} {/if}
</Layout> </Layout>