From 990ea1ffb2e198e0ae9cf47b6de1fd5c0b7ede85 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Wed, 3 Jul 2024 14:41:23 +0300 Subject: [PATCH] feat: quick suggestions click close (#7533) Now recently visited projects, features, pages will also close the command bar. --- .../commandBar/CommandQuickSuggestions.tsx | 12 +++++- .../RecentlyVisited/CommandResultGroup.tsx | 38 ++++++++++++++----- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/frontend/src/component/commandBar/CommandQuickSuggestions.tsx b/frontend/src/component/commandBar/CommandQuickSuggestions.tsx index ad4e9ea54d..42307252b4 100644 --- a/frontend/src/component/commandBar/CommandQuickSuggestions.tsx +++ b/frontend/src/component/commandBar/CommandQuickSuggestions.tsx @@ -13,6 +13,7 @@ const toListItemButton = ( item: LastViewedPage, routes: Record, index: number, + onClick: () => void, ) => { const key = `recently-visited-${index}`; if (item.featureId && item.projectId) { @@ -21,6 +22,7 @@ const toListItemButton = ( key={key} featureId={item.featureId} projectId={item.projectId} + onClick={onClick} /> ); } @@ -29,13 +31,19 @@ const toListItemButton = ( ); } if (!item.pathName) return null; const name = routes[item.pathName]?.title ?? item.pathName; return ( - + ); }; @@ -48,7 +56,7 @@ export const CommandQuickSuggestions = ({ }) => { const { lastVisited } = useRecentlyVisited(); const buttons = lastVisited.map((item, index) => - toListItemButton(item, routes, index), + toListItemButton(item, routes, index, onClick), ); return ( { +const ButtonItemIcon = ({ + path, +}: { + path: string; +}) => { if (path === '/projects') { return ; } @@ -68,10 +72,16 @@ export const RecentlyVisitedPathButton = ({ path, key, name, -}: { path: string; key: string; name: string }) => { + onClick, +}: { + path: string; + key: string; + name: string; + onClick: () => void; +}) => { const { trackEvent } = usePlausibleTracker(); - const onClick = () => { + const onItemClick = () => { trackEvent('command-bar', { props: { eventType: `click`, @@ -80,6 +90,7 @@ export const RecentlyVisitedPathButton = ({ pageType: name, }, }); + onClick(); }; return ( @@ -89,7 +100,7 @@ export const RecentlyVisitedPathButton = ({ component={Link} to={path} sx={listItemButtonStyle} - onClick={onClick} + onClick={onItemClick} > @@ -106,12 +117,17 @@ export const RecentlyVisitedPathButton = ({ export const RecentlyVisitedProjectButton = ({ projectId, key, -}: { projectId: string; key: string }) => { + onClick, +}: { + projectId: string; + key: string; + onClick: () => void; +}) => { const { trackEvent } = usePlausibleTracker(); const { project, loading } = useProjectOverview(projectId); const projectDeleted = !project.name && !loading; - const onClick = () => { + const onItemClick = () => { trackEvent('command-bar', { props: { eventType: `click`, @@ -119,6 +135,7 @@ export const RecentlyVisitedProjectButton = ({ eventTarget: 'Projects', }, }); + onClick(); }; if (projectDeleted) return null; @@ -129,7 +146,7 @@ export const RecentlyVisitedProjectButton = ({ component={Link} to={`/projects/${projectId}`} sx={listItemButtonStyle} - onClick={onClick} + onClick={onItemClick} > @@ -147,12 +164,14 @@ export const RecentlyVisitedFeatureButton = ({ key, projectId, featureId, + onClick, }: { key: string; projectId: string; featureId: string; + onClick: () => void; }) => { - const onClick = () => { + const onItemClick = () => { const { trackEvent } = usePlausibleTracker(); trackEvent('command-bar', { @@ -162,6 +181,7 @@ export const RecentlyVisitedFeatureButton = ({ eventTarget: 'Flags', }, }); + onClick(); }; return ( {'flag'}