mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	feat: quick suggestions click close (#7533)
Now recently visited projects, features, pages will also close the command bar.
This commit is contained in:
		
							parent
							
								
									fc95d459d0
								
							
						
					
					
						commit
						990ea1ffb2
					
				| @ -13,6 +13,7 @@ const toListItemButton = ( | |||||||
|     item: LastViewedPage, |     item: LastViewedPage, | ||||||
|     routes: Record<string, { path: string; route: string; title: string }>, |     routes: Record<string, { path: string; route: string; title: string }>, | ||||||
|     index: number, |     index: number, | ||||||
|  |     onClick: () => void, | ||||||
| ) => { | ) => { | ||||||
|     const key = `recently-visited-${index}`; |     const key = `recently-visited-${index}`; | ||||||
|     if (item.featureId && item.projectId) { |     if (item.featureId && item.projectId) { | ||||||
| @ -21,6 +22,7 @@ const toListItemButton = ( | |||||||
|                 key={key} |                 key={key} | ||||||
|                 featureId={item.featureId} |                 featureId={item.featureId} | ||||||
|                 projectId={item.projectId} |                 projectId={item.projectId} | ||||||
|  |                 onClick={onClick} | ||||||
|             /> |             /> | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| @ -29,13 +31,19 @@ const toListItemButton = ( | |||||||
|             <RecentlyVisitedProjectButton |             <RecentlyVisitedProjectButton | ||||||
|                 key={key} |                 key={key} | ||||||
|                 projectId={item.projectId} |                 projectId={item.projectId} | ||||||
|  |                 onClick={onClick} | ||||||
|             /> |             /> | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
|     if (!item.pathName) return null; |     if (!item.pathName) return null; | ||||||
|     const name = routes[item.pathName]?.title ?? item.pathName; |     const name = routes[item.pathName]?.title ?? item.pathName; | ||||||
|     return ( |     return ( | ||||||
|         <RecentlyVisitedPathButton key={key} path={item.pathName} name={name} /> |         <RecentlyVisitedPathButton | ||||||
|  |             key={key} | ||||||
|  |             path={item.pathName} | ||||||
|  |             name={name} | ||||||
|  |             onClick={onClick} | ||||||
|  |         /> | ||||||
|     ); |     ); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| @ -48,7 +56,7 @@ export const CommandQuickSuggestions = ({ | |||||||
| }) => { | }) => { | ||||||
|     const { lastVisited } = useRecentlyVisited(); |     const { lastVisited } = useRecentlyVisited(); | ||||||
|     const buttons = lastVisited.map((item, index) => |     const buttons = lastVisited.map((item, index) => | ||||||
|         toListItemButton(item, routes, index), |         toListItemButton(item, routes, index, onClick), | ||||||
|     ); |     ); | ||||||
|     return ( |     return ( | ||||||
|         <CommandResultGroup |         <CommandResultGroup | ||||||
|  | |||||||
| @ -50,7 +50,11 @@ export interface CommandResultGroupItem { | |||||||
|     description?: string | null; |     description?: string | null; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const ButtonItemIcon = ({ path }: { path: string }) => { | const ButtonItemIcon = ({ | ||||||
|  |     path, | ||||||
|  | }: { | ||||||
|  |     path: string; | ||||||
|  | }) => { | ||||||
|     if (path === '/projects') { |     if (path === '/projects') { | ||||||
|         return <StyledProjectIcon />; |         return <StyledProjectIcon />; | ||||||
|     } |     } | ||||||
| @ -68,10 +72,16 @@ export const RecentlyVisitedPathButton = ({ | |||||||
|     path, |     path, | ||||||
|     key, |     key, | ||||||
|     name, |     name, | ||||||
| }: { path: string; key: string; name: string }) => { |     onClick, | ||||||
|  | }: { | ||||||
|  |     path: string; | ||||||
|  |     key: string; | ||||||
|  |     name: string; | ||||||
|  |     onClick: () => void; | ||||||
|  | }) => { | ||||||
|     const { trackEvent } = usePlausibleTracker(); |     const { trackEvent } = usePlausibleTracker(); | ||||||
| 
 | 
 | ||||||
|     const onClick = () => { |     const onItemClick = () => { | ||||||
|         trackEvent('command-bar', { |         trackEvent('command-bar', { | ||||||
|             props: { |             props: { | ||||||
|                 eventType: `click`, |                 eventType: `click`, | ||||||
| @ -80,6 +90,7 @@ export const RecentlyVisitedPathButton = ({ | |||||||
|                 pageType: name, |                 pageType: name, | ||||||
|             }, |             }, | ||||||
|         }); |         }); | ||||||
|  |         onClick(); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     return ( |     return ( | ||||||
| @ -89,7 +100,7 @@ export const RecentlyVisitedPathButton = ({ | |||||||
|             component={Link} |             component={Link} | ||||||
|             to={path} |             to={path} | ||||||
|             sx={listItemButtonStyle} |             sx={listItemButtonStyle} | ||||||
|             onClick={onClick} |             onClick={onItemClick} | ||||||
|         > |         > | ||||||
|             <StyledListItemIcon> |             <StyledListItemIcon> | ||||||
|                 <ButtonItemIcon path={path} /> |                 <ButtonItemIcon path={path} /> | ||||||
| @ -106,12 +117,17 @@ export const RecentlyVisitedPathButton = ({ | |||||||
| export const RecentlyVisitedProjectButton = ({ | export const RecentlyVisitedProjectButton = ({ | ||||||
|     projectId, |     projectId, | ||||||
|     key, |     key, | ||||||
| }: { projectId: string; key: string }) => { |     onClick, | ||||||
|  | }: { | ||||||
|  |     projectId: string; | ||||||
|  |     key: string; | ||||||
|  |     onClick: () => void; | ||||||
|  | }) => { | ||||||
|     const { trackEvent } = usePlausibleTracker(); |     const { trackEvent } = usePlausibleTracker(); | ||||||
|     const { project, loading } = useProjectOverview(projectId); |     const { project, loading } = useProjectOverview(projectId); | ||||||
|     const projectDeleted = !project.name && !loading; |     const projectDeleted = !project.name && !loading; | ||||||
| 
 | 
 | ||||||
|     const onClick = () => { |     const onItemClick = () => { | ||||||
|         trackEvent('command-bar', { |         trackEvent('command-bar', { | ||||||
|             props: { |             props: { | ||||||
|                 eventType: `click`, |                 eventType: `click`, | ||||||
| @ -119,6 +135,7 @@ export const RecentlyVisitedProjectButton = ({ | |||||||
|                 eventTarget: 'Projects', |                 eventTarget: 'Projects', | ||||||
|             }, |             }, | ||||||
|         }); |         }); | ||||||
|  |         onClick(); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     if (projectDeleted) return null; |     if (projectDeleted) return null; | ||||||
| @ -129,7 +146,7 @@ export const RecentlyVisitedProjectButton = ({ | |||||||
|             component={Link} |             component={Link} | ||||||
|             to={`/projects/${projectId}`} |             to={`/projects/${projectId}`} | ||||||
|             sx={listItemButtonStyle} |             sx={listItemButtonStyle} | ||||||
|             onClick={onClick} |             onClick={onItemClick} | ||||||
|         > |         > | ||||||
|             <StyledListItemIcon> |             <StyledListItemIcon> | ||||||
|                 <StyledProjectIcon /> |                 <StyledProjectIcon /> | ||||||
| @ -147,12 +164,14 @@ export const RecentlyVisitedFeatureButton = ({ | |||||||
|     key, |     key, | ||||||
|     projectId, |     projectId, | ||||||
|     featureId, |     featureId, | ||||||
|  |     onClick, | ||||||
| }: { | }: { | ||||||
|     key: string; |     key: string; | ||||||
|     projectId: string; |     projectId: string; | ||||||
|     featureId: string; |     featureId: string; | ||||||
|  |     onClick: () => void; | ||||||
| }) => { | }) => { | ||||||
|     const onClick = () => { |     const onItemClick = () => { | ||||||
|         const { trackEvent } = usePlausibleTracker(); |         const { trackEvent } = usePlausibleTracker(); | ||||||
| 
 | 
 | ||||||
|         trackEvent('command-bar', { |         trackEvent('command-bar', { | ||||||
| @ -162,6 +181,7 @@ export const RecentlyVisitedFeatureButton = ({ | |||||||
|                 eventTarget: 'Flags', |                 eventTarget: 'Flags', | ||||||
|             }, |             }, | ||||||
|         }); |         }); | ||||||
|  |         onClick(); | ||||||
|     }; |     }; | ||||||
|     return ( |     return ( | ||||||
|         <ListItemButton |         <ListItemButton | ||||||
| @ -170,7 +190,7 @@ export const RecentlyVisitedFeatureButton = ({ | |||||||
|             component={Link} |             component={Link} | ||||||
|             to={`/projects/${projectId}/features/${featureId}`} |             to={`/projects/${projectId}/features/${featureId}`} | ||||||
|             sx={listItemButtonStyle} |             sx={listItemButtonStyle} | ||||||
|             onClick={onClick} |             onClick={onItemClick} | ||||||
|         > |         > | ||||||
|             <StyledListItemIcon> |             <StyledListItemIcon> | ||||||
|                 <Icon>{'flag'}</Icon> |                 <Icon>{'flag'}</Icon> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user