Fix for both #4167, allow saving but warn if never sent and #4165 save the query name when clicking name save icon.

This commit is contained in:
mike12345567 2022-02-07 18:47:10 +00:00
parent 9298071cc2
commit 2f3af46222
4 changed files with 84 additions and 31 deletions

View File

@ -1,5 +1,6 @@
<script> <script>
import "@spectrum-css/button/dist/index-vars.css" import "@spectrum-css/button/dist/index-vars.css"
import Tooltip from "../Tooltip/Tooltip.svelte"
export let disabled = false export let disabled = false
export let size = "M" export let size = "M"
@ -11,9 +12,13 @@
export let quiet = false export let quiet = false
export let icon = undefined export let icon = undefined
export let active = false export let active = false
export let tooltip = undefined
let showTooltip = false
</script> </script>
<button <div class:container={!!tooltip}>
<button
class:spectrum-Button--cta={cta} class:spectrum-Button--cta={cta}
class:spectrum-Button--primary={primary} class:spectrum-Button--primary={primary}
class:spectrum-Button--secondary={secondary} class:spectrum-Button--secondary={secondary}
@ -24,7 +29,9 @@
class="spectrum-Button spectrum-Button--size{size.toUpperCase()}" class="spectrum-Button spectrum-Button--size{size.toUpperCase()}"
{disabled} {disabled}
on:click|preventDefault on:click|preventDefault
> on:mouseover={() => (showTooltip = true)}
on:mouseleave={() => (showTooltip = false)}
>
{#if icon} {#if icon}
<svg <svg
class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}" class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}"
@ -38,9 +45,22 @@
{#if $$slots} {#if $$slots}
<span class="spectrum-Button-label"><slot /></span> <span class="spectrum-Button-label"><slot /></span>
{/if} {/if}
</button> </button>
{#if showTooltip && tooltip}
<div class="position">
<div class="tooltip">
<Tooltip textWrapping={true} direction={"bottom"} text={tooltip} />
</div>
</div>
{/if}
</div>
<style> <style>
.container {
display: flex;
align-items: center;
flex-direction: column;
}
.spectrum-Button-label { .spectrum-Button-label {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
@ -49,4 +69,19 @@
.active { .active {
color: var(--spectrum-global-color-blue-600) !important; color: var(--spectrum-global-color-blue-600) !important;
} }
.tooltip {
position: absolute;
display: flex;
justify-content: center;
z-index: 100;
width: 160px;
text-align: center;
transform: translateX(-50%);
top: -5px;
}
.position {
position: relative;
width: 0;
height: 0;
}
</style> </style>

View File

@ -17,6 +17,7 @@
class:icon-small={size === "M" || size === "S"} class:icon-small={size === "M" || size === "S"}
on:mouseover={() => (showTooltip = true)} on:mouseover={() => (showTooltip = true)}
on:mouseleave={() => (showTooltip = false)} on:mouseleave={() => (showTooltip = false)}
on:focus
> >
<Icon name="InfoOutline" size="S" disabled={true} /> <Icon name="InfoOutline" size="S" disabled={true} />
</div> </div>
@ -47,7 +48,7 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
top: 15px; top: 15px;
z-index: 1; z-index: 100;
width: 160px; width: 160px;
} }
.icon { .icon {

View File

@ -17,6 +17,10 @@
dispatch("change") dispatch("change")
} }
} }
function save() {
dispatch("save", value)
}
</script> </script>
<div class="parent"> <div class="parent">
@ -39,7 +43,10 @@
name="SaveFloppy" name="SaveFloppy"
hoverable hoverable
size="S" size="S"
on:click={() => setEditing(false)} on:click={() => {
setEditing(false)
save()
}}
/> />
{/if} {/if}
</div> </div>

View File

@ -59,6 +59,7 @@
$: schemaReadOnly = !responseSuccess $: schemaReadOnly = !responseSuccess
$: variablesReadOnly = !responseSuccess $: variablesReadOnly = !responseSuccess
$: showVariablesTab = shouldShowVariables(dynamicVariables, variablesReadOnly) $: showVariablesTab = shouldShowVariables(dynamicVariables, variablesReadOnly)
$: hasSchema = !!query?.schema
function getSelectedQuery() { function getSelectedQuery() {
return cloneDeep( return cloneDeep(
@ -294,6 +295,7 @@
bind:value={query.name} bind:value={query.name}
defaultValue="Untitled" defaultValue="Untitled"
on:change={() => (query.flags.urlName = false)} on:change={() => (query.flags.urlName = false)}
on:save={saveQuery}
/> />
<div class="access"> <div class="access">
<Label>Access level</Label> <Label>Access level</Label>
@ -313,7 +315,18 @@
<div class="url"> <div class="url">
<Input bind:value={url} placeholder="http://www.api.com/endpoint" /> <Input bind:value={url} placeholder="http://www.api.com/endpoint" />
</div> </div>
<Button cta disabled={!url} on:click={runQuery}>Send</Button> <Button primary disabled={!url} on:click={runQuery}>Send</Button>
<Button
disabled={!query.name}
cta={hasSchema}
warning={!hasSchema}
on:click={saveQuery}
icon={!hasSchema && query.name ? "Alert" : null}
tooltip={!hasSchema
? "Saving a query before sending will mean no schema is generated"
: null}>Save</Button
>
{#if !query.schema}{/if}
</div> </div>
<Tabs selected="Bindings" quiet noPadding noHorizPadding onTop> <Tabs selected="Bindings" quiet noPadding noHorizPadding onTop>
<Tab title="Bindings"> <Tab title="Bindings">
@ -527,9 +540,6 @@
>{response?.info.size}</span >{response?.info.size}</span
> >
</Label> </Label>
<Button disabled={!responseSuccess} cta on:click={saveQuery}
>Save query</Button
>
</div> </div>
{/if} {/if}
</Tabs> </Tabs>