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

143 lines
3.6 KiB
Svelte
Raw Normal View History

<script>
import { onMount } from "svelte"
import { goto, params } from "@sveltech/routify"
import {
store,
allScreens,
backendUiStore,
selectedAccessRole,
screenSearchString,
} from "builderStore"
import { FrontendTypes } from "constants"
2021-01-14 11:03:33 +01:00
import ComponentNavigationTree from "components/design/NavigationPanel/ComponentNavigationTree/index.svelte"
import Layout from "components/design/NavigationPanel/Layout.svelte"
import NewScreenModal from "components/design/NavigationPanel/NewScreenModal.svelte"
import NewLayoutModal from "components/design/NavigationPanel/NewLayoutModal.svelte"
import { Modal, Switcher, Select, Input } from "@budibase/bbui"
2020-05-29 19:32:52 +02:00
const tabs = [
{
title: "Screens",
key: "screen",
},
{
title: "Layouts",
key: "layout",
},
]
let modal
let routes = {}
$: tab = $params.assetType
2020-12-02 14:41:00 +01:00
const navigate = ({ detail }) => {
if (!detail) {
return
}
2020-12-07 17:06:20 +01:00
$goto(`../${detail.heading.key}`)
2020-12-02 14:41:00 +01:00
}
const updateAccessRole = event => {
const role = event.target.value
// Select a valid screen with this new role - otherwise we'll not be
// able to change role at all because ComponentNavigationTree will kick us
// back the current role again because the same screen ID is still selected
const firstValidScreenId = $allScreens.find(
screen => screen.routing.roleId === role
)?._id
if (firstValidScreenId) {
store.actions.screens.select(firstValidScreenId)
}
// Otherwise clear the selected screen ID so that the first new valid screen
// can be selected by ComponentNavigationTree
else {
store.update(state => {
state.selectedScreenId = null
return state
})
}
selectedAccessRole.set(role)
}
onMount(() => {
2020-11-19 22:07:25 +01:00
store.actions.routing.fetch()
})
</script>
<div class="title">
<Switcher headings={tabs} bind:value={tab} on:change={navigate}>
{#if tab === FrontendTypes.SCREEN}
<i
on:click={modal.show}
data-cy="new-screen"
class="ri-add-circle-fill" />
<div class="role-select">
<Select
extraThin
secondary
on:change={updateAccessRole}
value={$selectedAccessRole}
label="Filter by Access">
{#each $backendUiStore.roles as role}
<option value={role._id}>{role.name}</option>
{/each}
</Select>
<Input
extraThin
2021-03-09 20:06:37 +01:00
placeholder="Enter a route to search"
label="Search Screens"
bind:value={$screenSearchString} />
</div>
<div class="nav-items-container">
<ComponentNavigationTree />
</div>
<Modal bind:this={modal}>
<NewScreenModal />
</Modal>
{:else if tab === FrontendTypes.LAYOUT}
<i
on:click={modal.show}
data-cy="new-layout"
class="ri-add-circle-fill" />
{#each $store.layouts as layout, idx (layout._id)}
<Layout {layout} border={idx > 0} />
2020-12-02 15:49:43 +01:00
{/each}
<Modal bind:this={modal}>
<NewLayoutModal />
</Modal>
{/if}
</Switcher>
</div>
<style>
.title {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
2020-12-04 15:52:40 +01:00
position: relative;
}
.title i {
font-size: 20px;
2020-12-04 15:52:40 +01:00
position: absolute;
top: 0;
right: 0;
}
.title i:hover {
cursor: pointer;
color: var(--blue);
}
.role-select {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
margin-bottom: var(--spacing-m);
gap: var(--spacing-m);
}
</style>