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

77 lines
1.9 KiB
Svelte
Raw Normal View History

2021-11-10 17:04:27 +01:00
<script>
import { ModalContent, Input, Select } from "@budibase/bbui"
import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl"
import { selectedAccessRole, allScreens } from "builderStore"
import { get } from "svelte/store"
import { roles } from "stores/backend"
import analytics, { Events } from "analytics"
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 confirmText = "Continue"
2021-11-23 21:14:28 +01:00
let routeError
2022-03-02 20:26:43 +01:00
let touched = false
let screenAccessRole = $selectedAccessRole + ""
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)) {
routeError = "This URL is already taken for this access role"
} else {
routeError = null
}
}
const routeExists = url => {
const roleId = get(selectedAccessRole) || "BASIC"
return get(allScreens).some(
screen =>
screen.routing.route.toLowerCase() === url.toLowerCase() &&
screen.routing.roleId === roleId
)
}
2021-11-29 12:53:46 +01:00
const confirmScreenDetails = async () => {
await onConfirm({
screenUrl,
screenAccessRole,
})
}
2021-11-10 17:04:27 +01:00
</script>
<ModalContent
size="M"
2021-11-16 13:18:13 +01:00
title={"Enter details"}
{confirmText}
onConfirm={confirmScreenDetails}
{onCancel}
2021-11-10 17:04:27 +01:00
cancelText={"Back"}
disabled={!screenAccessRole || !screenUrl || routeError || !touched}
2021-11-10 17:04:27 +01:00
>
<Input
label="URL"
error={routeError}
bind:value={screenUrl}
on:change={routeChanged}
/>
<Select
bind:value={screenAccessRole}
on:change={() => {
analytics.captureEvent(Events.SCREEN.CREATE_ROLE_UPDATED, {
screenAccessRole,
})
}}
label="Screen access"
getOptionLabel={role => role.name}
getOptionValue={role => role._id}
getOptionColor={role => role.color}
options={$roles}
/>
2021-11-10 17:04:27 +01:00
</ModalContent>