Support navigate to link in new tab (#9800)

* Support navigate to link in new tab

* Add dropdown for Navigate To type

* lint

* Remove labels
This commit is contained in:
melohagan 2023-03-01 17:41:50 +00:00 committed by GitHub
parent 6fdc328cd9
commit 6a6bbb38c4
3 changed files with 70 additions and 21 deletions

View File

@ -1,22 +1,66 @@
<script>
import { Label, Checkbox } from "@budibase/bbui"
import { store } from "builderStore"
import { onMount } from "svelte"
import { Label, Checkbox, Select } from "@budibase/bbui"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
import DrawerBindableCombobox from "components/common/bindings/DrawerBindableCombobox.svelte"
export let parameters
export let bindings = []
$: urlOptions = $store.screens
.map(screen => screen.routing?.route)
.filter(x => x != null)
const typeOptions = [
{
label: "Screen",
value: "screen",
},
{
label: "URL",
value: "url",
},
]
onMount(() => {
if (!parameters.type) {
parameters.type = "screen"
}
})
</script>
<div class="root">
<Label small>Screen</Label>
<DrawerBindableInput
title="Destination URL"
placeholder="/screen"
value={parameters.url}
on:change={value => (parameters.url = value.detail)}
{bindings}
<Label small>Destination</Label>
<Select
placeholder={null}
bind:value={parameters.type}
options={typeOptions}
on:change={() => (parameters.url = "")}
/>
<div />
<Checkbox text="Open screen in modal" bind:value={parameters.peek} />
{#if parameters.type === "screen"}
<DrawerBindableCombobox
title="Destination"
placeholder="/screen"
value={parameters.url}
on:change={value => (parameters.url = value.detail)}
{bindings}
options={urlOptions}
appendBindingsAsOptions={false}
/>
<div />
<Checkbox text="Open screen in modal" bind:value={parameters.peek} />
{:else}
<DrawerBindableInput
title="Destination"
placeholder="/url"
value={parameters.url}
on:change={value => (parameters.url = value.detail)}
{bindings}
/>
<div />
<Checkbox text="New Tab" bind:value={parameters.externalNewTab} />
{/if}
</div>
<style>
@ -24,7 +68,7 @@
display: grid;
align-items: center;
gap: var(--spacing-m);
grid-template-columns: auto 1fr;
grid-template-columns: auto;
max-width: 400px;
margin: 0 auto;
}

View File

@ -66,22 +66,27 @@ const createRouteStore = () => {
return state
})
}
const navigate = (url, peek) => {
const navigate = (url, peek, externalNewTab) => {
if (get(builderStore).inBuilder) {
return
}
if (url) {
// If we're already peeking, don't peek again
const isPeeking = get(store).queryParams?.peek
if (peek && !isPeeking) {
const external = !url.startsWith("/")
if (peek && !isPeeking && !external) {
peekStore.actions.showPeek(url)
} else {
const external = !url.startsWith("/")
if (external) {
window.location.href = url
} else {
push(url)
} else if (external) {
if (url.startsWith("www")) {
url = `https://${url}`
}
if (externalNewTab) {
window.open(url, "_blank")
} else {
window.location.href = url
}
} else {
push(url)
}
}
}

View File

@ -140,8 +140,8 @@ const triggerAutomationHandler = async action => {
}
const navigationHandler = action => {
const { url, peek } = action.parameters
routeStore.actions.navigate(url, peek)
const { url, peek, externalNewTab } = action.parameters
routeStore.actions.navigate(url, peek, externalNewTab)
}
const queryExecutionHandler = async action => {