mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
feat: clear search string and close box after click (#7511)
Now when selecting an item from command menu, the search string is cleared and command menu closed.
This commit is contained in:
parent
932ae2b80f
commit
4eebf49423
@ -179,6 +179,11 @@ export const CommandBar = () => {
|
|||||||
setValue(value);
|
setValue(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const clearSearchValue = () => {
|
||||||
|
onSearchChange('');
|
||||||
|
setShowSuggestions(false);
|
||||||
|
};
|
||||||
|
|
||||||
const hotkey = useKeyboardShortcut(
|
const hotkey = useKeyboardShortcut(
|
||||||
{
|
{
|
||||||
modifiers: ['ctrl'],
|
modifiers: ['ctrl'],
|
||||||
@ -262,14 +267,19 @@ export const CommandBar = () => {
|
|||||||
<CommandFeatures
|
<CommandFeatures
|
||||||
searchString={searchString}
|
searchString={searchString}
|
||||||
setSearchedFlagCount={setSearchedFlagCount}
|
setSearchedFlagCount={setSearchedFlagCount}
|
||||||
|
onClick={clearSearchValue}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CommandResultGroup
|
<CommandResultGroup
|
||||||
groupName={'Projects'}
|
groupName={'Projects'}
|
||||||
icon={'flag'}
|
icon={'flag'}
|
||||||
|
onClick={clearSearchValue}
|
||||||
items={searchedProjects}
|
items={searchedProjects}
|
||||||
/>
|
/>
|
||||||
<CommandPages items={searchedPages} />
|
<CommandPages
|
||||||
|
items={searchedPages}
|
||||||
|
onClick={clearSearchValue}
|
||||||
|
/>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={hasNoResults}
|
condition={hasNoResults}
|
||||||
show={
|
show={
|
||||||
@ -283,8 +293,14 @@ export const CommandBar = () => {
|
|||||||
elseShow={
|
elseShow={
|
||||||
showSuggestions && (
|
showSuggestions && (
|
||||||
<CommandResultsPaper onKeyDownCapture={onKeyDown}>
|
<CommandResultsPaper onKeyDownCapture={onKeyDown}>
|
||||||
<CommandRecent routes={allRoutes} />
|
<CommandRecent
|
||||||
<CommandPageSuggestions routes={allRoutes} />
|
routes={allRoutes}
|
||||||
|
onClick={clearSearchValue}
|
||||||
|
/>
|
||||||
|
<CommandPageSuggestions
|
||||||
|
routes={allRoutes}
|
||||||
|
onClick={clearSearchValue}
|
||||||
|
/>
|
||||||
</CommandResultsPaper>
|
</CommandResultsPaper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,12 @@ import { useEffect } from 'react';
|
|||||||
interface ICommandBar {
|
interface ICommandBar {
|
||||||
searchString: string;
|
searchString: string;
|
||||||
setSearchedFlagCount: (count: number) => void;
|
setSearchedFlagCount: (count: number) => void;
|
||||||
|
onClick: () => void;
|
||||||
}
|
}
|
||||||
export const CommandFeatures = ({
|
export const CommandFeatures = ({
|
||||||
searchString,
|
searchString,
|
||||||
setSearchedFlagCount,
|
setSearchedFlagCount,
|
||||||
|
onClick,
|
||||||
}: ICommandBar) => {
|
}: ICommandBar) => {
|
||||||
const { features = [] } = useFeatureSearch(
|
const { features = [] } = useFeatureSearch(
|
||||||
{
|
{
|
||||||
@ -34,6 +36,11 @@ export const CommandFeatures = ({
|
|||||||
}, [JSON.stringify(flags)]);
|
}, [JSON.stringify(flags)]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CommandResultGroup groupName={'Flags'} icon={'flag'} items={flags} />
|
<CommandResultGroup
|
||||||
|
groupName={'Flags'}
|
||||||
|
icon={'flag'}
|
||||||
|
items={flags}
|
||||||
|
onClick={onClick}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -43,13 +43,15 @@ const pages = [
|
|||||||
|
|
||||||
export const CommandPageSuggestions = ({
|
export const CommandPageSuggestions = ({
|
||||||
routes,
|
routes,
|
||||||
|
onClick,
|
||||||
}: {
|
}: {
|
||||||
routes: Record<string, { path: string; route: string; title: string }>;
|
routes: Record<string, { path: string; route: string; title: string }>;
|
||||||
|
onClick: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const { trackEvent } = usePlausibleTracker();
|
const { trackEvent } = usePlausibleTracker();
|
||||||
const filtered = pages.filter((page) => routes[page]);
|
const filtered = pages.filter((page) => routes[page]);
|
||||||
const pageItems = toListItemData(filtered, routes);
|
const pageItems = toListItemData(filtered, routes);
|
||||||
const onClick = (item: IPageSuggestionItem) => {
|
const onItemClick = (item: IPageSuggestionItem) => {
|
||||||
trackEvent('command-bar', {
|
trackEvent('command-bar', {
|
||||||
props: {
|
props: {
|
||||||
eventType: `click`,
|
eventType: `click`,
|
||||||
@ -58,9 +60,10 @@ export const CommandPageSuggestions = ({
|
|||||||
pageType: item.name,
|
pageType: item.name,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
onClick();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<CommandResultGroup icon='pages' groupName='Pages'>
|
<CommandResultGroup icon='pages' groupName='Pages' onClick={onClick}>
|
||||||
{pageItems.map((item, index) => (
|
{pageItems.map((item, index) => (
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
key={`recently-visited-${index}`}
|
key={`recently-visited-${index}`}
|
||||||
@ -68,7 +71,7 @@ export const CommandPageSuggestions = ({
|
|||||||
component={Link}
|
component={Link}
|
||||||
to={item.path}
|
to={item.path}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onClick(item);
|
onItemClick(item);
|
||||||
}}
|
}}
|
||||||
sx={listItemButtonStyle}
|
sx={listItemButtonStyle}
|
||||||
>
|
>
|
||||||
|
@ -13,13 +13,15 @@ import { IconRenderer } from 'component/layout/MainLayout/NavigationSidebar/Icon
|
|||||||
|
|
||||||
export const CommandPages = ({
|
export const CommandPages = ({
|
||||||
items,
|
items,
|
||||||
|
onClick,
|
||||||
}: {
|
}: {
|
||||||
items: CommandResultGroupItem[];
|
items: CommandResultGroupItem[];
|
||||||
|
onClick: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const { trackEvent } = usePlausibleTracker();
|
const { trackEvent } = usePlausibleTracker();
|
||||||
const groupName = 'Pages';
|
const groupName = 'Pages';
|
||||||
|
|
||||||
const onClick = (item: CommandResultGroupItem) => {
|
const onItemClick = (item: CommandResultGroupItem) => {
|
||||||
trackEvent('command-bar', {
|
trackEvent('command-bar', {
|
||||||
props: {
|
props: {
|
||||||
eventType: `click`,
|
eventType: `click`,
|
||||||
@ -28,9 +30,14 @@ export const CommandPages = ({
|
|||||||
...(groupName === 'Pages' && { pageType: item.name }),
|
...(groupName === 'Pages' && { pageType: item.name }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
onClick();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<CommandResultGroup groupName={'Pages'} icon={'default'}>
|
<CommandResultGroup
|
||||||
|
groupName={'Pages'}
|
||||||
|
icon={'default'}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
{items.map((item, index) => (
|
{items.map((item, index) => (
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
key={`command-result-group-pages-${index}`}
|
key={`command-result-group-pages-${index}`}
|
||||||
@ -38,7 +45,7 @@ export const CommandPages = ({
|
|||||||
component={Link}
|
component={Link}
|
||||||
to={item.link}
|
to={item.link}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onClick(item);
|
onItemClick(item);
|
||||||
}}
|
}}
|
||||||
sx={listItemButtonStyle}
|
sx={listItemButtonStyle}
|
||||||
>
|
>
|
||||||
|
@ -42,7 +42,9 @@ const toListItemButton = (
|
|||||||
|
|
||||||
export const CommandRecent = ({
|
export const CommandRecent = ({
|
||||||
routes,
|
routes,
|
||||||
|
onClick,
|
||||||
}: {
|
}: {
|
||||||
|
onClick: () => void;
|
||||||
routes: Record<string, { path: string; route: string; title: string }>;
|
routes: Record<string, { path: string; route: string; title: string }>;
|
||||||
}) => {
|
}) => {
|
||||||
const { lastVisited } = useRecentlyVisited();
|
const { lastVisited } = useRecentlyVisited();
|
||||||
@ -50,7 +52,11 @@ export const CommandRecent = ({
|
|||||||
toListItemButton(item, routes, index),
|
toListItemButton(item, routes, index),
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<CommandResultGroup icon='default' groupName='Quick suggestions'>
|
<CommandResultGroup
|
||||||
|
icon='default'
|
||||||
|
groupName='Quick suggestions'
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
<List>{buttons}</List>
|
<List>{buttons}</List>
|
||||||
</CommandResultGroup>
|
</CommandResultGroup>
|
||||||
);
|
);
|
||||||
|
@ -180,6 +180,7 @@ interface CommandResultGroupProps {
|
|||||||
icon: string;
|
icon: string;
|
||||||
groupName: string;
|
groupName: string;
|
||||||
items?: CommandResultGroupItem[];
|
items?: CommandResultGroupItem[];
|
||||||
|
onClick: () => void;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +188,7 @@ export const CommandResultGroup = ({
|
|||||||
icon,
|
icon,
|
||||||
groupName,
|
groupName,
|
||||||
items,
|
items,
|
||||||
|
onClick,
|
||||||
children,
|
children,
|
||||||
}: CommandResultGroupProps) => {
|
}: CommandResultGroupProps) => {
|
||||||
const { trackEvent } = usePlausibleTracker();
|
const { trackEvent } = usePlausibleTracker();
|
||||||
@ -199,7 +201,7 @@ export const CommandResultGroup = ({
|
|||||||
|
|
||||||
const slicedItems = items?.slice(0, 3);
|
const slicedItems = items?.slice(0, 3);
|
||||||
|
|
||||||
const onClick = (item: CommandResultGroupItem) => {
|
const onItemClick = (item: CommandResultGroupItem) => {
|
||||||
trackEvent('command-bar', {
|
trackEvent('command-bar', {
|
||||||
props: {
|
props: {
|
||||||
eventType: `click`,
|
eventType: `click`,
|
||||||
@ -208,6 +210,7 @@ export const CommandResultGroup = ({
|
|||||||
...(groupName === 'Pages' && { pageType: item.name }),
|
...(groupName === 'Pages' && { pageType: item.name }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
onClick();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -222,8 +225,9 @@ export const CommandResultGroup = ({
|
|||||||
key={`command-result-group-${groupName}-${index}`}
|
key={`command-result-group-${groupName}-${index}`}
|
||||||
dense={true}
|
dense={true}
|
||||||
component={Link}
|
component={Link}
|
||||||
onClick={() => {
|
onClick={(e) => {
|
||||||
onClick(item);
|
e.stopPropagation();
|
||||||
|
onItemClick(item);
|
||||||
}}
|
}}
|
||||||
to={item.link}
|
to={item.link}
|
||||||
sx={listItemButtonStyle}
|
sx={listItemButtonStyle}
|
||||||
|
Loading…
Reference in New Issue
Block a user