Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: changed behaviour of new button for search and settings modules #27

Merged
merged 8 commits into from
Mar 7, 2022
25 changes: 21 additions & 4 deletions src/shell/creation-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import React, { FC, useMemo } from 'react';
import React, { FC, useCallback, useMemo, useState } from 'react';
import { reduce, groupBy } from 'lodash';
import { MultiButton } from '@zextras/carbonio-design-system';
import { MultiButton, Button, Dropdown } from '@zextras/carbonio-design-system';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { useActions } from '../store/integrations/hooks';
Expand Down Expand Up @@ -43,16 +43,23 @@ export const CreationButton: FC<{ activeRoute?: AppRoute }> = ({ activeRoute })
const [t] = useTranslation();
const location = useLocation();
const actions = useActions({ activeRoute, location }, ACTION_TYPES.NEW);
const [open, setOpen] = useState(false);
const primaryAction = useMemo(
() =>
actions?.find?.(
(a) => (a.group === activeRoute?.id || a.group === activeRoute?.app) && a.primary
) ?? actions?.find?.((a) => a.primary),
),
[actions, activeRoute?.app, activeRoute?.id]
);
const secondaryActions = useSecondaryActions(actions, activeRoute);

return (
const onClose = useCallback(() => {
setOpen(false);
}, []);
const onOpen = useCallback(() => {
setOpen(true);
}, []);
return primaryAction ? (
<MultiButton
style={{ height: '42px' }}
background="primary"
Expand All @@ -61,5 +68,15 @@ export const CreationButton: FC<{ activeRoute?: AppRoute }> = ({ activeRoute })
items={secondaryActions}
disabled={!primaryAction || primaryAction?.disabled}
/>
) : (
<Dropdown items={secondaryActions} onClose={onClose} onOpen={onOpen}>
<Button
style={{ height: '42px' }}
background="primary"
items={secondaryActions}
label={t('new', 'New')}
icon={open ? 'ChevronUp' : 'ChevronDown'}
/>
</Dropdown>
);
};