1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: now able to search pages (#7446)

Now can search pages
This commit is contained in:
Jaanus Sellin 2024-06-25 14:29:36 +02:00 committed by GitHub
parent ed7f917df6
commit ed9d0cccbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -83,6 +83,12 @@ const StyledClose = styled(Close)(({ theme }) => ({
fontSize: theme.typography.body1.fontSize, fontSize: theme.typography.body1.fontSize,
})); }));
interface IPageRouteInfo {
path: string;
route: string;
title: string;
}
export const CommandBar = () => { export const CommandBar = () => {
const searchInputRef = useRef<HTMLInputElement>(null); const searchInputRef = useRef<HTMLInputElement>(null);
const searchContainerRef = useRef<HTMLInputElement>(null); const searchContainerRef = useRef<HTMLInputElement>(null);
@ -91,12 +97,12 @@ export const CommandBar = () => {
const [searchedProjects, setSearchedProjects] = useState< const [searchedProjects, setSearchedProjects] = useState<
CommandResultGroupItem[] CommandResultGroupItem[]
>([]); >([]);
const [searchedPages, setSearchedPages] = useState<
CommandResultGroupItem[]
>([]);
const { lastVisited } = useRecentlyVisited(); const { lastVisited } = useRecentlyVisited();
const { routes } = useRoutes(); const { routes } = useRoutes();
const allRoutes: Record< const allRoutes: Record<string, IPageRouteInfo> = {};
string,
{ path: string; route: string; title: string }
> = {};
for (const route of [ for (const route of [
...routes.mainNavRoutes, ...routes.mainNavRoutes,
...routes.adminRoutes, ...routes.adminRoutes,
@ -139,6 +145,15 @@ export const CommandBar = () => {
})); }));
setSearchedProjects(mappedProjects); setSearchedProjects(mappedProjects);
const filteredPages = Object.values(allRoutes).filter((route) =>
route.title.toLowerCase().includes(query.toLowerCase()),
);
const mappedPages = filteredPages.map((page) => ({
name: page.title,
link: page.path,
}));
setSearchedPages(mappedPages);
}, 200); }, 200);
const onSearchChange = (value: string) => { const onSearchChange = (value: string) => {
@ -235,6 +250,11 @@ export const CommandBar = () => {
icon={'flag'} icon={'flag'}
items={searchedProjects} items={searchedProjects}
/> />
<CommandResultGroup
groupName={'Pages'}
icon={'flag'}
items={searchedPages}
/>
</CommandResultsPaper> </CommandResultsPaper>
} }
elseShow={ elseShow={