mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
f42e74e7c5
Now we have nice logical naming ![image](https://github.com/Unleash/unleash/assets/964450/c24041bc-db94-463e-aa9c-d7ecd484ab12)
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import {
|
|
CommandResultGroup,
|
|
RecentlyVisitedFeatureButton,
|
|
RecentlyVisitedPathButton,
|
|
RecentlyVisitedProjectButton,
|
|
} from './RecentlyVisited/CommandResultGroup';
|
|
import {
|
|
useRecentlyVisited,
|
|
type LastViewedPage,
|
|
} from 'hooks/useRecentlyVisited';
|
|
|
|
const toListItemButton = (
|
|
item: LastViewedPage,
|
|
routes: Record<string, { path: string; route: string; title: string }>,
|
|
index: number,
|
|
) => {
|
|
const key = `recently-visited-${index}`;
|
|
if (item.featureId && item.projectId) {
|
|
return (
|
|
<RecentlyVisitedFeatureButton
|
|
key={key}
|
|
featureId={item.featureId}
|
|
projectId={item.projectId}
|
|
/>
|
|
);
|
|
}
|
|
if (item.projectId) {
|
|
return (
|
|
<RecentlyVisitedProjectButton
|
|
key={key}
|
|
projectId={item.projectId}
|
|
/>
|
|
);
|
|
}
|
|
if (!item.pathName) return null;
|
|
const name = routes[item.pathName]?.title ?? item.pathName;
|
|
return (
|
|
<RecentlyVisitedPathButton key={key} path={item.pathName} name={name} />
|
|
);
|
|
};
|
|
|
|
export const CommandQuickSuggestions = ({
|
|
routes,
|
|
onClick,
|
|
}: {
|
|
onClick: () => void;
|
|
routes: Record<string, { path: string; route: string; title: string }>;
|
|
}) => {
|
|
const { lastVisited } = useRecentlyVisited();
|
|
const buttons = lastVisited.map((item, index) =>
|
|
toListItemButton(item, routes, index),
|
|
);
|
|
return (
|
|
<CommandResultGroup
|
|
icon='default'
|
|
groupName='Quick suggestions'
|
|
onClick={onClick}
|
|
>
|
|
{buttons}
|
|
</CommandResultGroup>
|
|
);
|
|
};
|