budibase/packages/builder/src/components/design/ScreenDetailsModal.svelte

81 lines
1.8 KiB
Svelte
Raw Normal View History

2021-11-10 17:04:27 +01:00
<script>
import { ModalContent, Input } from "@budibase/bbui"
import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl"
import { get } from "svelte/store"
import { store } from "builderStore"
2021-11-10 17:04:27 +01:00
export let onConfirm
export let onCancel
2022-03-02 20:26:43 +01:00
export let screenUrl
export let screenRole
export let confirmText = "Continue"
2021-11-23 21:14:28 +01:00
2022-04-22 19:23:16 +02:00
const appPrefix = "/app"
let touched = false
let error
2022-04-22 19:23:16 +02:00
$: appUrl = screenUrl
? `${window.location.origin}${appPrefix}${screenUrl}`
: `${window.location.origin}${appPrefix}`
const routeChanged = event => {
if (!event.detail.startsWith("/")) {
screenUrl = "/" + event.detail
}
2022-03-02 20:26:43 +01:00
touched = true
screenUrl = sanitizeUrl(screenUrl)
if (routeExists(screenUrl)) {
error = "This URL is already taken for this access role"
} else {
error = null
}
}
const routeExists = url => {
if (!screenRole) {
return false
}
return get(store).screens.some(
screen =>
screen.routing.route.toLowerCase() === url.toLowerCase() &&
screen.routing.roleId === screenRole
)
}
2021-11-29 12:53:46 +01:00
const confirmScreenDetails = async () => {
await onConfirm({
screenUrl,
})
}
2021-11-10 17:04:27 +01:00
</script>
<ModalContent
size="M"
title={"Screen details"}
{confirmText}
onConfirm={confirmScreenDetails}
{onCancel}
2021-11-10 17:04:27 +01:00
cancelText={"Back"}
disabled={!screenUrl || error || !touched}
2021-11-10 17:04:27 +01:00
>
<Input
label="Enter a URL for the new screen"
{error}
bind:value={screenUrl}
on:change={routeChanged}
/>
2022-04-22 19:23:16 +02:00
<div class="app-server" title={appUrl}>
{appUrl}
</div>
2021-11-10 17:04:27 +01:00
</ModalContent>
2022-04-22 19:23:16 +02:00
<style>
.app-server {
color: var(--spectrum-global-color-gray-600);
width: 320px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>