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

142 lines
3.7 KiB
Svelte
Raw Normal View History

<script>
import { onMount } from "svelte"
2021-03-17 12:40:24 +01:00
import { goto, params } from "@roxi/routify"
import {
store,
allScreens,
selectedAccessRole,
screenSearchString,
} from "builderStore"
2021-04-01 11:29:47 +02:00
import { roles } from "stores/backend"
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 { Icon, Modal, Select, Search, Tabs, Tab } from "@budibase/bbui"
2020-05-29 19:32:52 +02:00
const tabs = [
{
title: "Screens",
key: "screen",
},
{
title: "Layouts",
key: "layout",
},
]
let modal
$: selected = tabs.find((t) => t.key === $params.assetType).title
2020-12-02 14:41:00 +01:00
const navigate = ({ detail }) => {
const { key } = tabs.find((t) => t.title === detail)
$goto(`../${key}`)
2020-12-02 14:41:00 +01:00
}
const updateAccessRole = (event) => {
const role = event.detail
// 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">
<Tabs {selected} on:select={navigate}>
<Tab title="Screens">
<div class="tab-content-padding">
<div class="role-select">
<Select
on:change={updateAccessRole}
value={$selectedAccessRole}
label="Filter by Access"
getOptionLabel={(role) => role.name}
getOptionValue={(role) => role._id}
options={$roles}
/>
<Search
placeholder="Enter a route to search"
label="Search Screens"
bind:value={$screenSearchString}
/>
</div>
<div class="nav-items-container">
<ComponentNavigationTree />
2021-03-11 16:53:31 +01:00
</div>
<Modal bind:this={modal}>
<NewScreenModal />
</Modal>
</div>
</Tab>
<Tab title="Layouts">
<div class="tab-content-padding">
<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} />
{/each}
<Modal bind:this={modal}>
<NewLayoutModal />
</Modal>
</div>
</Tab>
</Tabs>
<div class="add-button">
<Icon hoverable name="AddCircle" on:click={modal.show} />
</div>
</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;
}
.add-button {
2020-12-04 15:52:40 +01:00
position: absolute;
top: var(--spectrum-alias-item-padding-l);
bottom: 0;
right: var(--spectrum-alias-item-padding-l);
}
.role-select {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
margin-bottom: var(--spacing-m);
gap: var(--spacing-m);
}
2021-03-11 16:53:31 +01:00
.tab-content-padding {
padding: 0 var(--spectrum-alias-item-padding-m);
2021-03-11 16:53:31 +01:00
}
</style>