REDROOM
PHP 8.2.30
Path:
Logout
Edit File
Size: 2.59 KB
Close
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/frontend/hooks/use-navigation-resources.ts
Text
Base64
import { useLocation, useNavigate } from 'react-router' /* eslint-disable no-param-reassign */ import type { IconProps, NavigationElementWithChildrenProps, NavigationProps, } from '@adminjs/design-system' import { useMemo } from 'react' import { useTranslation } from '../hooks/use-translation.js' import { ResourceJSON } from '../interfaces/index.js' import useLocalStorage from './use-local-storage/use-local-storage.js' const isSelected = (href, location): boolean => { const regExp = new RegExp(`${href}($|/)`) return !!location.pathname.match(regExp) } export function useNavigationResources( resources: Array<ResourceJSON>, ): NavigationProps['elements'] { const [openElements, setOpenElements] = useLocalStorage<Record<string, boolean>>('sidebarElements', {}) const navigate = useNavigate() const location = useLocation() const { translateLabel } = useTranslation() const enrichResource = useMemo(() => ( resource: ResourceJSON, icon?: IconProps['icon'], ): NavigationElementWithChildrenProps => ({ href: resource.href || undefined, icon, isSelected: isSelected(resource.href, location), label: translateLabel(resource.name, resource.id), id: resource.id, onClick: (event): void => { if (resource.href) { event.preventDefault() navigate(resource.href) } }, }), [location, navigate]) // grouping resources into parents const map = resources // first filter out resources which are not visible .filter((res) => res.href && res.navigation?.show !== false) .reduce((memo, resource) => { // in case resource has the same name as parent we namespace it wit "resource-"" const key = resource.navigation?.name || ['resource', resource.name].join('-') if (!resource.navigation || resource.navigation.name === null) { memo[key] = enrichResource(resource, resource.navigation?.icon) } else if (memo[key] && memo[key].elements && resource.navigation?.name) { memo[key].label = translateLabel(resource.navigation?.name) memo[key].elements?.push?.(enrichResource(resource)) } else { memo[key] = { elements: [enrichResource(resource)], label: translateLabel(resource.navigation?.name), icon: resource.navigation?.icon, onClick: (): void => setOpenElements({ ...openElements, [key]: !openElements[key], }), isOpen: !!openElements[key], } } return memo }, {} as Record<string, NavigationElementWithChildrenProps>) return Object.values(map) } export default useNavigationResources
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 6 × Files: 10
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
use-action
DIR
-
drwxr-xr-x
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-local-storage
DIR
-
drwxr-xr-x
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-record
DIR
-
drwxr-xr-x
2026-02-28 00:32:50
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-records
DIR
-
drwxr-xr-x
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-resource
DIR
-
drwxr-xr-x
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-selected-records
DIR
-
drwxr-xr-x
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
index.ts
550 B
lrw-r--r--
2026-02-28 00:32:28
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-current-admin.ts
1.52 KB
lrw-r--r--
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-filter-drawer.tsx
946 B
lrw-r--r--
2026-02-28 00:32:50
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-history-listen.ts
1.13 KB
lrw-r--r--
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-modal.doc.md
3.07 KB
lrw-r--r--
2026-02-28 00:31:56
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-modal.ts
2.28 KB
lrw-r--r--
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-navigation-resources.ts
2.59 KB
lrw-r--r--
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-notice.ts
890 B
lrw-r--r--
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-query-params.ts
2.39 KB
lrw-r--r--
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
use-translation.ts
1.65 KB
lrw-r--r--
2026-02-28 00:32:46
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).