mirror of https://github.com/buster-so/buster.git
close on select false for favorites
This commit is contained in:
parent
2a0b727e17
commit
ac6b63bd6d
|
@ -89,7 +89,12 @@ export const useSaveToDashboardDropdownContent = ({
|
||||||
value: dashboard.id,
|
value: dashboard.id,
|
||||||
label: dashboard.name || 'New dashboard',
|
label: dashboard.name || 'New dashboard',
|
||||||
selected: selectedDashboards.some((d) => d === dashboard.id),
|
selected: selectedDashboards.some((d) => d === dashboard.id),
|
||||||
onClick: () => onClickItem(dashboard),
|
closeOnSelect: false,
|
||||||
|
onClick: (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
onClickItem(dashboard);
|
||||||
|
},
|
||||||
link: createBusterRoute({
|
link: createBusterRoute({
|
||||||
route: BusterRoutes.APP_DASHBOARD_ID,
|
route: BusterRoutes.APP_DASHBOARD_ID,
|
||||||
dashboardId: dashboard.id
|
dashboardId: dashboard.id
|
||||||
|
|
|
@ -81,7 +81,8 @@ export const useFavoriteStar = ({
|
||||||
return userFavorites?.some((favorite) => favorite.id === id);
|
return userFavorites?.some((favorite) => favorite.id === id);
|
||||||
}, [userFavorites, id]);
|
}, [userFavorites, id]);
|
||||||
|
|
||||||
const onFavoriteClick = useMemoizedFn(async (e?: React.MouseEvent<HTMLButtonElement>) => {
|
const onFavoriteClick = useMemoizedFn(
|
||||||
|
async (e?: React.MouseEvent<HTMLButtonElement> | React.MouseEvent<HTMLDivElement>) => {
|
||||||
e?.stopPropagation();
|
e?.stopPropagation();
|
||||||
e?.preventDefault();
|
e?.preventDefault();
|
||||||
if (!isFavorited) {
|
if (!isFavorited) {
|
||||||
|
@ -95,7 +96,8 @@ export const useFavoriteStar = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
return await removeItemFromFavorite([id]);
|
return await removeItemFromFavorite([id]);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
|
|
@ -63,7 +63,8 @@ export const useFavoriteMetricSelectMenu = ({ metricId }: { metricId: string })
|
||||||
label: isFavorited ? 'Remove from favorites' : 'Add to favorites',
|
label: isFavorited ? 'Remove from favorites' : 'Add to favorites',
|
||||||
value: 'add-to-favorites',
|
value: 'add-to-favorites',
|
||||||
icon: isFavorited ? <StarFilled /> : <Star />,
|
icon: isFavorited ? <StarFilled /> : <Star />,
|
||||||
onClick: onFavoriteClick
|
onClick: onFavoriteClick,
|
||||||
|
closeOnSelect: false
|
||||||
}),
|
}),
|
||||||
[isFavorited, onFavoriteClick]
|
[isFavorited, onFavoriteClick]
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,10 +15,6 @@ const meta: Meta<typeof Dropdown> = {
|
||||||
layout: 'centered'
|
layout: 'centered'
|
||||||
},
|
},
|
||||||
argTypes: {
|
argTypes: {
|
||||||
closeOnSelect: {
|
|
||||||
control: 'boolean',
|
|
||||||
defaultValue: true
|
|
||||||
},
|
|
||||||
align: {
|
align: {
|
||||||
control: 'select',
|
control: 'select',
|
||||||
options: ['start', 'center', 'end'],
|
options: ['start', 'center', 'end'],
|
||||||
|
|
|
@ -31,7 +31,8 @@ export interface DropdownItem<T = string> {
|
||||||
secondaryLabel?: string;
|
secondaryLabel?: string;
|
||||||
value: T;
|
value: T;
|
||||||
shortcut?: string;
|
shortcut?: string;
|
||||||
onClick?: () => void;
|
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
|
||||||
|
closeOnSelect?: boolean; //default is true
|
||||||
icon?: React.ReactNode;
|
icon?: React.ReactNode;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
|
@ -52,7 +53,6 @@ export interface DropdownProps<T = string> extends DropdownMenuProps {
|
||||||
items: DropdownItems<T>;
|
items: DropdownItems<T>;
|
||||||
selectType?: 'single' | 'multiple' | 'none';
|
selectType?: 'single' | 'multiple' | 'none';
|
||||||
menuHeader?: string | React.ReactNode; //if string it will render a search box
|
menuHeader?: string | React.ReactNode; //if string it will render a search box
|
||||||
closeOnSelect?: boolean;
|
|
||||||
onSelect?: (value: T) => void;
|
onSelect?: (value: T) => void;
|
||||||
align?: 'start' | 'center' | 'end';
|
align?: 'start' | 'center' | 'end';
|
||||||
side?: 'top' | 'right' | 'bottom' | 'left';
|
side?: 'top' | 'right' | 'bottom' | 'left';
|
||||||
|
@ -81,7 +81,6 @@ export const DropdownBase = <T,>({
|
||||||
selectType = 'none',
|
selectType = 'none',
|
||||||
menuHeader,
|
menuHeader,
|
||||||
contentClassName = '',
|
contentClassName = '',
|
||||||
closeOnSelect = true,
|
|
||||||
onSelect,
|
onSelect,
|
||||||
children,
|
children,
|
||||||
align = 'start',
|
align = 'start',
|
||||||
|
@ -114,7 +113,6 @@ export const DropdownBase = <T,>({
|
||||||
items={items}
|
items={items}
|
||||||
selectType={selectType}
|
selectType={selectType}
|
||||||
menuHeader={menuHeader}
|
menuHeader={menuHeader}
|
||||||
closeOnSelect={closeOnSelect}
|
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
showIndex={showIndex}
|
showIndex={showIndex}
|
||||||
emptyStateText={emptyStateText}
|
emptyStateText={emptyStateText}
|
||||||
|
@ -135,7 +133,6 @@ export const DropdownContent = <T,>({
|
||||||
items,
|
items,
|
||||||
selectType,
|
selectType,
|
||||||
menuHeader,
|
menuHeader,
|
||||||
closeOnSelect = true,
|
|
||||||
showIndex = false,
|
showIndex = false,
|
||||||
emptyStateText = 'No items found',
|
emptyStateText = 'No items found',
|
||||||
footerContent,
|
footerContent,
|
||||||
|
@ -198,7 +195,7 @@ export const DropdownContent = <T,>({
|
||||||
if (!disabled && onSelect) {
|
if (!disabled && onSelect) {
|
||||||
onSelect(item.value);
|
onSelect(item.value);
|
||||||
// Close the dropdown if closeOnSelect is true
|
// Close the dropdown if closeOnSelect is true
|
||||||
if (closeOnSelect) {
|
if (item.closeOnSelect !== false) {
|
||||||
const dropdownTrigger = document.querySelector('[data-state="open"][role="menu"]');
|
const dropdownTrigger = document.querySelector('[data-state="open"][role="menu"]');
|
||||||
if (dropdownTrigger) {
|
if (dropdownTrigger) {
|
||||||
const closeEvent = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true });
|
const closeEvent = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true });
|
||||||
|
@ -248,7 +245,7 @@ export const DropdownContent = <T,>({
|
||||||
selectType={selectType}
|
selectType={selectType}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
onSelectItem={onSelectItem}
|
onSelectItem={onSelectItem}
|
||||||
closeOnSelect={closeOnSelect}
|
closeOnSelect={(item as DropdownItem).closeOnSelect !== false}
|
||||||
showIndex={showIndex}
|
showIndex={showIndex}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -270,7 +267,7 @@ export const DropdownContent = <T,>({
|
||||||
selectType={selectType}
|
selectType={selectType}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
onSelectItem={onSelectItem}
|
onSelectItem={onSelectItem}
|
||||||
closeOnSelect={closeOnSelect}
|
closeOnSelect={(item as DropdownItem).closeOnSelect !== false}
|
||||||
showIndex={showIndex}
|
showIndex={showIndex}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -365,7 +362,7 @@ const DropdownItem = <T,>({
|
||||||
selectType: DropdownProps<T>['selectType'];
|
selectType: DropdownProps<T>['selectType'];
|
||||||
}) => {
|
}) => {
|
||||||
const onClickItem = useMemoizedFn((e: React.MouseEvent<HTMLDivElement>) => {
|
const onClickItem = useMemoizedFn((e: React.MouseEvent<HTMLDivElement>) => {
|
||||||
if (onClick) onClick();
|
if (onClick) onClick(e);
|
||||||
if (onSelect) onSelect(value as T);
|
if (onSelect) onSelect(value as T);
|
||||||
});
|
});
|
||||||
const enabledHotKeys = showIndex && !disabled && !!onSelectItem;
|
const enabledHotKeys = showIndex && !disabled && !!onSelectItem;
|
||||||
|
|
|
@ -190,6 +190,7 @@ const useDashboardSelectMenu = ({ metricId }: { metricId: string }) => {
|
||||||
() => ({
|
() => ({
|
||||||
label: 'Add to dashboard',
|
label: 'Add to dashboard',
|
||||||
value: 'add-to-dashboard',
|
value: 'add-to-dashboard',
|
||||||
|
closeOnSelect: false,
|
||||||
icon: <ASSET_ICONS.dashboardAdd />,
|
icon: <ASSET_ICONS.dashboardAdd />,
|
||||||
items: [<React.Fragment key="dashboard-sub-menu">{dashboardSubMenu}</React.Fragment>]
|
items: [<React.Fragment key="dashboard-sub-menu">{dashboardSubMenu}</React.Fragment>]
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue