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

Remove the heart icon button to add the view as a favorite from the top bar #8769

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const PageFavoriteFoldersDropdown = ({
onSubmit={closeDropdown}
record={record}
objectNameSingular={objectNameSingular}
dropdownId={dropdownId}
/>
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type FavoriteFolderPickerProps = {
onSubmit?: () => void;
record?: ObjectRecord;
objectNameSingular: string;
dropdownId: string;
};

const NO_FOLDER_ID = 'no-folder';
Expand All @@ -28,6 +29,7 @@ export const FavoriteFolderPicker = ({
onSubmit,
record,
objectNameSingular,
dropdownId,
}: FavoriteFolderPickerProps) => {
const [isFavoriteFolderCreating, setIsFavoriteFolderCreating] =
useRecoilState(isFavoriteFolderCreatingState);
Expand Down Expand Up @@ -97,7 +99,7 @@ export const FavoriteFolderPicker = ({
toggleFolderSelection={toggleFolderSelection}
/>
</DropdownMenuItemsContainer>
<FavoriteFolderPickerFooter />
<FavoriteFolderPickerFooter dropdownId={dropdownId} />
</DropdownMenu>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FAVORITE_FOLDER_PICKER_DROPDOWN_ID } from '@/favorites/favorite-folder-picker/constants/FavoriteFolderPickerDropdownId';
import { isFavoriteFolderCreatingState } from '@/favorites/states/isFavoriteFolderCreatingState';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
Expand All @@ -10,13 +9,16 @@ import { useRecoilState, useSetRecoilState } from 'recoil';
import { IconPlus, MenuItem } from 'twenty-ui';

const StyledFooter = styled.div`
background: ${({ theme }) => theme.background.primary};
border-bottom-left-radius: ${({ theme }) => theme.border.radius.md};
border-bottom-right-radius: ${({ theme }) => theme.border.radius.md};
border-top: 1px solid ${({ theme }) => theme.border.color.light};
`;

export const FavoriteFolderPickerFooter = () => {
export const FavoriteFolderPickerFooter = ({
dropdownId,
}: {
dropdownId: string;
}) => {
const [, setIsFavoriteFolderCreating] = useRecoilState(
isFavoriteFolderCreatingState,
);
Expand All @@ -25,7 +27,7 @@ export const FavoriteFolderPickerFooter = () => {
);
const { openNavigationSection } = useNavigationSection('Favorites');
const theme = useTheme();
const { closeDropdown } = useDropdown(FAVORITE_FOLDER_PICKER_DROPDOWN_ID);
const { closeDropdown } = useDropdown(dropdownId);

return (
<StyledFooter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { PageFavoriteFoldersDropdown } from '@/favorites/components/PageFavoriteFolderDropdown';
import { FAVORITE_FOLDER_PICKER_DROPDOWN_ID } from '@/favorites/favorite-folder-picker/constants/FavoriteFolderPickerDropdownId';
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly';
import { RecordIndexPageKanbanAddButton } from '@/object-record/record-index/components/RecordIndexPageKanbanAddButton';
import { RecordIndexRootPropsContext } from '@/object-record/record-index/contexts/RecordIndexRootPropsContext';
import { recordIndexViewTypeState } from '@/object-record/record-index/states/recordIndexViewTypeState';
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { PageAddButton } from '@/ui/layout/page/components/PageAddButton';
import { PageHeader } from '@/ui/layout/page/components/PageHeader';
import { PageHotkeysEffect } from '@/ui/layout/page/components/PageHotkeysEffect';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { currentViewIdComponentState } from '@/views/states/currentViewIdComponentState';
import { View } from '@/views/types/View';
import { ViewType } from '@/views/types/ViewType';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { useContext } from 'react';
import { useRecoilValue } from 'recoil';
import { useIcons } from 'twenty-ui';
Expand All @@ -24,27 +15,10 @@ import { capitalize } from '~/utils/string/capitalize';
export const RecordIndexPageHeader = () => {
const { findObjectMetadataItemByNamePlural } =
useFilteredObjectMetadataItems();
const isFavoriteFolderEnabled = useIsFeatureEnabled(
'IS_FAVORITE_FOLDER_ENABLED',
);

const { objectNamePlural, onCreateRecord, recordIndexId } = useContext(
const { objectNamePlural, onCreateRecord } = useContext(
RecordIndexRootPropsContext,
);
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
const currentViewId = useRecoilComponentValueV2(
currentViewIdComponentState,
recordIndexId,
);

const view = views.find((view) => view.id === currentViewId);

const { sortedFavorites: favorites } = useFavorites();

const isFavorite = favorites.some(
(favorite) =>
favorite.recordId === currentViewId && favorite.workspaceMemberId,
);

const objectMetadataItem =
findObjectMetadataItemByNamePlural(objectNamePlural);
Expand Down Expand Up @@ -72,14 +46,6 @@ export const RecordIndexPageHeader = () => {
return (
<PageHeader title={pageHeaderTitle} Icon={Icon}>
<PageHotkeysEffect onAddButtonClick={handleAddButtonClick} />
{isFavoriteFolderEnabled && (
<PageFavoriteFoldersDropdown
record={view}
dropdownId={FAVORITE_FOLDER_PICKER_DROPDOWN_ID}
objectNameSingular="view"
isFavorite={isFavorite}
/>
)}
{shouldDisplayAddButton &&
(isTable ? (
<PageAddButton onClick={handleAddButtonClick} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TEXT_INPUT_STYLE } from 'twenty-ui';
const StyledDropdownMenuSearchInputContainer = styled.div`
align-items: center;
--vertical-padding: ${({ theme }) => theme.spacing(2)};

border-radius: ${({ theme }) => theme.border.radius.sm};
display: flex;
background: ${({ theme }) => theme.background.transparent.secondary};
backdrop-filter: ${({ theme }) => theme.blur.medium};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SelectHotkeyScope } from '@/ui/input/types/SelectHotkeyScope';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
import { useTheme } from '@emotion/react';
import { Placement } from '@floating-ui/react';
import { FunctionComponent, MouseEvent, ReactElement, ReactNode } from 'react';
import {
IconChevronRight,
Expand Down Expand Up @@ -36,6 +37,7 @@ export type MenuItemWithOptionDropdownProps = {
testId?: string;
text: ReactNode;
hasSubMenu?: boolean;
dropdownPlacement?: Placement;
};

// TODO: refactor this
Expand All @@ -53,6 +55,7 @@ export const MenuItemWithOptionDropdown = ({
testId,
text,
hasSubMenu = false,
dropdownPlacement = 'bottom-end',
}: MenuItemWithOptionDropdownProps) => {
const theme = useTheme();

Expand Down Expand Up @@ -86,6 +89,7 @@ export const MenuItemWithOptionDropdown = ({
accent="tertiary"
/>
}
dropdownPlacement={dropdownPlacement}
dropdownComponents={dropdownContent}
dropdownId={dropdownId}
dropdownHotkeyScope={{ scope: SelectHotkeyScope.Select }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { ViewsHotkeyScope } from '@/views/types/ViewsHotkeyScope';
import { ViewPickerContentCreateMode } from '@/views/view-picker/components/ViewPickerContentCreateMode';
import { ViewPickerContentEditMode } from '@/views/view-picker/components/ViewPickerContentEditMode';
import { ViewPickerContentEffect } from '@/views/view-picker/components/ViewPickerContentEffect';
import { ViewPickerFavoriteFoldersDropdown } from '@/views/view-picker/components/ViewPickerFavoriteFoldersDropdown';
import { ViewPickerListContent } from '@/views/view-picker/components/ViewPickerListContent';
import { VIEW_PICKER_DROPDOWN_ID } from '@/views/view-picker/constants/ViewPickerDropdownId';
import { useUpdateViewFromCurrentState } from '@/views/view-picker/hooks/useUpdateViewFromCurrentState';
import { useViewPickerMode } from '@/views/view-picker/hooks/useViewPickerMode';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { isDefined } from '~/utils/isDefined';

const StyledDropdownLabelAdornments = styled.span`
Expand Down Expand Up @@ -49,6 +51,9 @@ const StyledViewName = styled.span`

export const ViewPickerDropdown = () => {
const theme = useTheme();
const isFavoriteFolderEnabled = useIsFeatureEnabled(
'IS_FAVORITE_FOLDER_ENABLED',
);

const { currentViewWithCombinedFiltersAndSorts } = useGetCurrentView();

Expand Down Expand Up @@ -99,21 +104,33 @@ export const ViewPickerDropdown = () => {
</StyledDropdownLabelAdornments>
</StyledDropdownButtonContainer>
}
dropdownComponents={
viewPickerMode === 'list' ? (
<ViewPickerListContent />
) : (
<>
{viewPickerMode === 'create-empty' ||
viewPickerMode === 'create-from-current' ? (
<ViewPickerContentCreateMode />
) : (
<ViewPickerContentEditMode />
)}
<ViewPickerContentEffect />
</>
)
}
dropdownComponents={(() => {
switch (viewPickerMode) {
case 'list':
return <ViewPickerListContent />;
case 'favorite-folders-picker':
return (
isFavoriteFolderEnabled && <ViewPickerFavoriteFoldersDropdown />
);
case 'create-empty':
case 'create-from-current':
return (
<>
<ViewPickerContentCreateMode />
<ViewPickerContentEffect />
</>
);
case 'edit':
return (
<>
<ViewPickerContentEditMode />
<ViewPickerContentEffect />
</>
);
default:
return null;
}
})()}
Comment on lines +107 to +133
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { FavoriteFolderPicker } from '@/favorites/favorite-folder-picker/components/FavoriteFolderPicker';
import { FavoriteFolderPickerEffect } from '@/favorites/favorite-folder-picker/components/FavoriteFolderPickerEffect';
import { FavoriteFolderPickerComponentInstanceContext } from '@/favorites/favorite-folder-picker/scopes/FavoriteFolderPickerScope';
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { DropdownScope } from '@/ui/layout/dropdown/scopes/DropdownScope';
import { useRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentStateV2';
import { View } from '@/views/types/View';
import { VIEW_PICKER_DROPDOWN_ID } from '@/views/view-picker/constants/ViewPickerDropdownId';
import { viewPickerReferenceViewIdComponentState } from '@/views/view-picker/states/viewPickerReferenceViewIdComponentState';

export const ViewPickerFavoriteFoldersDropdown = () => {
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
const [viewPickerReferenceViewId] = useRecoilComponentStateV2(
viewPickerReferenceViewIdComponentState,
);

const view = views.find((view) => view.id === viewPickerReferenceViewId);

return (
<FavoriteFolderPickerComponentInstanceContext
favoriteFoldersScopeId={VIEW_PICKER_DROPDOWN_ID}
>
<DropdownScope dropdownScopeId={VIEW_PICKER_DROPDOWN_ID}>
<>
<FavoriteFolderPickerEffect record={view} />
<FavoriteFolderPicker
record={view}
objectNameSingular="view"
dropdownId={VIEW_PICKER_DROPDOWN_ID}
/>
</>
</DropdownScope>
</FavoriteFolderPickerComponentInstanceContext>
);
};
Loading
Loading