mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-09 02:11:55 +03:00
8928 refactor page header buttons (#8952)
Closes #8928 <img width="1296" alt="Capture d’écran 2024-12-09 à 10 26 37" src="https://github.com/user-attachments/assets/f33202b0-9c11-48da-8daa-e867d62a1803"> <img width="1296" alt="Capture d’écran 2024-12-09 à 10 26 54" src="https://github.com/user-attachments/assets/a94f89d4-ca12-403f-bfcb-12168a82f77c">
This commit is contained in:
parent
ef0ae2568d
commit
387f5259a7
@ -1,4 +1,4 @@
|
|||||||
import { IconButton, IconHeart } from 'twenty-ui';
|
import { Button, IconHeart } from 'twenty-ui';
|
||||||
|
|
||||||
type PageFavoriteButtonProps = {
|
type PageFavoriteButtonProps = {
|
||||||
isFavorite: boolean;
|
isFavorite: boolean;
|
||||||
@ -8,13 +8,18 @@ type PageFavoriteButtonProps = {
|
|||||||
export const PageFavoriteButton = ({
|
export const PageFavoriteButton = ({
|
||||||
isFavorite,
|
isFavorite,
|
||||||
onClick,
|
onClick,
|
||||||
}: PageFavoriteButtonProps) => (
|
}: PageFavoriteButtonProps) => {
|
||||||
<IconButton
|
const title = isFavorite ? 'Remove from favorites' : 'Add to favorites';
|
||||||
Icon={IconHeart}
|
return (
|
||||||
size="medium"
|
<Button
|
||||||
variant="secondary"
|
Icon={IconHeart}
|
||||||
data-testid="add-button"
|
dataTestId="favorite-button"
|
||||||
accent={isFavorite ? 'danger' : 'default'}
|
size="small"
|
||||||
onClick={onClick}
|
variant="secondary"
|
||||||
/>
|
accent={isFavorite ? 'danger' : 'default'}
|
||||||
);
|
title={title}
|
||||||
|
onClick={onClick}
|
||||||
|
ariaLabel={title}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
@ -3,6 +3,7 @@ import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetada
|
|||||||
import { RecordIndexPageKanbanAddButton } from '@/object-record/record-index/components/RecordIndexPageKanbanAddButton';
|
import { RecordIndexPageKanbanAddButton } from '@/object-record/record-index/components/RecordIndexPageKanbanAddButton';
|
||||||
import { RecordIndexRootPropsContext } from '@/object-record/record-index/contexts/RecordIndexRootPropsContext';
|
import { RecordIndexRootPropsContext } from '@/object-record/record-index/contexts/RecordIndexRootPropsContext';
|
||||||
import { recordIndexViewTypeState } from '@/object-record/record-index/states/recordIndexViewTypeState';
|
import { recordIndexViewTypeState } from '@/object-record/record-index/states/recordIndexViewTypeState';
|
||||||
|
import { PageHeaderOpenCommandMenuButton } from '@/ui/layout/page-header/components/PageHeaderOpenCommandMenuButton';
|
||||||
import { PageAddButton } from '@/ui/layout/page/components/PageAddButton';
|
import { PageAddButton } from '@/ui/layout/page/components/PageAddButton';
|
||||||
import { PageHeader } from '@/ui/layout/page/components/PageHeader';
|
import { PageHeader } from '@/ui/layout/page/components/PageHeader';
|
||||||
import { PageHotkeysEffect } from '@/ui/layout/page/components/PageHotkeysEffect';
|
import { PageHotkeysEffect } from '@/ui/layout/page/components/PageHotkeysEffect';
|
||||||
@ -52,6 +53,7 @@ export const RecordIndexPageHeader = () => {
|
|||||||
) : (
|
) : (
|
||||||
<RecordIndexPageKanbanAddButton />
|
<RecordIndexPageKanbanAddButton />
|
||||||
))}
|
))}
|
||||||
|
<PageHeaderOpenCommandMenuButton />
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -12,11 +12,11 @@ import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
|
|||||||
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
|
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
|
||||||
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
|
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
|
||||||
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
||||||
|
import { PageAddButton } from '@/ui/layout/page/components/PageAddButton';
|
||||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { useCallback, useContext } from 'react';
|
import { useCallback, useContext } from 'react';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
import { IconButton, IconPlus } from 'twenty-ui';
|
|
||||||
|
|
||||||
const StyledDropdownMenuItemsContainer = styled(DropdownMenuItemsContainer)`
|
const StyledDropdownMenuItemsContainer = styled(DropdownMenuItemsContainer)`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -92,16 +92,7 @@ export const RecordIndexPageKanbanAddButton = () => {
|
|||||||
<Dropdown
|
<Dropdown
|
||||||
dropdownMenuWidth="200px"
|
dropdownMenuWidth="200px"
|
||||||
dropdownPlacement="bottom-start"
|
dropdownPlacement="bottom-start"
|
||||||
clickableComponent={
|
clickableComponent={<PageAddButton />}
|
||||||
<IconButton
|
|
||||||
Icon={IconPlus}
|
|
||||||
dataTestId="add-button"
|
|
||||||
size="medium"
|
|
||||||
variant="secondary"
|
|
||||||
accent="default"
|
|
||||||
ariaLabel="Add"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
dropdownId={dropdownId}
|
dropdownId={dropdownId}
|
||||||
dropdownComponents={
|
dropdownComponents={
|
||||||
<StyledDropDownMenu>
|
<StyledDropDownMenu>
|
||||||
|
@ -20,7 +20,7 @@ export const SignInBackgroundMockPage = () => {
|
|||||||
<PageContainer>
|
<PageContainer>
|
||||||
<PageHeader title="Companies" Icon={IconBuildingSkyscraper}>
|
<PageHeader title="Companies" Icon={IconBuildingSkyscraper}>
|
||||||
<PageHotkeysEffect onAddButtonClick={() => {}} />
|
<PageHotkeysEffect onAddButtonClick={() => {}} />
|
||||||
<PageAddButton onClick={() => {}} />
|
<PageAddButton />
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<RecordFieldValueSelectorContextProvider>
|
<RecordFieldValueSelectorContextProvider>
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import { IconButton, IconDotsVertical } from 'twenty-ui';
|
import { Button, IconDotsVertical } from 'twenty-ui';
|
||||||
|
|
||||||
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
|
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
|
||||||
|
|
||||||
export const ShowPageMoreButton = () => {
|
export const PageHeaderOpenCommandMenuButton = () => {
|
||||||
const { openCommandMenu } = useCommandMenu();
|
const { openCommandMenu } = useCommandMenu();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<Button
|
||||||
Icon={IconDotsVertical}
|
Icon={IconDotsVertical}
|
||||||
size="medium"
|
dataTestId="page-header-open-command-menu-button"
|
||||||
dataTestId="more-showpage-button"
|
size="small"
|
||||||
accent="default"
|
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
accent="default"
|
||||||
|
shortcut="⌘K"
|
||||||
|
ariaLabel="Open command menu"
|
||||||
onClick={openCommandMenu}
|
onClick={openCommandMenu}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
@ -1,17 +1,18 @@
|
|||||||
import { IconButton, IconPlus } from 'twenty-ui';
|
import { Button, IconPlus } from 'twenty-ui';
|
||||||
|
|
||||||
type PageAddButtonProps = {
|
type PageAddButtonProps = {
|
||||||
onClick: () => void;
|
onClick?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PageAddButton = ({ onClick }: PageAddButtonProps) => (
|
export const PageAddButton = ({ onClick }: PageAddButtonProps) => (
|
||||||
<IconButton
|
<Button
|
||||||
Icon={IconPlus}
|
Icon={IconPlus}
|
||||||
dataTestId="add-button"
|
dataTestId="add-button"
|
||||||
size="medium"
|
size="small"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
accent="default"
|
accent="default"
|
||||||
|
title="New record"
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
ariaLabel="Add"
|
ariaLabel="New record"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -129,24 +129,6 @@ export const PageHeader = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<StyledTopBarIconStyledTitleContainer>
|
<StyledTopBarIconStyledTitleContainer>
|
||||||
{hasPaginationButtons && (
|
|
||||||
<>
|
|
||||||
<IconButton
|
|
||||||
Icon={IconChevronUp}
|
|
||||||
size="small"
|
|
||||||
variant="secondary"
|
|
||||||
disabled={!hasPreviousRecord}
|
|
||||||
onClick={() => navigateToPreviousRecord?.()}
|
|
||||||
/>
|
|
||||||
<IconButton
|
|
||||||
Icon={IconChevronDown}
|
|
||||||
size="small"
|
|
||||||
variant="secondary"
|
|
||||||
disabled={!hasNextRecord}
|
|
||||||
onClick={() => navigateToNextRecord?.()}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{Icon && <Icon size={theme.icon.size.md} />}
|
{Icon && <Icon size={theme.icon.size.md} />}
|
||||||
{title && (
|
{title && (
|
||||||
<StyledTitleContainer data-testid="top-bar-title">
|
<StyledTitleContainer data-testid="top-bar-title">
|
||||||
@ -159,7 +141,28 @@ export const PageHeader = ({
|
|||||||
)}
|
)}
|
||||||
</StyledTopBarIconStyledTitleContainer>
|
</StyledTopBarIconStyledTitleContainer>
|
||||||
</StyledLeftContainer>
|
</StyledLeftContainer>
|
||||||
<StyledPageActionContainer>{children}</StyledPageActionContainer>
|
|
||||||
|
<StyledPageActionContainer>
|
||||||
|
{hasPaginationButtons && (
|
||||||
|
<>
|
||||||
|
<IconButton
|
||||||
|
Icon={IconChevronUp}
|
||||||
|
size="small"
|
||||||
|
variant="secondary"
|
||||||
|
disabled={!hasPreviousRecord}
|
||||||
|
onClick={() => navigateToPreviousRecord?.()}
|
||||||
|
/>
|
||||||
|
<IconButton
|
||||||
|
Icon={IconChevronDown}
|
||||||
|
size="small"
|
||||||
|
variant="secondary"
|
||||||
|
disabled={!hasNextRecord}
|
||||||
|
onClick={() => navigateToNextRecord?.()}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
</StyledPageActionContainer>
|
||||||
</StyledTopBarContainer>
|
</StyledTopBarContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import {
|
import { Button, IconCheckbox, IconNotes, IconPlus, MenuItem } from 'twenty-ui';
|
||||||
IconButton,
|
|
||||||
IconCheckbox,
|
|
||||||
IconNotes,
|
|
||||||
IconPlus,
|
|
||||||
MenuItem,
|
|
||||||
} from 'twenty-ui';
|
|
||||||
|
|
||||||
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
|
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
|
||||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||||
@ -28,7 +22,7 @@ export const ShowPageAddButton = ({
|
|||||||
}: {
|
}: {
|
||||||
activityTargetObject: ActivityTargetableObject;
|
activityTargetObject: ActivityTargetableObject;
|
||||||
}) => {
|
}) => {
|
||||||
const { closeDropdown, toggleDropdown } = useDropdown('add-show-page');
|
const { closeDropdown } = useDropdown('add-show-page');
|
||||||
const openNote = useOpenCreateActivityDrawer({
|
const openNote = useOpenCreateActivityDrawer({
|
||||||
activityObjectNameSingular: CoreObjectNameSingular.Note,
|
activityObjectNameSingular: CoreObjectNameSingular.Note,
|
||||||
});
|
});
|
||||||
@ -66,13 +60,14 @@ export const ShowPageAddButton = ({
|
|||||||
<Dropdown
|
<Dropdown
|
||||||
dropdownId={SHOW_PAGE_ADD_BUTTON_DROPDOWN_ID}
|
dropdownId={SHOW_PAGE_ADD_BUTTON_DROPDOWN_ID}
|
||||||
clickableComponent={
|
clickableComponent={
|
||||||
<IconButton
|
<Button
|
||||||
Icon={IconPlus}
|
Icon={IconPlus}
|
||||||
size="medium"
|
dataTestId="add-button"
|
||||||
dataTestId="add-showpage-button"
|
size="small"
|
||||||
accent="default"
|
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={toggleDropdown}
|
accent="default"
|
||||||
|
title="New note/task"
|
||||||
|
ariaLabel="New note/task"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
dropdownComponents={
|
dropdownComponents={
|
||||||
|
@ -3,8 +3,8 @@ import { PageFavoriteFoldersDropdown } from '@/favorites/components/PageFavorite
|
|||||||
import { FAVORITE_FOLDER_PICKER_DROPDOWN_ID } from '@/favorites/favorite-folder-picker/constants/FavoriteFolderPickerDropdownId';
|
import { FAVORITE_FOLDER_PICKER_DROPDOWN_ID } from '@/favorites/favorite-folder-picker/constants/FavoriteFolderPickerDropdownId';
|
||||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||||
|
import { PageHeaderOpenCommandMenuButton } from '@/ui/layout/page-header/components/PageHeaderOpenCommandMenuButton';
|
||||||
import { ShowPageAddButton } from '@/ui/layout/show-page/components/ShowPageAddButton';
|
import { ShowPageAddButton } from '@/ui/layout/show-page/components/ShowPageAddButton';
|
||||||
import { ShowPageMoreButton } from '@/ui/layout/show-page/components/ShowPageMoreButton';
|
|
||||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||||
|
|
||||||
type RecordShowPageBaseHeaderProps = {
|
type RecordShowPageBaseHeaderProps = {
|
||||||
@ -49,7 +49,7 @@ export const RecordShowPageBaseHeader = ({
|
|||||||
targetObjectNameSingular: objectMetadataItem.nameSingular,
|
targetObjectNameSingular: objectMetadataItem.nameSingular,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ShowPageMoreButton key="more" />
|
<PageHeaderOpenCommandMenuButton key="more" />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -30,6 +30,7 @@ export type ButtonProps = {
|
|||||||
target?: string;
|
target?: string;
|
||||||
dataTestId?: string;
|
dataTestId?: string;
|
||||||
shortcut?: string;
|
shortcut?: string;
|
||||||
|
ariaLabel?: string;
|
||||||
} & React.ComponentProps<'button'>;
|
} & React.ComponentProps<'button'>;
|
||||||
|
|
||||||
const StyledButton = styled('button', {
|
const StyledButton = styled('button', {
|
||||||
@ -391,6 +392,7 @@ export const Button = ({
|
|||||||
target,
|
target,
|
||||||
dataTestId,
|
dataTestId,
|
||||||
shortcut,
|
shortcut,
|
||||||
|
ariaLabel,
|
||||||
}: ButtonProps) => {
|
}: ButtonProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
@ -411,6 +413,7 @@ export const Button = ({
|
|||||||
as={to ? Link : 'button'}
|
as={to ? Link : 'button'}
|
||||||
target={target}
|
target={target}
|
||||||
data-testid={dataTestId}
|
data-testid={dataTestId}
|
||||||
|
aria-label={ariaLabel}
|
||||||
>
|
>
|
||||||
{Icon && <Icon size={theme.icon.size.sm} />}
|
{Icon && <Icon size={theme.icon.size.sm} />}
|
||||||
{title}
|
{title}
|
||||||
|
Loading…
Reference in New Issue
Block a user