@servicetitan/navigation 14.4.0 → 14.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/titan-layout/layout-sidebar.d.ts.map +1 -1
- package/dist/components/titan-layout/layout-sidebar.js +30 -11
- package/dist/components/titan-layout/layout-sidebar.js.map +1 -1
- package/dist/components/titan-layout/layout-sidebar.module.less +1 -1
- package/dist/components/titan-layout/navigation-catalog/navigation-catalog-trigger.js +1 -1
- package/dist/components/titan-layout/navigation-catalog/navigation-catalog-trigger.js.map +1 -1
- package/dist/components/titan-layout/navigation-catalog/navigation-catalog.d.ts.map +1 -1
- package/dist/components/titan-layout/navigation-catalog/navigation-catalog.js +54 -63
- package/dist/components/titan-layout/navigation-catalog/navigation-catalog.js.map +1 -1
- package/dist/utils/__tests__/side-nav.test.d.ts +2 -0
- package/dist/utils/__tests__/side-nav.test.d.ts.map +1 -0
- package/dist/utils/side-nav.d.ts +17 -0
- package/dist/utils/side-nav.d.ts.map +1 -1
- package/dist/utils/side-nav.js +32 -0
- package/dist/utils/side-nav.js.map +1 -1
- package/package.json +2 -2
- package/src/components/titan-layout/__tests__/navigation-catalog-reset.test.tsx +59 -7
- package/src/components/titan-layout/layout-sidebar.module.less +1 -1
- package/src/components/titan-layout/layout-sidebar.tsx +34 -10
- package/src/components/titan-layout/navigation-catalog/navigation-catalog-trigger.tsx +1 -1
- package/src/components/titan-layout/navigation-catalog/navigation-catalog.tsx +58 -74
- package/src/utils/__tests__/side-nav.test.ts +77 -0
- package/src/utils/side-nav.ts +42 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/titan-layout/navigation-catalog/navigation-catalog.tsx"],"sourcesContent":["import { Button, Dialog, Icon, SearchField, Text, Tooltip } from '@servicetitan/anvil2';\nimport IconLock from '@servicetitan/anvil2/assets/icons/material/round/lock.svg';\nimport IconStar from '@servicetitan/anvil2/assets/icons/material/round/star.svg';\nimport IconStarBorder from '@servicetitan/anvil2/assets/icons/material/round/star_border.svg';\nimport classNames from 'classnames';\nimport { FC, Fragment, MouseEvent, useMemo, useRef, useState } from 'react';\nimport {\n filterCatalogGroups,\n getCatalogChildren,\n getCatalogSubmenuGroups,\n} from '../../../utils/catalog-groups';\nimport { NavigationItemData } from '../../../utils/navigation';\nimport { getCounterTag } from '../../../utils/side-nav';\nimport { BadgeTag } from '../../badge-tag';\nimport { PinnedNavigationConfig } from '../interface';\nimport { useTitanLayoutContext } from '../layout-context';\nimport { NavigationCatalogFooter } from './navigation-catalog-footer';\nimport * as styles from './navigation-catalog.module.less';\n\n/** Shown in place of the pin control for a destination the user may not unpin. */\nconst LockedPin: FC = () => (\n <Tooltip>\n <Tooltip.Trigger>\n <Icon svg={IconLock} className={styles.lock} />\n </Tooltip.Trigger>\n <Tooltip.Content style={{ pointerEvents: 'none' }}>\n Cannot be removed from Favorites\n </Tooltip.Content>\n </Tooltip>\n);\n\ninterface PinToggleProps {\n /** Mixed modules stay highlighted but use an outline until all pages are pinned. */\n pinned: boolean | 'mixed';\n label: string;\n onToggle: () => void;\n}\n\nconst PinToggle: FC<PinToggleProps> = ({ pinned, label, onToggle }) => {\n const toggle = (event: MouseEvent) => {\n // The control sits inside the row but is not a navigation affordance.\n event.preventDefault();\n event.stopPropagation();\n onToggle();\n };\n\n return (\n <Tooltip delay={300}>\n <Tooltip.Trigger>\n <Button\n appearance=\"ghost\"\n size=\"small\"\n icon={pinned === true ? IconStar : IconStarBorder}\n className={classNames(styles.star, pinned && styles.starActive)}\n aria-label={label}\n aria-pressed={pinned}\n onClick={toggle}\n />\n </Tooltip.Trigger>\n <Tooltip.Content style={{ pointerEvents: 'none' }}>\n {pinned === 'mixed'\n ? 'Add this module to Favorites'\n : pinned\n ? 'Remove from Favorites'\n : 'Add to Favorites'}\n </Tooltip.Content>\n </Tooltip>\n );\n};\n\ninterface CatalogRowsProps {\n item: NavigationItemData;\n /**\n * Every id the module's own control covers, taken from the unfiltered item.\n *\n * `item` may have been narrowed by the search, so deriving this from it would let the control\n * act on only the pages that happen to be visible — silently stranding the rest.\n */\n scopeIds: string[];\n isPinned: (id: string) => boolean;\n isLocked: (id: string) => boolean;\n /** `ownerId` is the module the page belongs to; omitted for the module's own row. */\n onTogglePin: (id: string, ownerId?: string) => void;\n onToggleAll: (ids: string[], shouldPin: boolean) => void;\n onNavigate: () => void;\n}\n\nconst CatalogRows: FC<CatalogRowsProps> = ({\n item,\n scopeIds,\n isPinned,\n isLocked,\n onTogglePin,\n onToggleAll,\n onNavigate,\n}) => {\n const { NavigationComponent } = useTitanLayoutContext();\n const submenuGroups = getCatalogSubmenuGroups(item);\n\n /*\n * Minus anything locked — locked destinations are always present, so the module's control\n * neither reports on them nor acts on them.\n */\n const everything = scopeIds.filter(id => !isLocked(id));\n const anyPinned = everything.some(isPinned);\n const allPinned = everything.length > 0 && everything.every(isPinned);\n const tag = getCounterTag(item.counter, item.tag);\n\n return (\n <div className={styles.moduleGroup}>\n <div className={styles.row}>\n <NavigationComponent\n to={item.to}\n className={styles.link}\n onClick={onNavigate}\n aria-label={item.title}\n >\n {item.icon && (\n <Icon svg={item.icon} size=\"medium\" className={styles.moduleIcon} />\n )}\n <Text inline size=\"small\" className={styles.moduleTitle}>\n {item.title}\n </Text>\n {/*\n * The same counter the rail shows, so a destination that is asking for\n * attention still says so here — the catalog is the only place an unfavourited\n * one is visible at all.\n */}\n {!!tag && <BadgeTag data={tag} className={styles.badge} />}\n </NavigationComponent>\n {/*\n * One control for the whole module: favouriting it takes its pages with it, and\n * unfavouriting it takes them away again.\n *\n * A gold outline marks a partially favourited module. Fill the star only when\n * its full, unfiltered scope is favourited, including pages hidden by search.\n * Clicking the outline adds the remaining pages; clicking the filled star removes all.\n */}\n {isLocked(item.id) ? (\n <LockedPin />\n ) : (\n <PinToggle\n pinned={allPinned ? true : anyPinned ? 'mixed' : false}\n label={\n allPinned\n ? `Unpin ${item.title} from the navigation`\n : `Pin ${item.title} to the navigation`\n }\n onToggle={() => onToggleAll(everything, !allPinned)}\n />\n )}\n </div>\n {submenuGroups.map(group => (\n <div key={group.links[0].id}>\n {group.title && (\n <Text variant=\"eyebrow\" size=\"small\" className={styles.submenuTitle}>\n {group.title}\n </Text>\n )}\n {group.links.map(child => {\n /*\n * Page titles are only unique within their item — \"Settings\" and \"Reports\" recur\n * across the catalog — and the row that tells them apart is a separate element, so\n * it is not part of any of these names. Anything reading the rows on their own, a\n * screen reader running through the links or a voice command naming one, would\n * otherwise be given the same name several times.\n */\n const qualifiedTitle = `${item.title}: ${child.title}`;\n const childPinned = isPinned(child.id);\n const childTag = getCounterTag(child.counter, child.tag);\n\n return (\n <div key={child.id} className={styles.row}>\n <NavigationComponent\n to={child.to}\n className={classNames(styles.link, styles.childLink)}\n onClick={onNavigate}\n aria-label={qualifiedTitle}\n >\n <Text inline className={styles.childTitle}>\n {child.title}\n </Text>\n {!!childTag && (\n <BadgeTag data={childTag} className={styles.badge} />\n )}\n </NavigationComponent>\n {isLocked(child.id) ? (\n <LockedPin />\n ) : (\n <PinToggle\n pinned={childPinned}\n label={\n childPinned\n ? `Unpin ${qualifiedTitle} from the navigation`\n : `Pin ${qualifiedTitle} to the navigation`\n }\n onToggle={() => onTogglePin(child.id, item.id)}\n />\n )}\n </div>\n );\n })}\n </div>\n ))}\n </div>\n );\n};\n\nexport interface NavigationCatalogProps extends PinnedNavigationConfig {\n open: boolean;\n onClose: () => void;\n}\n\n/**\n * Every destination the host offers, grouped into sections, with a star on every row.\n *\n * The catalog shows what it is given and nothing more — the host has already resolved what this\n * user may reach, so the catalog cannot offer a destination they do not have.\n */\nexport const NavigationCatalog: FC<NavigationCatalogProps> = ({\n open,\n onClose,\n groups,\n pinnedIds,\n lockedIds,\n onPinnedIdsChange,\n onResetToDefaults,\n}) => {\n const [query, setQuery] = useState('');\n const isSearching = query.trim().length > 0;\n const searchRef = useRef<HTMLInputElement>(null);\n\n /*\n * Resolved here rather than by the host, so a catalog that costs requests to enumerate is paid\n * for on opening the dialog and not on every page load. This component is mounted only while\n * open, so the call happens once per open unless the host changes the function.\n */\n const resolvedGroups = useMemo(() => groups(), [groups]);\n\n const visibleGroups = useMemo(\n () => filterCatalogGroups(resolvedGroups, query),\n [resolvedGroups, query]\n );\n\n /*\n * The pin scope of every item, keyed by id and built before the search narrows anything, so a\n * module's control still covers the pages a query is currently hiding.\n */\n const scopeById = useMemo(\n () =>\n new Map(\n resolvedGroups\n .flatMap(group => group.items)\n .map(item => [\n item.id,\n [item.id, ...getCatalogChildren(item).map(child => child.id)],\n ])\n ),\n [resolvedGroups]\n );\n const pinnedSet = useMemo(() => new Set(pinnedIds), [pinnedIds]);\n const lockedSet = useMemo(() => new Set(lockedIds ?? []), [lockedIds]);\n\n const isPinned = (id: string) => pinnedSet.has(id);\n const isLocked = (id: string) => lockedSet.has(id);\n\n /**\n * Favourites or unfavourites one row, carrying its module with it.\n *\n * A page is reached through its module, so the two travel together: favouriting a page brings\n * the module along when it is not already there, and unfavouriting the last one takes the\n * module with it. Leaving the module behind on its own would not read as an emptier\n * navigation — it would put the module back carrying every page it has.\n *\n * Locked ids never reach a proposal. The controls that would move them are not rendered, so\n * that part is belt and braces — but the host's list is the thing that gets persisted, and a\n * locked destination has no business appearing in or disappearing from it.\n */\n const togglePin = (id: string, ownerId?: string) => {\n if (lockedSet.has(id)) {\n return;\n }\n\n /** The module, when it is a separate row that this page can legitimately move. */\n const owner = ownerId !== id && ownerId && !lockedSet.has(ownerId) ? ownerId : undefined;\n\n if (pinnedSet.has(id)) {\n const removing = new Set([id]);\n\n if (owner) {\n const siblings = (scopeById.get(owner) ?? []).filter(\n scoped => scoped !== owner && scoped !== id\n );\n\n if (!siblings.some(sibling => pinnedSet.has(sibling))) {\n removing.add(owner);\n }\n }\n\n onPinnedIdsChange(pinnedIds.filter(pinned => !removing.has(pinned)));\n return;\n }\n\n // Module first, so it reads ahead of its own page in the saved order.\n const additions = owner && !pinnedSet.has(owner) ? [owner, id] : [id];\n\n onPinnedIdsChange([...pinnedIds, ...additions]);\n };\n\n /*\n * One proposal for the whole set rather than one per row, so a host that persists on every\n * change writes once, and every intermediate list — states the user never asked for — never\n * exists.\n */\n const toggleAll = (ids: string[], shouldPin: boolean) => {\n const actionable = ids.filter(id => !lockedSet.has(id));\n\n if (!shouldPin) {\n const removing = new Set(actionable);\n\n onPinnedIdsChange(pinnedIds.filter(pinned => !removing.has(pinned)));\n return;\n }\n\n const additions = actionable.filter(id => !pinnedSet.has(id));\n\n if (additions.length > 0) {\n onPinnedIdsChange([...pinnedIds, ...additions]);\n }\n };\n\n const close = () => {\n setQuery('');\n onClose();\n };\n\n return (\n <Dialog\n open={open}\n onClose={close}\n size=\"xlarge\"\n aria-label=\"All Navigation\"\n className={styles.dialog}\n data-cy=\"navigation-catalog-dialog\"\n >\n <Dialog.Content className={styles.content}>\n <div className={styles.body}>\n <SearchField\n ref={searchRef}\n size=\"small\"\n className={styles.search}\n placeholder=\"Go to ...\"\n value={query}\n onChange={event => setQuery(event.target.value)}\n onClear={() => setQuery('')}\n aria-label=\"Go to\"\n />\n <div\n className={classNames(styles.results, isSearching && styles.searchResults)}\n >\n {visibleGroups.length === 0 ? (\n <div className={styles.empty}>\n {/*\n * Two different nothings: a search that matched no row, and a host\n * that offered no rows at all. The second is a real state — the\n * catalog is reachable whether or not there is anything in it — and\n * quoting an empty query at the user does not describe it.\n */}\n <Text subdued>\n {isSearching ? (\n <Fragment>\n No navigation items match “{query}”.\n </Fragment>\n ) : (\n 'There are no navigation items to show.'\n )}\n </Text>\n </div>\n ) : (\n <div className={isSearching ? undefined : styles.columns}>\n {visibleGroups.map(group => (\n <div\n key={group.title}\n className={isSearching ? undefined : styles.group}\n >\n {/*\n * Browse uses titled columns. Search stacks matches at full\n * width, keeping only each module's own submenu headings.\n */}\n {!isSearching && (\n <Text\n variant=\"eyebrow\"\n size=\"medium\"\n className={styles.groupTitle}\n >\n {group.title}\n </Text>\n )}\n {group.items.map(item => (\n <CatalogRows\n key={item.id}\n item={item}\n scopeIds={scopeById.get(item.id) ?? [item.id]}\n isPinned={isPinned}\n isLocked={isLocked}\n onTogglePin={togglePin}\n onToggleAll={toggleAll}\n onNavigate={close}\n />\n ))}\n </div>\n ))}\n </div>\n )}\n </div>\n </div>\n </Dialog.Content>\n <NavigationCatalogFooter\n onRestore={\n onResetToDefaults &&\n (() => {\n onResetToDefaults();\n // The control disappears with the host's reset; keep focus in the dialog.\n searchRef.current?.focus();\n })\n }\n />\n </Dialog>\n );\n};\n"],"names":["Button","Dialog","Icon","SearchField","Text","Tooltip","IconLock","IconStar","IconStarBorder","classNames","Fragment","useMemo","useRef","useState","filterCatalogGroups","getCatalogChildren","getCatalogSubmenuGroups","getCounterTag","BadgeTag","useTitanLayoutContext","NavigationCatalogFooter","styles","LockedPin","Trigger","svg","className","lock","Content","style","pointerEvents","PinToggle","pinned","label","onToggle","toggle","event","preventDefault","stopPropagation","delay","appearance","size","icon","star","starActive","aria-label","aria-pressed","onClick","CatalogRows","item","scopeIds","isPinned","isLocked","onTogglePin","onToggleAll","onNavigate","NavigationComponent","submenuGroups","everything","filter","id","anyPinned","some","allPinned","length","every","tag","counter","div","moduleGroup","row","to","link","title","moduleIcon","inline","moduleTitle","data","badge","map","group","variant","submenuTitle","links","child","qualifiedTitle","childPinned","childTag","childLink","childTitle","NavigationCatalog","open","onClose","groups","pinnedIds","lockedIds","onPinnedIdsChange","onResetToDefaults","query","setQuery","isSearching","trim","searchRef","resolvedGroups","visibleGroups","scopeById","Map","flatMap","items","pinnedSet","Set","lockedSet","has","togglePin","ownerId","owner","undefined","removing","siblings","get","scoped","sibling","add","additions","toggleAll","ids","shouldPin","actionable","close","dialog","data-cy","content","body","ref","search","placeholder","value","onChange","target","onClear","results","searchResults","empty","subdued","columns","groupTitle","onRestore","current","focus"],"mappings":";AAAA,SAASA,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAEC,IAAI,EAAEC,OAAO,QAAQ,uBAAuB;AACxF,OAAO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AL;qBAEAK,qBAAAA,UAAU6C,OAAO,cAAjB7C,yCAAAA,mBAAmB8C,KAAK;gBAC5B,CAAA;;;;AAKpB,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/titan-layout/navigation-catalog/navigation-catalog.tsx"],"sourcesContent":["import { Button, Dialog, Icon, SearchField, Text, Tooltip } from '@servicetitan/anvil2';\nimport IconLock from '@servicetitan/anvil2/assets/icons/material/round/lock.svg';\nimport IconStar from '@servicetitan/anvil2/assets/icons/material/round/star.svg';\nimport IconStarBorder from '@servicetitan/anvil2/assets/icons/material/round/star_border.svg';\nimport classNames from 'classnames';\nimport { FC, Fragment, MouseEvent, useMemo, useRef, useState } from 'react';\nimport {\n filterCatalogGroups,\n getCatalogChildren,\n getCatalogSubmenuGroups,\n} from '../../../utils/catalog-groups';\nimport { NavigationItemData } from '../../../utils/navigation';\nimport { getCounterTag } from '../../../utils/side-nav';\nimport { BadgeTag } from '../../badge-tag';\nimport { PinnedNavigationConfig } from '../interface';\nimport { useTitanLayoutContext } from '../layout-context';\nimport { NavigationCatalogFooter } from './navigation-catalog-footer';\nimport * as styles from './navigation-catalog.module.less';\n\n/** Shown in place of the pin control for a destination the user may not unpin. */\nconst LockedPin: FC = () => (\n <Tooltip>\n <Tooltip.Trigger>\n <Icon svg={IconLock} className={styles.lock} />\n </Tooltip.Trigger>\n <Tooltip.Content style={{ pointerEvents: 'none' }}>\n Cannot be removed from Favorites\n </Tooltip.Content>\n </Tooltip>\n);\n\ninterface PinToggleProps {\n /** `mixed` is a module on the rail with only some of its pages: an outline, still active. */\n pinned: boolean | 'mixed';\n label: string;\n onToggle: () => void;\n}\n\nconst PinToggle: FC<PinToggleProps> = ({ pinned, label, onToggle }) => {\n const toggle = (event: MouseEvent) => {\n // The control sits inside the row but is not a navigation affordance.\n event.preventDefault();\n event.stopPropagation();\n onToggle();\n };\n\n return (\n <Tooltip delay={300}>\n <Tooltip.Trigger>\n <Button\n appearance=\"ghost\"\n size=\"small\"\n icon={pinned === true ? IconStar : IconStarBorder}\n className={classNames(styles.star, pinned && styles.starActive)}\n aria-label={label}\n aria-pressed={pinned}\n data-pendo=\"global-nav-favorite-star\"\n onClick={toggle}\n />\n </Tooltip.Trigger>\n <Tooltip.Content style={{ pointerEvents: 'none' }}>\n {pinned ? 'Remove from Favorites' : 'Add to Favorites'}\n </Tooltip.Content>\n </Tooltip>\n );\n};\n\ninterface CatalogRowsProps {\n item: NavigationItemData;\n /**\n * Every id the module's own control covers, taken from the unfiltered item.\n *\n * `item` may have been narrowed by the search, so deriving this from it would let the control\n * act on only the pages that happen to be visible — silently stranding the rest.\n */\n scopeIds: string[];\n isPinned: (id: string) => boolean;\n isLocked: (id: string) => boolean;\n onToggleModule: (moduleId: string) => void;\n onTogglePage: (id: string, moduleId: string) => void;\n onNavigate: () => void;\n}\n\nconst CatalogRows: FC<CatalogRowsProps> = ({\n item,\n scopeIds,\n isPinned,\n isLocked,\n onToggleModule,\n onTogglePage,\n onNavigate,\n}) => {\n const { NavigationComponent } = useTitanLayoutContext();\n const submenuGroups = getCatalogSubmenuGroups(item);\n\n /*\n * A pinned module id means the whole module, every page included. Pinned page ids without\n * their module mean the module is on the rail carrying only those pages.\n */\n const isWholeModule = isPinned(item.id);\n const isOnRail = scopeIds.some(isPinned);\n const pageIds = scopeIds.filter(id => id !== item.id && !isLocked(id));\n const isFullyPinned = isWholeModule || (pageIds.length > 0 && pageIds.every(isPinned));\n const tag = getCounterTag(item.counter, item.tag);\n\n return (\n <div className={styles.moduleGroup}>\n <div className={styles.row}>\n <NavigationComponent\n to={item.to}\n className={styles.link}\n onClick={onNavigate}\n aria-label={item.title}\n >\n {item.icon && (\n <Icon svg={item.icon} size=\"medium\" className={styles.moduleIcon} />\n )}\n <Text inline size=\"small\" className={styles.moduleTitle}>\n {item.title}\n </Text>\n {/*\n * The same counter the rail shows, so a destination that is asking for\n * attention still says so here — the catalog is the only place an unfavourited\n * one is visible at all.\n */}\n {!!tag && <BadgeTag data={tag} className={styles.badge} />}\n </NavigationComponent>\n {/*\n * Filled when every page is favourited, an outline when only some are. Either way\n * the module is on the rail, so one click takes it off with all of its pages.\n */}\n {isLocked(item.id) ? (\n <LockedPin />\n ) : (\n <PinToggle\n pinned={isFullyPinned ? true : isOnRail ? 'mixed' : false}\n label={\n isOnRail\n ? `Unpin ${item.title} from the navigation`\n : `Pin ${item.title} to the navigation`\n }\n onToggle={() => onToggleModule(item.id)}\n />\n )}\n </div>\n {submenuGroups.map(group => (\n <div key={group.links[0].id}>\n {group.title && (\n <Text variant=\"eyebrow\" size=\"small\" className={styles.submenuTitle}>\n {group.title}\n </Text>\n )}\n {group.links.map(child => {\n /*\n * Page titles are only unique within their item — \"Settings\" and \"Reports\" recur\n * across the catalog — and the row that tells them apart is a separate element, so\n * it is not part of any of these names. Anything reading the rows on their own, a\n * screen reader running through the links or a voice command naming one, would\n * otherwise be given the same name several times.\n */\n const qualifiedTitle = `${item.title}: ${child.title}`;\n const childPinned = isWholeModule || isPinned(child.id);\n const childTag = getCounterTag(child.counter, child.tag);\n\n return (\n <div key={child.id} className={styles.row}>\n <NavigationComponent\n to={child.to}\n className={classNames(styles.link, styles.childLink)}\n onClick={onNavigate}\n aria-label={qualifiedTitle}\n >\n <Text inline className={styles.childTitle}>\n {child.title}\n </Text>\n {!!childTag && (\n <BadgeTag data={childTag} className={styles.badge} />\n )}\n </NavigationComponent>\n {isLocked(child.id) ? (\n <LockedPin />\n ) : (\n <PinToggle\n pinned={childPinned}\n label={\n childPinned\n ? `Unpin ${qualifiedTitle} from the navigation`\n : `Pin ${qualifiedTitle} to the navigation`\n }\n onToggle={() => onTogglePage(child.id, item.id)}\n />\n )}\n </div>\n );\n })}\n </div>\n ))}\n </div>\n );\n};\n\nexport interface NavigationCatalogProps extends PinnedNavigationConfig {\n open: boolean;\n onClose: () => void;\n}\n\n/**\n * Every destination the host offers, grouped into sections, with a star on every row.\n *\n * The catalog shows what it is given and nothing more — the host has already resolved what this\n * user may reach, so the catalog cannot offer a destination they do not have.\n */\nexport const NavigationCatalog: FC<NavigationCatalogProps> = ({\n open,\n onClose,\n groups,\n pinnedIds,\n lockedIds,\n onPinnedIdsChange,\n onResetToDefaults,\n}) => {\n const [query, setQuery] = useState('');\n const isSearching = query.trim().length > 0;\n const searchRef = useRef<HTMLInputElement>(null);\n\n /*\n * Resolved here rather than by the host, so a catalog that costs requests to enumerate is paid\n * for on opening the dialog and not on every page load. This component is mounted only while\n * open, so the call happens once per open unless the host changes the function.\n */\n const resolvedGroups = useMemo(() => groups(), [groups]);\n\n const visibleGroups = useMemo(\n () => filterCatalogGroups(resolvedGroups, query),\n [resolvedGroups, query]\n );\n\n /*\n * The pin scope of every item, keyed by id and built before the search narrows anything, so a\n * module's control still covers the pages a query is currently hiding.\n */\n const scopeById = useMemo(\n () =>\n new Map(\n resolvedGroups\n .flatMap(group => group.items)\n .map(item => [\n item.id,\n [item.id, ...getCatalogChildren(item).map(child => child.id)],\n ])\n ),\n [resolvedGroups]\n );\n const pinnedSet = useMemo(() => new Set(pinnedIds), [pinnedIds]);\n const lockedSet = useMemo(() => new Set(lockedIds ?? []), [lockedIds]);\n\n const isPinned = (id: string) => pinnedSet.has(id);\n const isLocked = (id: string) => lockedSet.has(id);\n\n /*\n * The saved list follows the host's model: a module id pins the whole module, and page ids\n * without their module pin the module carrying only those pages. A module id is therefore\n * never saved next to its own page ids — the host would read that as the whole module.\n *\n * Locked ids never reach a proposal. The controls that would move them are not rendered, so\n * that part is belt and braces — but the host's list is the thing that gets persisted, and a\n * locked destination has no business appearing in or disappearing from it.\n */\n\n /** Takes a module off the rail with all of its pages, or puts the whole module on it. */\n const toggleModule = (moduleId: string) => {\n if (lockedSet.has(moduleId)) {\n return;\n }\n\n const scope = (scopeById.get(moduleId) ?? [moduleId]).filter(id => !lockedSet.has(id));\n const scopeSet = new Set(scope);\n const withoutModule = pinnedIds.filter(pinned => !scopeSet.has(pinned));\n\n onPinnedIdsChange(\n scope.some(id => pinnedSet.has(id)) ? withoutModule : [...withoutModule, moduleId]\n );\n };\n\n /**\n * Favourites or unfavourites a single page.\n *\n * Unstarring a page of a wholly favourited module narrows the module to the rest of its pages,\n * in the module's place; unstarring its last page takes the module off the rail.\n */\n const togglePage = (id: string, moduleId: string) => {\n if (lockedSet.has(id)) {\n return;\n }\n\n const scope = scopeById.get(moduleId) ?? [moduleId];\n const pages = scope.filter(scoped => scoped !== moduleId && !lockedSet.has(scoped));\n\n if (pinnedSet.has(moduleId) && !lockedSet.has(moduleId)) {\n const scopeSet = new Set(scope);\n const rest = pages.filter(page => page !== id);\n\n onPinnedIdsChange(\n pinnedIds.flatMap(pinned =>\n pinned === moduleId ? rest : scopeSet.has(pinned) ? [] : [pinned]\n )\n );\n return;\n }\n\n onPinnedIdsChange(\n pinnedSet.has(id) ? pinnedIds.filter(pinned => pinned !== id) : [...pinnedIds, id]\n );\n };\n\n const close = () => {\n setQuery('');\n onClose();\n };\n\n return (\n <Dialog\n open={open}\n onClose={close}\n size=\"xlarge\"\n aria-label=\"All Navigation\"\n className={styles.dialog}\n data-cy=\"navigation-catalog-dialog\"\n >\n <Dialog.Content className={styles.content}>\n <div className={styles.body}>\n <SearchField\n ref={searchRef}\n size=\"small\"\n className={styles.search}\n placeholder=\"Go to ...\"\n value={query}\n onChange={event => setQuery(event.target.value)}\n onClear={() => setQuery('')}\n aria-label=\"Go to\"\n />\n <div\n className={classNames(styles.results, isSearching && styles.searchResults)}\n >\n {visibleGroups.length === 0 ? (\n <div className={styles.empty}>\n {/*\n * Two different nothings: a search that matched no row, and a host\n * that offered no rows at all. The second is a real state — the\n * catalog is reachable whether or not there is anything in it — and\n * quoting an empty query at the user does not describe it.\n */}\n <Text subdued>\n {isSearching ? (\n <Fragment>\n No navigation items match “{query}”.\n </Fragment>\n ) : (\n 'There are no navigation items to show.'\n )}\n </Text>\n </div>\n ) : (\n <div className={isSearching ? undefined : styles.columns}>\n {visibleGroups.map(group => (\n <div\n key={group.title}\n className={isSearching ? undefined : styles.group}\n >\n {/*\n * Browse uses titled columns. Search stacks matches at full\n * width, keeping only each module's own submenu headings.\n */}\n {!isSearching && (\n <Text\n variant=\"eyebrow\"\n size=\"medium\"\n className={styles.groupTitle}\n >\n {group.title}\n </Text>\n )}\n {group.items.map(item => (\n <CatalogRows\n key={item.id}\n item={item}\n scopeIds={scopeById.get(item.id) ?? [item.id]}\n isPinned={isPinned}\n isLocked={isLocked}\n onToggleModule={toggleModule}\n onTogglePage={togglePage}\n onNavigate={close}\n />\n ))}\n </div>\n ))}\n </div>\n )}\n </div>\n </div>\n </Dialog.Content>\n <NavigationCatalogFooter\n onRestore={\n onResetToDefaults &&\n (() => {\n onResetToDefaults();\n // The control disappears with the host's reset; keep focus in the dialog.\n searchRef.current?.focus();\n })\n }\n />\n </Dialog>\n );\n};\n"],"names":["Button","Dialog","Icon","SearchField","Text","Tooltip","IconLock","IconStar","IconStarBorder","classNames","Fragment","useMemo","useRef","useState","filterCatalogGroups","getCatalogChildren","getCatalogSubmenuGroups","getCounterTag","BadgeTag","useTitanLayoutContext","NavigationCatalogFooter","styles","LockedPin","Trigger","svg","className","lock","Content","style","pointerEvents","PinToggle","pinned","label","onToggle","toggle","event","preventDefault","stopPropagation","delay","appearance","size","icon","star","starActive","aria-label","aria-pressed","data-pendo","onClick","CatalogRows","item","scopeIds","isPinned","isLocked","onToggleModule","onTogglePage","onNavigate","NavigationComponent","submenuGroups","isWholeModule","id","isOnRail","some","pageIds","filter","isFullyPinned","length","every","tag","counter","div","moduleGroup","row","to","link","title","moduleIcon","inline","moduleTitle","data","badge","map","group","variant","submenuTitle","links","child","qualifiedTitle","childPinned","childTag","childLink","childTitle","NavigationCatalog","open","onClose","groups","pinnedIds","lockedIds","onPinnedIdsChange","onResetToDefaults","query","setQuery","isSearching","trim","searchRef","resolvedGroups","visibleGroups","scopeById","Map","flatMap","items","pinnedSet","Set","lockedSet","has","toggleModule","moduleId","scope","get","scopeSet","withoutModule","togglePage","pages","scoped","rest","page","close","dialog","data-cy","content","body","ref","search","placeholder","value","onChange","target","onClear","results","searchResults","empty","subdued","undefined","columns","groupTitle","onRestore","current","focus"],"mappings":";AAAA,SAASA,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAEC,IAAI,EAAEC,OAAO,QAAQ,uBAAuB;AACxF,OAAOC,cAAc,4DAA4D;AACjF,OAAOC,cAAc,4DAA4D;AACjF,OAAOC,oBAAoB,mEAAmE;AAC9F,OAAOC,gBAAgB,aAAa;AACpC,SAAaC,QAAQ,EAAcC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC5E,SACIC,mBAAmB,EACnBC,kBAAkB,EAClBC,uBAAuB,QACpB,gCAAgC;AAEvC,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAASC,QAAQ,QAAQ,kBAAkB;AAE3C,SAASC,qBAAqB,QAAQ,oBAAoB;AAC1D,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,YAAYC,YAAY,mCAAmC;AAE3D,gFAAgF,GAChF,MAAMC,YAAgB,kBAClB,MAACjB;;0BACG,KAACA,QAAQkB,OAAO;0BACZ,cAAA,KAACrB;oBAAKsB,KAAKlB;oBAAUmB,WAAWJ,OAAOK,IAAI;;;0BAE/C,KAACrB,QAAQsB,OAAO;gBAACC,OAAO;oBAAEC,eAAe;gBAAO;0BAAG;;;;AAa3D,MAAMC,YAAgC,CAAC,EAAEC,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAE;IAC9D,MAAMC,SAAS,CAACC;QACZ,sEAAsE;QACtEA,MAAMC,cAAc;QACpBD,MAAME,eAAe;QACrBJ;IACJ;IAEA,qBACI,MAAC5B;QAAQiC,OAAO;;0BACZ,KAACjC,QAAQkB,OAAO;0BACZ,cAAA,KAACvB;oBACGuC,YAAW;oBACXC,MAAK;oBACLC,MAAMV,WAAW,OAAOxB,WAAWC;oBACnCiB,WAAWhB,WAAWY,OAAOqB,IAAI,EAAEX,UAAUV,OAAOsB,UAAU;oB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KAAKU,EAAE;qDAAC;oDAC7CR,UAAUA;oDACVC,UAAUA;oDACVC,gBAAgB6D;oDAChB5D,cAAckE;oDACdjE,YAAYsE;mDAPP5E,KAAKU,EAAE;;;uCAlBfsB,MAAMP,KAAK;;;;;;0BAmC5C,KAACtD;gBACG4H,WACI9C,qBACC,CAAA;wBAEG,0EAA0E;oBAC1EK;oBAFAL;qBAEAK,qBAAAA,UAAU0C,OAAO,cAAjB1C,yCAAAA,mBAAmB2C,KAAK;gBAC5B,CAAA;;;;AAKpB,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"side-nav.test.d.ts","sourceRoot":"","sources":["../../../src/utils/__tests__/side-nav.test.ts"],"names":[],"mappings":""}
|
package/dist/utils/side-nav.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { CounterTagProps } from '../components/counter-tag';
|
|
2
2
|
import { CounterTagData, CounterTagValue } from './counter-tag';
|
|
3
3
|
import { NavigationSubmenuData } from './navigation';
|
|
4
|
+
/**
|
|
5
|
+
* A module with sub-items always routes to the first one, in the nav's existing order, rather
|
|
6
|
+
* than whatever destination the host configured for the module row itself (3.5a). A host-supplied
|
|
7
|
+
* `to` only applies to modules with no submenu.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getModuleDestination(to: string, submenu: NavigationSubmenuData | undefined): string;
|
|
10
|
+
/**
|
|
11
|
+
* Routing a module row to its first sub-item (see `getModuleDestination`) means the row's `to` no
|
|
12
|
+
* longer identifies the module for a host that has no explicit `isActive` of its own — the default
|
|
13
|
+
* "compare href to pathname" behavior would then only match the first sub-item's page, not the rest
|
|
14
|
+
* of the module. Synthesize an equivalent match across the module's own `to` and every sub-item
|
|
15
|
+
* instead, so the row still highlights on any of the module's pages, not just the first.
|
|
16
|
+
*
|
|
17
|
+
* Returns `undefined` when there's nothing to match, so a host can still supply its own `isActive`
|
|
18
|
+
* and take precedence (this only fills the gap left by the default behavior, it doesn't replace it).
|
|
19
|
+
*/
|
|
20
|
+
export declare function getModuleActiveMatcher(to: string, submenu: NavigationSubmenuData | undefined): ((pathname: string) => boolean) | undefined;
|
|
4
21
|
export declare function getSubmenuGroupTag(submenu: NavigationSubmenuData | undefined, defaultTag: CounterTagProps | undefined): CounterTagProps | undefined;
|
|
5
22
|
export declare const getCounterTag: (counter: CounterTagValue | undefined, tag?: CounterTagData) => CounterTagProps | undefined;
|
|
6
23
|
//# sourceMappingURL=side-nav.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"side-nav.d.ts","sourceRoot":"","sources":["../../src/utils/side-nav.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,qBAAqB,GAAG,SAAS,EAC1C,UAAU,EAAE,eAAe,GAAG,SAAS,GACxC,eAAe,GAAG,SAAS,CAyB7B;AAED,eAAO,MAAM,aAAa,GACtB,SAAS,eAAe,GAAG,SAAS,EACpC,MAAM,cAAc,KACrB,eAAe,GAAG,SAIpB,CAAC"}
|
|
1
|
+
{"version":3,"file":"side-nav.d.ts","sourceRoot":"","sources":["../../src/utils/side-nav.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,qBAAqB,GAAG,SAAS,GAC3C,MAAM,CAQR;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAClC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,qBAAqB,GAAG,SAAS,GAC3C,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAS7C;AAED,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,qBAAqB,GAAG,SAAS,EAC1C,UAAU,EAAE,eAAe,GAAG,SAAS,GACxC,eAAe,GAAG,SAAS,CAyB7B;AAED,eAAO,MAAM,aAAa,GACtB,SAAS,eAAe,GAAG,SAAS,EACpC,MAAM,cAAc,KACrB,eAAe,GAAG,SAIpB,CAAC"}
|
package/dist/utils/side-nav.js
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module with sub-items always routes to the first one, in the nav's existing order, rather
|
|
3
|
+
* than whatever destination the host configured for the module row itself (3.5a). A host-supplied
|
|
4
|
+
* `to` only applies to modules with no submenu.
|
|
5
|
+
*/ export function getModuleDestination(to, submenu) {
|
|
6
|
+
var _ref;
|
|
7
|
+
for (const group of (_ref = submenu === null || submenu === void 0 ? void 0 : submenu.groups) !== null && _ref !== void 0 ? _ref : []){
|
|
8
|
+
if (group.links.length > 0) {
|
|
9
|
+
return group.links[0].to;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Routing a module row to its first sub-item (see `getModuleDestination`) means the row's `to` no
|
|
16
|
+
* longer identifies the module for a host that has no explicit `isActive` of its own — the default
|
|
17
|
+
* "compare href to pathname" behavior would then only match the first sub-item's page, not the rest
|
|
18
|
+
* of the module. Synthesize an equivalent match across the module's own `to` and every sub-item
|
|
19
|
+
* instead, so the row still highlights on any of the module's pages, not just the first.
|
|
20
|
+
*
|
|
21
|
+
* Returns `undefined` when there's nothing to match, so a host can still supply its own `isActive`
|
|
22
|
+
* and take precedence (this only fills the gap left by the default behavior, it doesn't replace it).
|
|
23
|
+
*/ export function getModuleActiveMatcher(to, submenu) {
|
|
24
|
+
var _ref;
|
|
25
|
+
const candidates = [
|
|
26
|
+
...to ? [
|
|
27
|
+
to
|
|
28
|
+
] : [],
|
|
29
|
+
...(_ref = submenu === null || submenu === void 0 ? void 0 : submenu.groups.flatMap((group)=>group.links.map((link)=>link.to))) !== null && _ref !== void 0 ? _ref : []
|
|
30
|
+
];
|
|
31
|
+
return candidates.length > 0 ? (pathname)=>candidates.some((candidate)=>pathname.startsWith(candidate)) : undefined;
|
|
32
|
+
}
|
|
1
33
|
export function getSubmenuGroupTag(submenu, defaultTag) {
|
|
2
34
|
if (!submenu) {
|
|
3
35
|
return defaultTag;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/side-nav.ts"],"sourcesContent":["import { CounterTagProps } from '../components/counter-tag';\nimport { CounterTagData, CounterTagValue } from './counter-tag';\nimport { NavigationSubmenuData } from './navigation';\n\nexport function getSubmenuGroupTag(\n submenu: NavigationSubmenuData | undefined,\n defaultTag: CounterTagProps | undefined\n): CounterTagProps | undefined {\n if (!submenu) {\n return defaultTag;\n }\n\n let tagValue: number | boolean | undefined = undefined;\n\n for (const group of submenu.groups) {\n for (const link of group.links) {\n const ltv: number | boolean | undefined = link.counter ?? link.tag?.value;\n\n if (ltv) {\n if (typeof ltv === 'number') {\n if (typeof tagValue !== 'number') {\n tagValue = 0;\n }\n tagValue += ltv;\n } else if (typeof tagValue !== 'number') {\n tagValue = true;\n }\n }\n }\n }\n\n return tagValue ? getCounterTag(tagValue) : defaultTag;\n}\n\nexport const getCounterTag = (\n counter: CounterTagValue | undefined,\n tag?: CounterTagData\n): CounterTagProps | undefined => {\n const value = counter ?? tag?.value;\n\n return value ? { value, className: '' } : undefined;\n};\n"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/side-nav.ts"],"sourcesContent":["import { CounterTagProps } from '../components/counter-tag';\nimport { CounterTagData, CounterTagValue } from './counter-tag';\nimport { NavigationSubmenuData } from './navigation';\n\n/**\n * A module with sub-items always routes to the first one, in the nav's existing order, rather\n * than whatever destination the host configured for the module row itself (3.5a). A host-supplied\n * `to` only applies to modules with no submenu.\n */\nexport function getModuleDestination(\n to: string,\n submenu: NavigationSubmenuData | undefined\n): string {\n for (const group of submenu?.groups ?? []) {\n if (group.links.length > 0) {\n return group.links[0].to;\n }\n }\n\n return to;\n}\n\n/**\n * Routing a module row to its first sub-item (see `getModuleDestination`) means the row's `to` no\n * longer identifies the module for a host that has no explicit `isActive` of its own — the default\n * \"compare href to pathname\" behavior would then only match the first sub-item's page, not the rest\n * of the module. Synthesize an equivalent match across the module's own `to` and every sub-item\n * instead, so the row still highlights on any of the module's pages, not just the first.\n *\n * Returns `undefined` when there's nothing to match, so a host can still supply its own `isActive`\n * and take precedence (this only fills the gap left by the default behavior, it doesn't replace it).\n */\nexport function getModuleActiveMatcher(\n to: string,\n submenu: NavigationSubmenuData | undefined\n): ((pathname: string) => boolean) | undefined {\n const candidates = [\n ...(to ? [to] : []),\n ...(submenu?.groups.flatMap(group => group.links.map(link => link.to)) ?? []),\n ];\n\n return candidates.length > 0\n ? (pathname: string) => candidates.some(candidate => pathname.startsWith(candidate))\n : undefined;\n}\n\nexport function getSubmenuGroupTag(\n submenu: NavigationSubmenuData | undefined,\n defaultTag: CounterTagProps | undefined\n): CounterTagProps | undefined {\n if (!submenu) {\n return defaultTag;\n }\n\n let tagValue: number | boolean | undefined = undefined;\n\n for (const group of submenu.groups) {\n for (const link of group.links) {\n const ltv: number | boolean | undefined = link.counter ?? link.tag?.value;\n\n if (ltv) {\n if (typeof ltv === 'number') {\n if (typeof tagValue !== 'number') {\n tagValue = 0;\n }\n tagValue += ltv;\n } else if (typeof tagValue !== 'number') {\n tagValue = true;\n }\n }\n }\n }\n\n return tagValue ? getCounterTag(tagValue) : defaultTag;\n}\n\nexport const getCounterTag = (\n counter: CounterTagValue | undefined,\n tag?: CounterTagData\n): CounterTagProps | undefined => {\n const value = counter ?? tag?.value;\n\n return value ? { value, className: '' } : undefined;\n};\n"],"names":["getModuleDestination","to","submenu","group","groups","links","length","getModuleActiveMatcher","candidates","flatMap","map","link","pathname","some","candidate","startsWith","undefined","getSubmenuGroupTag","defaultTag","tagValue","ltv","counter","tag","value","getCounterTag","className"],"mappings":"AAIA;;;;CAIC,GACD,OAAO,SAASA,qBACZC,EAAU,EACVC,OAA0C;;IAE1C,KAAK,MAAMC,iBAASD,oBAAAA,8BAAAA,QAASE,MAAM,uCAAI,EAAE,CAAE;QACvC,IAAID,MAAME,KAAK,CAACC,MAAM,GAAG,GAAG;YACxB,OAAOH,MAAME,KAAK,CAAC,EAAE,CAACJ,EAAE;QAC5B;IACJ;IAEA,OAAOA;AACX;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASM,uBACZN,EAAU,EACVC,OAA0C;;IAE1C,MAAMM,aAAa;WACXP,KAAK;YAACA;SAAG,GAAG,EAAE;mBACdC,oBAAAA,8BAAAA,QAASE,MAAM,CAACK,OAAO,CAACN,CAAAA,QAASA,MAAME,KAAK,CAACK,GAAG,CAACC,CAAAA,OAAQA,KAAKV,EAAE,yCAAM,EAAE;KAC/E;IAED,OAAOO,WAAWF,MAAM,GAAG,IACrB,CAACM,WAAqBJ,WAAWK,IAAI,CAACC,CAAAA,YAAaF,SAASG,UAAU,CAACD,cACvEE;AACV;AAEA,OAAO,SAASC,mBACZf,OAA0C,EAC1CgB,UAAuC;IAEvC,IAAI,CAAChB,SAAS;QACV,OAAOgB;IACX;IAEA,IAAIC,WAAyCH;IAE7C,KAAK,MAAMb,SAASD,QAAQE,MAAM,CAAE;QAChC,KAAK,MAAMO,QAAQR,MAAME,KAAK,CAAE;gBACcM;gBAAgBA;YAA1D,MAAMS,OAAoCT,gBAAAA,KAAKU,OAAO,cAAZV,2BAAAA,iBAAgBA,YAAAA,KAAKW,GAAG,cAARX,gCAAAA,UAAUY,KAAK;YAEzE,IAAIH,KAAK;gBACL,IAAI,OAAOA,QAAQ,UAAU;oBACzB,IAAI,OAAOD,aAAa,UAAU;wBAC9BA,WAAW;oBACf;oBACAA,YAAYC;gBAChB,OAAO,IAAI,OAAOD,aAAa,UAAU;oBACrCA,WAAW;gBACf;YACJ;QACJ;IACJ;IAEA,OAAOA,WAAWK,cAAcL,YAAYD;AAChD;AAEA,OAAO,MAAMM,gBAAgB,CACzBH,SACAC;IAEA,MAAMC,QAAQF,oBAAAA,qBAAAA,UAAWC,gBAAAA,0BAAAA,IAAKC,KAAK;IAEnC,OAAOA,QAAQ;QAAEA;QAAOE,WAAW;IAAG,IAAIT;AAC9C,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/navigation",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.5.1",
|
|
4
4
|
"description": "Navigation components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"less": true,
|
|
36
36
|
"webpack": false
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "641fcf58999dd57e39c199ca97fddfc0aa224a4c"
|
|
39
39
|
}
|
|
@@ -133,22 +133,74 @@ it('leaves favorites untouched until the host applies the reset', () => {
|
|
|
133
133
|
const props = renderCatalog();
|
|
134
134
|
click(button('Restore Default Favorites')!);
|
|
135
135
|
click(button('Restore')!);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
* `mixed` here, because two of Marketing's three ids are favourited and not the third.
|
|
139
|
-
*/
|
|
140
|
-
expect(marketingStar().getAttribute('aria-pressed')).toBe('mixed');
|
|
136
|
+
// Fully controlled: the catalog has proposed nothing, so the rows still read as they did.
|
|
137
|
+
expect(marketingStar().getAttribute('aria-pressed')).toBe('true');
|
|
141
138
|
expect(props.onPinnedIdsChange).not.toHaveBeenCalled();
|
|
142
139
|
});
|
|
143
140
|
|
|
144
141
|
it('keeps star edits on onPinnedIdsChange without calling the reset handler', () => {
|
|
145
142
|
const props = renderCatalog();
|
|
146
|
-
// A partly favourited module completes itself rather than clearing: campaigns joins the list.
|
|
147
143
|
click(marketingStar());
|
|
148
|
-
expect(props.onPinnedIdsChange).toHaveBeenCalledWith([
|
|
144
|
+
expect(props.onPinnedIdsChange).toHaveBeenCalledWith([]);
|
|
149
145
|
expect(props.onResetToDefaults).not.toHaveBeenCalled();
|
|
150
146
|
});
|
|
151
147
|
|
|
148
|
+
describe('favourite stars', () => {
|
|
149
|
+
const star = (label: string) =>
|
|
150
|
+
container.querySelector(`button[aria-label="${label}"]`)?.getAttribute('aria-pressed');
|
|
151
|
+
const clickStar = (label: string) =>
|
|
152
|
+
click(container.querySelector(`button[aria-label="${label}"]`)!);
|
|
153
|
+
|
|
154
|
+
it('pins only the page, not its module, when one page is starred', () => {
|
|
155
|
+
const props = renderCatalog({ pinnedIds: ['other'] });
|
|
156
|
+
clickStar('Pin Marketing: Campaigns to the navigation');
|
|
157
|
+
expect(props.onPinnedIdsChange).toHaveBeenCalledWith(['other', 'campaigns']);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('shows a module pinned by its id alone as filled, with every page starred', () => {
|
|
161
|
+
renderCatalog({ pinnedIds: ['marketing'] });
|
|
162
|
+
expect(star('Unpin Marketing from the navigation')).toBe('true');
|
|
163
|
+
expect(star('Unpin Marketing: Overview from the navigation')).toBe('true');
|
|
164
|
+
expect(star('Unpin Marketing: Campaigns from the navigation')).toBe('true');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('shows a module on the rail through one page as mixed, with only that page starred', () => {
|
|
168
|
+
renderCatalog({ pinnedIds: ['overview'] });
|
|
169
|
+
expect(star('Unpin Marketing from the navigation')).toBe('mixed');
|
|
170
|
+
expect(star('Unpin Marketing: Overview from the navigation')).toBe('true');
|
|
171
|
+
expect(star('Pin Marketing: Campaigns to the navigation')).toBe('false');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('shows a module as filled once every page is starred on its own', () => {
|
|
175
|
+
renderCatalog({ pinnedIds: ['overview', 'campaigns'] });
|
|
176
|
+
expect(star('Unpin Marketing from the navigation')).toBe('true');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('removes a partly favourited module and its pages in one click', () => {
|
|
180
|
+
const props = renderCatalog({ pinnedIds: ['other', 'overview'] });
|
|
181
|
+
clickStar('Unpin Marketing from the navigation');
|
|
182
|
+
expect(props.onPinnedIdsChange).toHaveBeenCalledWith(['other']);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('pins an unfavourited module by its id alone', () => {
|
|
186
|
+
const props = renderCatalog({ pinnedIds: [] });
|
|
187
|
+
clickStar('Pin Marketing to the navigation');
|
|
188
|
+
expect(props.onPinnedIdsChange).toHaveBeenCalledWith(['marketing']);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('narrows a whole module to its remaining pages when one page is unstarred', () => {
|
|
192
|
+
const props = renderCatalog({ pinnedIds: ['a', 'marketing', 'b'] });
|
|
193
|
+
clickStar('Unpin Marketing: Overview from the navigation');
|
|
194
|
+
expect(props.onPinnedIdsChange).toHaveBeenCalledWith(['a', 'campaigns', 'b']);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('takes the module off the rail when its last page is unstarred', () => {
|
|
198
|
+
const props = renderCatalog({ pinnedIds: ['overview'] });
|
|
199
|
+
clickStar('Unpin Marketing: Overview from the navigation');
|
|
200
|
+
expect(props.onPinnedIdsChange).toHaveBeenCalledWith([]);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
152
204
|
it('hides restore when the host does not offer one', () => {
|
|
153
205
|
renderCatalog({ onResetToDefaults: undefined });
|
|
154
206
|
expect(button('Restore Default Favorites')).toBeUndefined();
|
|
@@ -401,7 +401,6 @@
|
|
|
401
401
|
background-color: @bg-color;
|
|
402
402
|
|
|
403
403
|
.toggle-wrapper {
|
|
404
|
-
display: flex;
|
|
405
404
|
padding: @spacing-1 @spacing-1 @spacing-1 14px;
|
|
406
405
|
}
|
|
407
406
|
|
|
@@ -620,6 +619,7 @@
|
|
|
620
619
|
|
|
621
620
|
.submenu-popover-title[data-anv][data-anv] {
|
|
622
621
|
color: @color-white;
|
|
622
|
+
font-size: @typescale-2;
|
|
623
623
|
margin-bottom: @spacing-0;
|
|
624
624
|
margin-top: @spacing-1;
|
|
625
625
|
padding: @spacing-1;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { Button, Divider, Icon, Popover, Text, ThemeProvider } from '@servicetitan/anvil2';
|
|
1
|
+
import { Button, Divider, Flex, Icon, Popover, Text, ThemeProvider } from '@servicetitan/anvil2';
|
|
2
2
|
import SvgClose from '@servicetitan/anvil2/assets/icons/material/round/close.svg';
|
|
3
3
|
import SvgCollapseAll from '@servicetitan/anvil2/assets/icons/material/round/unfold_less.svg';
|
|
4
4
|
import SvgExpandAll from '@servicetitan/anvil2/assets/icons/material/round/unfold_more.svg';
|
|
5
5
|
import SvgCollapse from '@servicetitan/anvil2/assets/icons/st/gnav_menu_collapse.svg';
|
|
6
6
|
import SvgExpand from '@servicetitan/anvil2/assets/icons/st/gnav_menu_expand.svg';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
|
-
import { Children, FC, Fragment, ReactElement, isValidElement } from 'react';
|
|
8
|
+
import { Children, FC, Fragment, ReactElement, isValidElement, useCallback, useRef } from 'react';
|
|
9
9
|
import { NavigationItemData, NavigationSubmenuData } from '../../utils/navigation';
|
|
10
10
|
import { NavLinkComponentProps } from '../../utils/navigation-context';
|
|
11
11
|
import { getModuleNotificationCount } from '../../utils/navigation-notifications';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
getCounterTag,
|
|
14
|
+
getModuleActiveMatcher,
|
|
15
|
+
getModuleDestination,
|
|
16
|
+
getSubmenuGroupTag,
|
|
17
|
+
} from '../../utils/side-nav';
|
|
13
18
|
import { PinnedNavigationConfig } from './interface';
|
|
14
19
|
import { NavigationComponentProps } from './interface-internal';
|
|
15
20
|
import { LayoutPlacementContext, useTitanLayoutContext } from './layout-context';
|
|
@@ -219,12 +224,12 @@ export const LayoutSidebar: FC<LayoutSidebarProps> = ({
|
|
|
219
224
|
{!mobile && (
|
|
220
225
|
<ThemeProvider mode="dark" className={Styles.navFooter}>
|
|
221
226
|
<div className={Styles.divider} />
|
|
222
|
-
<
|
|
227
|
+
<Flex direction="column" className={Styles.toggleWrapper}>
|
|
223
228
|
<SideNavigationOptionsToggle
|
|
224
229
|
expanded={barExpanded}
|
|
225
230
|
onExpandedChange={() => onBarExpandChange(!barExpanded)}
|
|
226
231
|
/>
|
|
227
|
-
</
|
|
232
|
+
</Flex>
|
|
228
233
|
</ThemeProvider>
|
|
229
234
|
)}
|
|
230
235
|
</div>
|
|
@@ -242,6 +247,8 @@ const SideNavigationOptionsToggle: FC<{
|
|
|
242
247
|
<Button
|
|
243
248
|
appearance="ghost"
|
|
244
249
|
size="small"
|
|
250
|
+
flexGrow={1}
|
|
251
|
+
justifyContent="flex-start"
|
|
245
252
|
icon={expanded ? SvgCollapse : SvgExpand}
|
|
246
253
|
data-cy="navigation-left-options"
|
|
247
254
|
data-pendo="navigation-left-options"
|
|
@@ -251,7 +258,7 @@ const SideNavigationOptionsToggle: FC<{
|
|
|
251
258
|
onClick={() => onExpandedChange?.(!expanded)}
|
|
252
259
|
/>,
|
|
253
260
|
expanded ? 'Collapse Menu' : 'Expand Menu',
|
|
254
|
-
{ placement: 'right' }
|
|
261
|
+
{ placement: 'right', pointerEventsNone: true }
|
|
255
262
|
);
|
|
256
263
|
|
|
257
264
|
/** Side Navigation menu item */
|
|
@@ -279,13 +286,28 @@ const SideNavigationGroupItem: FC<{
|
|
|
279
286
|
} = useTitanLayoutContext();
|
|
280
287
|
|
|
281
288
|
const tag = getSubmenuGroupTag(item.submenu, getCounterTag(item.counter, item.tag));
|
|
289
|
+
const isActive = item.isActive ?? getModuleActiveMatcher(item.to, item.submenu);
|
|
290
|
+
|
|
291
|
+
/*
|
|
292
|
+
* Some destinations (legacy monolith pages) never fire the route-change signal the popover
|
|
293
|
+
* would otherwise rely on to dismiss itself, leaving it stranded open over the loaded page.
|
|
294
|
+
* Closing explicitly on click, rather than waiting on navigation to settle, works everywhere.
|
|
295
|
+
*/
|
|
296
|
+
const popoverRef = useRef<{ closePopover: () => void }>(null);
|
|
297
|
+
const handleSubmenuLinkClick = useCallback(
|
|
298
|
+
(itemId: string, submenuItemId?: string) => {
|
|
299
|
+
popoverRef.current?.closePopover();
|
|
300
|
+
onNavigationLinkClick?.(itemId, submenuItemId);
|
|
301
|
+
},
|
|
302
|
+
[onNavigationLinkClick]
|
|
303
|
+
);
|
|
282
304
|
|
|
283
305
|
return barExpanded ? (
|
|
284
306
|
<InternalSideNavigationGroup
|
|
285
307
|
id={item.id}
|
|
286
|
-
to={item.to}
|
|
308
|
+
to={getModuleDestination(item.to, item.submenu)}
|
|
287
309
|
title={item.title}
|
|
288
|
-
isActive={
|
|
310
|
+
isActive={isActive}
|
|
289
311
|
icon={item.icon}
|
|
290
312
|
iconActive={item.iconActive}
|
|
291
313
|
className={item.className}
|
|
@@ -304,6 +326,7 @@ const SideNavigationGroupItem: FC<{
|
|
|
304
326
|
</InternalSideNavigationGroup>
|
|
305
327
|
) : (
|
|
306
328
|
<Popover
|
|
329
|
+
ref={popoverRef}
|
|
307
330
|
placement="right-start"
|
|
308
331
|
openOnHover={!touchDevice}
|
|
309
332
|
delay={200}
|
|
@@ -315,9 +338,9 @@ const SideNavigationGroupItem: FC<{
|
|
|
315
338
|
<div {...triggerProps}>
|
|
316
339
|
<InternalSideNavigationLink
|
|
317
340
|
id={item.id}
|
|
318
|
-
to={item.to}
|
|
341
|
+
to={getModuleDestination(item.to, item.submenu)}
|
|
319
342
|
title={item.collapsedTitle ?? item.title}
|
|
320
|
-
isActive={
|
|
343
|
+
isActive={isActive}
|
|
321
344
|
icon={item.icon}
|
|
322
345
|
iconActive={item.iconActive}
|
|
323
346
|
className={classNames(
|
|
@@ -351,6 +374,7 @@ const SideNavigationGroupItem: FC<{
|
|
|
351
374
|
parentId={item.id}
|
|
352
375
|
groups={item.submenu?.groups ?? []}
|
|
353
376
|
navigationComponent={navigationComponent}
|
|
377
|
+
onNavigationLinkClick={handleSubmenuLinkClick}
|
|
354
378
|
/>
|
|
355
379
|
</div>
|
|
356
380
|
</div>
|
|
@@ -95,7 +95,7 @@ export const NavigationCatalogTrigger: FC<NavigationCatalogTriggerProps> = ({
|
|
|
95
95
|
* selector written for a link to match it.
|
|
96
96
|
*/
|
|
97
97
|
'data-cy': 'navigation-catalog-trigger',
|
|
98
|
-
'data-pendo': '
|
|
98
|
+
'data-pendo': 'global-nav-go-to',
|
|
99
99
|
'appearance': 'secondary',
|
|
100
100
|
'size': 'small',
|
|
101
101
|
'aria-label': 'Go to',
|