Skip to content

Commit

Permalink
remove flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ehconitin committed Dec 20, 2024
1 parent 03f8979 commit b59cdc2
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 184 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import { useRecoilState, useRecoilValue } from 'recoil';
import { IconFolderPlus, LightIconButton, isDefined } from 'twenty-ui';

import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { CurrentWorkspaceMemberOrphanFavorites } from '@/favorites/components/CurrentWorkspaceMemberOrphanFavorites';
import { FavoritesDragProvider } from '@/favorites/components/FavoritesDragProvider';
import { FavoriteFolders } from '@/favorites/components/FavoritesFolders';
import { FavoritesSkeletonLoader } from '@/favorites/components/FavoritesSkeletonLoader';
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { useFavoritesByFolder } from '@/favorites/hooks/useFavoritesByFolder';
import { isFavoriteFolderCreatingState } from '@/favorites/states/isFavoriteFolderCreatingState';
import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading';
import { NavigationDrawerAnimatedCollapseWrapper } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper';
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 { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { useRecoilState, useRecoilValue } from 'recoil';
import { IconFolderPlus, LightIconButton, isDefined } from 'twenty-ui';

export const CurrentWorkspaceMemberFavoritesFolders = () => {
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
const { sortedFavorites: favorites } = useFavorites();
const { favoritesByFolder } = useFavoritesByFolder();

const [isFavoriteFolderCreating, setIsFavoriteFolderCreating] =
useRecoilState(isFavoriteFolderCreatingState);

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

const {
Expand All @@ -38,21 +36,15 @@ export const CurrentWorkspaceMemberFavoritesFolders = () => {
setIsFavoriteFolderCreating((current) => !current);
};

const shouldDisplayFavoritesWithFeatureFlagEnabled = true;

//todo: remove this logic once feature flag gating is removed
const shouldDisplayFavoritesWithoutFeatureFlagEnabled =
favorites.length > 0 || isFavoriteFolderCreating;

const shouldDisplayFavorites = isFavoriteFolderEnabled
? shouldDisplayFavoritesWithFeatureFlagEnabled
: shouldDisplayFavoritesWithoutFeatureFlagEnabled;

if (loading && isDefined(currentWorkspaceMember)) {
return <FavoritesSkeletonLoader />;
}

if (!shouldDisplayFavorites) {
if (
(!favorites || favorites.length === 0) &&
!isFavoriteFolderCreating &&
!favoritesByFolder.length
) {
return null;
}

Expand All @@ -63,24 +55,17 @@ export const CurrentWorkspaceMemberFavoritesFolders = () => {
label="Favorites"
onClick={toggleNavigationSection}
rightIcon={
isFavoriteFolderEnabled ? (
<LightIconButton
Icon={IconFolderPlus}
onClick={toggleNewFolder}
accent="tertiary"
/>
) : undefined
<LightIconButton
Icon={IconFolderPlus}
onClick={toggleNewFolder}
accent="tertiary"
/>
}
/>
</NavigationDrawerAnimatedCollapseWrapper>

{isNavigationSectionOpen && (
<FavoritesDragProvider>
{isFavoriteFolderEnabled && (
<FavoriteFolders
isNavigationSectionOpen={isNavigationSectionOpen}
/>
)}
<FavoriteFolders isNavigationSectionOpen={isNavigationSectionOpen} />
<CurrentWorkspaceMemberOrphanFavorites />
</FavoritesDragProvider>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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 { useCreateFavoriteFolder } from '@/favorites/hooks/useCreateFavoriteFolder';
import { useFavoritesByFolder } from '@/favorites/hooks/useFavoritesByFolder';
import { isFavoriteFolderCreatingState } from '@/favorites/states/isFavoriteFolderCreatingState';
import { NavigationDrawerInput } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerInput';
import { useState } from 'react';
import { useRecoilState } from 'recoil';
import { IconFolder } from 'twenty-ui';

type FavoriteFoldersProps = {
isNavigationSectionOpen: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import React from 'react';

import { PrefetchFavoriteFoldersRunQueriesEffect } from '@/prefetch/components/PrefetchFavortiteFoldersRunQueriesEffect';
import { PrefetchRunQueriesEffect } from '@/prefetch/components/PrefetchRunQueriesEffect';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import React from 'react';

export const PrefetchDataProvider = ({ children }: React.PropsWithChildren) => {
const isFavoriteFolderEnabled = useIsFeatureEnabled(
'IS_FAVORITE_FOLDER_ENABLED',
);
return (
<>
<PrefetchRunQueriesEffect />
{isFavoriteFolderEnabled && <PrefetchFavoriteFoldersRunQueriesEffect />}
{children}
</>
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRecoilValue } from 'recoil';

import { currentUserState } from '@/auth/states/currentUserState';
import { Favorite } from '@/favorites/types/Favorite';
import { FavoriteFolder } from '@/favorites/types/FavoriteFolder';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
import { useCombinedFindManyRecords } from '@/object-record/multiple-objects/hooks/useCombinedFindManyRecords';
import { PREFETCH_CONFIG } from '@/prefetch/constants/PrefetchConfig';
Expand All @@ -23,15 +24,14 @@ export const PrefetchRunQueriesEffect = () => {
usePrefetchRunQuery<Favorite>({
prefetchKey: PrefetchKey.AllFavorites,
});

const { upsertRecordsInCache: upsertFavoritesFoldersInCache } =
usePrefetchRunQuery<FavoriteFolder>({
prefetchKey: PrefetchKey.AllFavoritesFolders,
});
const { objectMetadataItems } = useObjectMetadataItems();

const operationSignatures = Object.values(PREFETCH_CONFIG)
.filter(
({ objectNameSingular }) =>
// TODO: Remove this filter once we merge PrefetchFavortiteFoldersRunQueriesEffect with this component
objectNameSingular !== 'favoriteFolder',
)

.map(({ objectNameSingular, operationSignatureFactory }) => {
const objectMetadataItem = objectMetadataItems.find(
(item) => item.nameSingular === objectNameSingular,
Expand All @@ -53,7 +53,15 @@ export const PrefetchRunQueriesEffect = () => {
if (isDefined(result.favorites)) {
upsertFavoritesInCache(result.favorites as Favorite[]);
}
}, [result, upsertViewsInCache, upsertFavoritesInCache]);
if (isDefined(result.favoriteFolders)) {
upsertFavoritesFoldersInCache(result.favoriteFolders as FavoriteFolder[]);
}
}, [
result,
upsertViewsInCache,
upsertFavoritesInCache,
upsertFavoritesFoldersInCache,
]);

return <></>;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { prefetchIsLoadedFamilyState } from '@/prefetch/states/prefetchIsLoadedFamilyState';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { useRecoilValue } from 'recoil';

export const useIsPrefetchLoading = () => {
const isFavoriteFolderEnabled = useIsFeatureEnabled(
'IS_FAVORITE_FOLDER_ENABLED',
);
const isFavoriteFoldersPrefetched = useRecoilValue(
prefetchIsLoadedFamilyState(PrefetchKey.AllFavoritesFolders),
);
Expand All @@ -21,6 +17,6 @@ export const useIsPrefetchLoading = () => {
return (
!areViewsPrefetched ||
!areFavoritesPrefetched ||
(isFavoriteFolderEnabled && !isFavoriteFoldersPrefetched)
!isFavoriteFoldersPrefetched
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { ViewPickerListContent } from '@/views/view-picker/components/ViewPicker
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 @@ -51,9 +50,6 @@ const StyledViewName = styled.span`

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

const { currentViewWithCombinedFiltersAndSorts } = useGetCurrentView();

Expand Down Expand Up @@ -110,9 +106,7 @@ export const ViewPickerDropdown = () => {
case 'list':
return <ViewPickerListContent />;
case 'favorite-folders-picker':
return (
isFavoriteFolderEnabled && <ViewPickerFavoriteFoldersDropdown />
);
return <ViewPickerFavoriteFoldersDropdown />;
case 'create-empty':
case 'create-from-current':
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { View } from '@/views/types/View';
import { useDeleteViewFromCurrentState } from '@/views/view-picker/hooks/useDeleteViewFromCurrentState';
import { useViewPickerMode } from '@/views/view-picker/hooks/useViewPickerMode';
import { viewPickerReferenceViewIdComponentState } from '@/views/view-picker/states/viewPickerReferenceViewIdComponentState';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { useState } from 'react';
import {
IconHeart,
Expand Down Expand Up @@ -41,10 +40,6 @@ export const ViewPickerOptionDropdown = ({
);
const { setViewPickerMode } = useViewPickerMode();

const isFavoriteFolderEnabled = useIsFeatureEnabled(
'IS_FAVORITE_FOLDER_ENABLED',
);

const { sortedFavorites: favorites } = useFavorites();
const { createFavorite } = useCreateFavorite();

Expand Down Expand Up @@ -86,22 +81,19 @@ export const ViewPickerOptionDropdown = ({
dropdownContent={
<DropdownMenuItemsContainer>
{isIndexView ? (
isFavoriteFolderEnabled && (
<MenuItem
LeftIcon={IconHeart}
text={isFavorite ? 'Manage favorite' : 'Add to Favorite'}
onClick={handleAddToFavorites}
/>
) : (
<>
<MenuItem
LeftIcon={IconHeart}
text={isFavorite ? 'Manage favorite' : 'Add to Favorite'}
onClick={handleAddToFavorites}
/>
)
) : (
<>
{isFavoriteFolderEnabled && (
<MenuItem
LeftIcon={IconHeart}
text={isFavorite ? 'Manage favorite' : 'Add to Favorite'}
onClick={handleAddToFavorites}
/>
)}

<MenuItem
LeftIcon={IconPencil}
text="Edit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ export type FeatureFlagKey =
| 'IS_MICROSOFT_SYNC_ENABLED'
| 'IS_ADVANCED_FILTERS_ENABLED'
| 'IS_AGGREGATE_QUERY_ENABLED'
| 'IS_FAVORITE_FOLDER_ENABLED'
| 'IS_VIEW_GROUPS_ENABLED'
| 'IS_PAGE_HEADER_V2_ENABLED';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
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 { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { useIsMobile } from 'twenty-ui';

type RecordShowPageBaseHeaderProps = {
Expand All @@ -23,31 +22,20 @@ export const RecordShowPageBaseHeader = ({
objectNameSingular,
handleFavoriteButtonClick,
}: RecordShowPageBaseHeaderProps) => {
const isFavoriteFolderEnabled = useIsFeatureEnabled(
'IS_FAVORITE_FOLDER_ENABLED',
);

const isMobile = useIsMobile();

return (
<>
{!isMobile && (
<>
{isFavoriteFolderEnabled ? (
isFavorite ? (
<PageFavoriteFoldersDropdown
key={FAVORITE_FOLDER_PICKER_DROPDOWN_ID}
dropdownId={FAVORITE_FOLDER_PICKER_DROPDOWN_ID}
isFavorite={isFavorite}
record={record}
objectNameSingular={objectNameSingular}
/>
) : (
<PageFavoriteButton
isFavorite={isFavorite}
onClick={handleFavoriteButtonClick}
/>
)
{isFavorite ? (
<PageFavoriteFoldersDropdown
key={FAVORITE_FOLDER_PICKER_DROPDOWN_ID}
dropdownId={FAVORITE_FOLDER_PICKER_DROPDOWN_ID}
isFavorite={isFavorite}
record={record}
objectNameSingular={objectNameSingular}
/>
) : (
<PageFavoriteButton
isFavorite={isFavorite}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,7 @@ export const seedFeatureFlags = async (
workspaceId: workspaceId,
value: false,
},
{
key: FeatureFlagKey.IsFavoriteFolderEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKey.IsFavoriteFolderEntityEnabled,
workspaceId: workspaceId,
value: true,
},

{
key: FeatureFlagKey.IsPageHeaderV2Enabled,
workspaceId: workspaceId,
Expand Down
Loading

0 comments on commit b59cdc2

Please sign in to comment.