Make screens searchable and make routes collapsible

This commit is contained in:
Andrew Kingston 2021-03-09 19:06:25 +00:00
parent 40c47bf3de
commit dfee775717
4 changed files with 77 additions and 35 deletions

View File

@ -2,7 +2,6 @@ import { getFrontendStore } from "./store/frontend"
import { getBackendUiStore } from "./store/backend" import { getBackendUiStore } from "./store/backend"
import { getAutomationStore } from "./store/automation" import { getAutomationStore } from "./store/automation"
import { getHostingStore } from "./store/hosting" import { getHostingStore } from "./store/hosting"
import { getThemeStore } from "./store/theme" import { getThemeStore } from "./store/theme"
import { derived, writable } from "svelte/store" import { derived, writable } from "svelte/store"
import analytics from "analytics" import analytics from "analytics"
@ -66,3 +65,5 @@ export const initialise = async () => {
console.log(err) console.log(err)
} }
} }
export const screenSearchString = writable(null)

View File

@ -1,8 +1,11 @@
<script> <script>
import { goto } from "@sveltech/routify" import {
import { store, selectedComponent, currentAsset } from "builderStore" store,
selectedComponent,
currentAsset,
screenSearchString,
} from "builderStore"
import instantiateStore from "./dragDropStore" import instantiateStore from "./dragDropStore"
import ComponentTree from "./ComponentTree.svelte" import ComponentTree from "./ComponentTree.svelte"
import NavItem from "components/common/NavItem.svelte" import NavItem from "components/common/NavItem.svelte"
import ScreenDropdownMenu from "./ScreenDropdownMenu.svelte" import ScreenDropdownMenu from "./ScreenDropdownMenu.svelte"
@ -21,33 +24,61 @@
export let indent export let indent
export let border export let border
let routeManuallyOpened = false
$: selectedScreen = $currentAsset $: selectedScreen = $currentAsset
$: allScreens = getAllScreens(route)
$: filteredScreens = getFilteredScreens(allScreens, $screenSearchString)
$: hasSearchMatch = $screenSearchString && filteredScreens.length > 0
$: noSearchMatch = $screenSearchString && !filteredScreens.length
$: routeSelected = route.subpaths[selectedScreen.routing.route] !== undefined
$: routeOpened = routeManuallyOpened || routeSelected || hasSearchMatch
const changeScreen = screenId => { const changeScreen = screenId => {
store.actions.screens.select(screenId) store.actions.screens.select(screenId)
// Reset manually opened flag every time a new screen is selected
routeManuallyOpened = false
}
const getAllScreens = route => {
let screens = []
Object.entries(route.subpaths).forEach(([route, subpath]) => {
Object.entries(subpath.screens).forEach(([role, id]) => {
screens.push({ id, route, role })
})
})
return screens
}
const getFilteredScreens = (screens, searchString) => {
return screens.filter(
screen => !searchString || screen.route.includes(searchString)
)
} }
</script> </script>
<NavItem {#if !noSearchMatch}
<NavItem
icon="ri-folder-line" icon="ri-folder-line"
text={path} text={path}
opened={true} on:click={() => (routeManuallyOpened = !routeManuallyOpened)}
opened={routeOpened}
{border} {border}
withArrow={route.subpaths} /> withArrow={route.subpaths} />
{#each Object.entries(route.subpaths) as [url, subpath]} {#if routeOpened}
{#each Object.entries(subpath.screens) as [role, screenId]} {#each filteredScreens as screen (screen.id)}
<NavItem <NavItem
icon="ri-artboard-2-line" icon="ri-artboard-2-line"
indentLevel={indent || 1} indentLevel={indent || 1}
selected={$store.selectedScreenId === screenId} selected={$store.selectedScreenId === screen.id}
opened={$store.selectedScreenId === screenId} opened={$store.selectedScreenId === screen.id}
text={ROUTE_NAME_MAP[url]?.[role] || url} text={ROUTE_NAME_MAP[screen.route]?.[screen.role] || screen.route}
withArrow={route.subpaths} withArrow={route.subpaths}
on:click={() => changeScreen(screenId)}> on:click={() => changeScreen(screen.id)}>
<ScreenDropdownMenu {screenId} /> <ScreenDropdownMenu screenId={screen.id} />
</NavItem> </NavItem>
{#if selectedScreen?._id === screenId} {#if selectedScreen?._id === screen.id}
<ComponentTree <ComponentTree
level={1} level={1}
components={selectedScreen.props._children} components={selectedScreen.props._children}
@ -55,4 +86,5 @@
{dragDropStore} /> {dragDropStore} />
{/if} {/if}
{/each} {/each}
{/each} {/if}
{/if}

View File

@ -56,7 +56,7 @@
</script> </script>
<div class="root"> <div class="root">
{#each paths as path, idx} {#each paths as path, idx (path)}
<PathTree border={idx > 0} {path} route={routes[path]} /> <PathTree border={idx > 0} {path} route={routes[path]} />
{/each} {/each}

View File

@ -1,19 +1,19 @@
<script> <script>
import { onMount } from "svelte" import { onMount } from "svelte"
import { goto, params, url } from "@sveltech/routify" import { goto, params } from "@sveltech/routify"
import { import {
store, store,
allScreens, allScreens,
currentAsset,
backendUiStore, backendUiStore,
selectedAccessRole, selectedAccessRole,
screenSearchString,
} from "builderStore" } from "builderStore"
import { FrontendTypes } from "constants" import { FrontendTypes } from "constants"
import ComponentNavigationTree from "components/design/NavigationPanel/ComponentNavigationTree/index.svelte" import ComponentNavigationTree from "components/design/NavigationPanel/ComponentNavigationTree/index.svelte"
import Layout from "components/design/NavigationPanel/Layout.svelte" import Layout from "components/design/NavigationPanel/Layout.svelte"
import NewScreenModal from "components/design/NavigationPanel/NewScreenModal.svelte" import NewScreenModal from "components/design/NavigationPanel/NewScreenModal.svelte"
import NewLayoutModal from "components/design/NavigationPanel/NewLayoutModal.svelte" import NewLayoutModal from "components/design/NavigationPanel/NewLayoutModal.svelte"
import { Modal, Switcher, Select } from "@budibase/bbui" import { Modal, Switcher, Select, Input } from "@budibase/bbui"
const tabs = [ const tabs = [
{ {
@ -85,6 +85,10 @@
<option value={role._id}>{role.name}</option> <option value={role._id}>{role.name}</option>
{/each} {/each}
</Select> </Select>
<Input
extraThin
label="Search Screens"
bind:value={$screenSearchString} />
</div> </div>
<div class="nav-items-container"> <div class="nav-items-container">
<ComponentNavigationTree /> <ComponentNavigationTree />
@ -127,6 +131,11 @@
} }
.role-select { .role-select {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
margin-bottom: var(--spacing-m); margin-bottom: var(--spacing-m);
gap: var(--spacing-m);
} }
</style> </style>