The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/views/hooks/useActionSpread.ts

34 lines
825 B

import { useMemo } from 'react';
type Action = {
label: string;
icon: string;
action: () => any;
};
type MenuOption = {
label: { label: string; icon: string };
action: Function;
};
const mapOptions = ([key, { action, label, icon }]: [string, Action]): [string, MenuOption] => [
key,
{
label: { label, icon }, // TODO fuselage
action,
},
];
export const useActionSpread = (
actions: Action[],
size = 2,
): { actions: [string, Action][]; menu: { [id: string]: MenuOption } | undefined } =>
useMemo(() => {
const entries = Object.entries(actions);
const options = entries.slice(0, size);
const menuOptions = entries.slice(size, entries.length).map(mapOptions);
const menu = menuOptions.length ? Object.fromEntries(menuOptions) : undefined;
return { actions: options, menu };
}, [actions, size]);