Skip to content

Commit

Permalink
feture flag added
Browse files Browse the repository at this point in the history
  • Loading branch information
ehconitin committed Nov 15, 2024
1 parent 6bff675 commit 30fc731
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export const RecordShowActionMenu = ({
record,
objectMetadataItem,
objectNameSingular,
handleFavoriteButtonClick,
}: {
isFavorite: boolean;
record: ObjectRecord | undefined;
objectMetadataItem: ObjectMetadataItem;
objectNameSingular: string;
handleFavoriteButtonClick: () => void;
}) => {
const contextStoreCurrentObjectMetadataId = useRecoilComponentValueV2(
contextStoreCurrentObjectMetadataIdComponentState,
Expand All @@ -41,6 +43,7 @@ export const RecordShowActionMenu = ({
record,
objectMetadataItem,
objectNameSingular,
handleFavoriteButtonClick,
}}
/>
<ActionMenuConfirmationModals />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const CurrentWorkspaceMemberFavorites = ({
onToggle,
}: CurrentWorkspaceMemberFavoritesProps) => {
const currentPath = useLocation().pathname;
const currentPathView = useLocation().pathname + useLocation().search;
const currentViewPath = useLocation().pathname + useLocation().search;

const theme = useTheme();
const [isRenaming, setIsRenaming] = useState(false);
Expand All @@ -57,7 +57,7 @@ export const CurrentWorkspaceMemberFavorites = ({
);
const selectedFavoriteIndex = folder.favorites.findIndex((favorite) =>
favorite.objectNameSingular === 'view'
? favorite.link === currentPathView
? favorite.link === currentViewPath
: favorite.link === currentPath,
);
const { deleteFavorite, handleReorderFavorite } = useFavorites();
Expand Down Expand Up @@ -189,7 +189,7 @@ export const CurrentWorkspaceMemberFavorites = ({
to={favorite.link}
active={
favorite.objectNameSingular === 'view'
? favorite.link === currentPathView
? favorite.link === currentViewPath
: favorite.link === currentPath
}
subItemState={getNavigationSubItemState({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { useLocation } from 'react-router-dom';
import { useRecoilState, useRecoilValue } from 'recoil';
import { IconFolderPlus, IconHeartOff, isDefined } from 'twenty-ui';

import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { CurrentWorkspaceMemberFavorites } from '@/favorites/components/CurrentWorkspaceMemberFavorites';
import { FavoriteIcon } from '@/favorites/components/FavoriteIcon';
import { FavoriteFolders } from '@/favorites/components/FavoritesFolders';
import { FavoritesSkeletonLoader } from '@/favorites/components/FavoritesSkeletonLoader';
import { FavoriteFolderHotkeyScope } from '@/favorites/constants/FavoriteFolderRightIconDropdownHotkeyScope';
import { useFavoriteFolders } from '@/favorites/hooks/useFavoriteFolders';
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { isFavoriteFolderCreatingState } from '@/favorites/states/isFavoriteFolderCreatingState';
import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading';
import { DraggableItem } from '@/ui/layout/draggable-list/components/DraggableItem';
import { DraggableList } from '@/ui/layout/draggable-list/components/DraggableList';
import { NavigationDrawerAnimatedCollapseWrapper } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper';
import { NavigationDrawerInput } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerInput';
import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSection';
import { NavigationDrawerSectionTitle } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSectionTitle';
import { useNavigationSection } from '@/ui/navigation/navigation-drawer/hooks/useNavigationSection';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useRecoilState, useRecoilValue } from 'recoil';
import { IconFolder, IconFolderPlus, IconHeartOff, isDefined } from 'twenty-ui';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';

const StyledContainer = styled(NavigationDrawerSection)`
width: 100%;
Expand All @@ -37,58 +35,25 @@ const StyledNavigationDrawerItem = styled(NavigationDrawerItem)`
`;

export const CurrentWorkspaceMemberFavoritesFolders = () => {
const [activeFolderId, setActiveFolderId] = useState<string | null>(null);
const { createFolder, favoriteFolder } = useFavoriteFolders();
const { deleteFavorite } = useFavorites();
const [folderName, setFolderName] = useState('');
const currentPath = useLocation().pathname;
const currentPathView = useLocation().pathname + useLocation().search;
const [isFavoriteFolderCreating, setIsFavoriteFolderCreating] =
useRecoilState(isFavoriteFolderCreatingState);
const currentViewPath = useLocation().pathname + useLocation().search;
const theme = useTheme();
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
const { favorites, handleReorderFavorite, favoritesByFolder } =
useFavorites();
const { favorites, handleReorderFavorite, deleteFavorite } = useFavorites();
const [isFavoriteFolderCreating, setIsFavoriteFolderCreating] =
useRecoilState(isFavoriteFolderCreatingState);

const isFavoriteFolderEnabled = useIsFeatureEnabled(
'IS_FAVORITE_FOLDER_ENABLED',
);
const loading = useIsPrefetchLoading();

const { toggleNavigationSection, isNavigationSectionOpenState } =
useNavigationSection('Favorites');
const isNavigationSectionOpen = useRecoilValue(isNavigationSectionOpenState);

const handleFolderNameChange = (value: string) => {
setFolderName(value);
};

const handleSubmitFolder = async (value: string) => {
if (!value) return false;

setIsFavoriteFolderCreating(false);
setFolderName('');
await createFolder(value);
return true;
};

const handleClickOutside = async (
event: MouseEvent | TouchEvent,
value: string,
) => {
if (!value) {
setIsFavoriteFolderCreating(false);
return;
}

setIsFavoriteFolderCreating(false);
setFolderName('');
await createFolder(value);
};

const handleCancel = () => {
setFolderName('');
setIsFavoriteFolderCreating(false);
};

const toggleNewFolder = () => {
setIsFavoriteFolderCreating((current) => !current);
setFolderName('');
};

if (loading && isDefined(currentWorkspaceMember)) {
Expand All @@ -99,59 +64,42 @@ export const CurrentWorkspaceMemberFavoritesFolders = () => {
(favorite) => favorite.workspaceMemberId === currentWorkspaceMember?.id,
);

const unorganisedFavorites = currentWorkspaceMemberFavorites.filter(
(favorite) => !favorite.favoriteFolderId,
);

if (
(!currentWorkspaceMemberFavorites ||
currentWorkspaceMemberFavorites.length === 0) &&
(!favoriteFolder || favoriteFolder.length === 0) &&
!isFavoriteFolderCreating
) {
return <></>;
return null;
}

const unorganisedFavorites = currentWorkspaceMemberFavorites.filter(
(favorite) => !favorite.favoriteFolderId,
);
const isGroup =
currentWorkspaceMemberFavorites.length > 1 || favoritesByFolder.length > 1;

return (
<StyledContainer>
<NavigationDrawerAnimatedCollapseWrapper>
<NavigationDrawerSectionTitle
label="Favorites"
onClick={() => toggleNavigationSection()}
rightIcon={<IconFolderPlus size={theme.icon.size.sm} />}
onRightIconClick={toggleNewFolder}
onClick={toggleNavigationSection}
rightIcon={
isFavoriteFolderEnabled ? (
<IconFolderPlus size={theme.icon.size.sm} />
) : undefined
}
onRightIconClick={
isFavoriteFolderEnabled ? toggleNewFolder : undefined
}
/>
</NavigationDrawerAnimatedCollapseWrapper>

{isNavigationSectionOpen && (
<>
{isFavoriteFolderCreating && (
<NavigationDrawerInput
Icon={IconFolder}
value={folderName}
onChange={handleFolderNameChange}
onSubmit={handleSubmitFolder}
onCancel={handleCancel}
onClickOutside={handleClickOutside}
hotkeyScope={
FavoriteFolderHotkeyScope.FavoriteFolderNavigationInput
}
{isFavoriteFolderEnabled && (
<FavoriteFolders
isNavigationSectionOpen={isNavigationSectionOpen}
/>
)}
{favoritesByFolder.map((folder) => (
<CurrentWorkspaceMemberFavorites
key={folder.folderId}
folder={folder}
isGroup={isGroup}
isOpen={activeFolderId === folder.folderId}
onToggle={(folderId) => {
setActiveFolderId((currentId) =>
currentId === folderId ? null : folderId,
);
}}
/>
))}

{unorganisedFavorites.length > 0 && (
<DraggableList
Expand All @@ -169,7 +117,7 @@ export const CurrentWorkspaceMemberFavoritesFolders = () => {
Icon={() => <FavoriteIcon favorite={favorite} />}
active={
favorite.objectNameSingular === 'view'
? favorite.link === currentPathView
? favorite.link === currentViewPath
: favorite.link === currentPath
}
to={favorite.link}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { useState } from 'react';
import { useRecoilState } from 'recoil';
import { IconFolder } from 'twenty-ui';

import { CurrentWorkspaceMemberFavorites } from '@/favorites/components/CurrentWorkspaceMemberFavorites';
import { FavoriteFolderHotkeyScope } from '@/favorites/constants/FavoriteFolderRightIconDropdownHotkeyScope';
import { useFavoriteFolders } from '@/favorites/hooks/useFavoriteFolders';
import { isFavoriteFolderCreatingState } from '@/favorites/states/isFavoriteFolderCreatingState';
import { NavigationDrawerInput } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerInput';

type FavoriteFoldersProps = {
isNavigationSectionOpen: boolean;
};

export const FavoriteFolders = ({
isNavigationSectionOpen,
}: FavoriteFoldersProps) => {
const [activeFolderId, setActiveFolderId] = useState<string | null>(null);
const [folderName, setFolderName] = useState('');

const { createFolder, favoritesByFolder } = useFavoriteFolders();
const [isFavoriteFolderCreating, setIsFavoriteFolderCreating] =
useRecoilState(isFavoriteFolderCreatingState);

const handleFolderNameChange = (value: string) => {
setFolderName(value);
};

const handleSubmitFolder = async (value: string) => {
if (!value) return false;

setIsFavoriteFolderCreating(false);
setFolderName('');
await createFolder(value);
return true;
};

const handleClickOutside = async (
event: MouseEvent | TouchEvent,
value: string,
) => {
if (!value) {
setIsFavoriteFolderCreating(false);
return;
}

setIsFavoriteFolderCreating(false);
setFolderName('');
await createFolder(value);
};

const handleCancel = () => {
setFolderName('');
setIsFavoriteFolderCreating(false);
};

if (!isNavigationSectionOpen) {
return null;
}

return (
<>
{isFavoriteFolderCreating && (
<NavigationDrawerInput
Icon={IconFolder}
value={folderName}
onChange={handleFolderNameChange}
onSubmit={handleSubmitFolder}
onCancel={handleCancel}
onClickOutside={handleClickOutside}
hotkeyScope={FavoriteFolderHotkeyScope.FavoriteFolderNavigationInput}
/>
)}
{favoritesByFolder.map((folder) => (
<CurrentWorkspaceMemberFavorites
key={folder.folderId}
folder={folder}
isGroup={favoritesByFolder.length > 1}
isOpen={activeFolderId === folder.folderId}
onToggle={(folderId) => {
setActiveFolderId((currentId) =>
currentId === folderId ? null : folderId,
);
}}
/>
))}
</>
);
};
Loading

0 comments on commit 30fc731

Please sign in to comment.