Skip to content

Commit

Permalink
Merge branch 'twentyhq:main' into fix-9232-cannot-delete-an-account
Browse files Browse the repository at this point in the history
  • Loading branch information
melvinjariwala authored Dec 28, 2024
2 parents 091e22b + 36bec4e commit 8c3f91c
Show file tree
Hide file tree
Showing 102 changed files with 1,953 additions and 5,870 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { SingleRecordActionHookWithObjectMetadataItem } from '@/action-menu/actions/types/SingleRecordActionHook';
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext';
import { useRecordShowPagePagination } from '@/object-record/record-show/hooks/useRecordShowPagePagination';
import { useContext } from 'react';

export const useNavigateToNextRecordSingleRecordAction: SingleRecordActionHookWithObjectMetadataItem =
({ recordId, objectMetadataItem }) => {
const { isInRightDrawer } = useContext(ActionMenuContext);

const { navigateToNextRecord } = useRecordShowPagePagination(
objectMetadataItem.nameSingular,
recordId,
);

return {
shouldBeRegistered: true,
shouldBeRegistered: !isInRightDrawer,
onClick: navigateToNextRecord,
};
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { SingleRecordActionHookWithObjectMetadataItem } from '@/action-menu/actions/types/SingleRecordActionHook';
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext';
import { useRecordShowPagePagination } from '@/object-record/record-show/hooks/useRecordShowPagePagination';
import { useContext } from 'react';

export const useNavigateToPreviousRecordSingleRecordAction: SingleRecordActionHookWithObjectMetadataItem =
({ recordId, objectMetadataItem }) => {
const { isInRightDrawer } = useContext(ActionMenuContext);
const { navigateToPreviousRecord } = useRecordShowPagePagination(
objectMetadataItem.nameSingular,
recordId,
);

return {
shouldBeRegistered: true,
shouldBeRegistered: !isInRightDrawer,
onClick: navigateToPreviousRecord,
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DEFAULT_SINGLE_RECORD_ACTIONS_CONFIG_V1 } from '@/action-menu/actions/record-actions/single-record/constants/DefaultSingleRecordActionsConfigV1';
import { DEFAULT_SINGLE_RECORD_ACTIONS_CONFIG_V2 } from '@/action-menu/actions/record-actions/single-record/constants/DefaultSingleRecordActionsConfigV2';
import { WORKFLOW_SINGLE_RECORD_ACTIONS_CONFIG } from '@/action-menu/actions/record-actions/single-record/workflow-actions/constants/WorkflowSingleRecordActionsConfig';
import { WORKFLOW_RUNS_SINGLE_RECORD_ACTIONS_CONFIG } from '@/action-menu/actions/record-actions/single-record/workflow-run-actions/constants/WorkflowRunsSingleRecordActionsConfig';
import { WORKFLOW_VERSIONS_SINGLE_RECORD_ACTIONS_CONFIG } from '@/action-menu/actions/record-actions/single-record/workflow-version-actions/constants/WorkflowVersionsSingleRecordActionsConfig';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
Expand All @@ -17,6 +18,9 @@ export const getActionConfig = (
) {
return WORKFLOW_VERSIONS_SINGLE_RECORD_ACTIONS_CONFIG;
}
if (objectMetadataItem.nameSingular === CoreObjectNameSingular.WorkflowRun) {
return WORKFLOW_RUNS_SINGLE_RECORD_ACTIONS_CONFIG;
}
return isPageHeaderV2Enabled
? DEFAULT_SINGLE_RECORD_ACTIONS_CONFIG_V2
: DEFAULT_SINGLE_RECORD_ACTIONS_CONFIG_V1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const useActivateLastPublishedVersionWorkflowSingleRecordAction: SingleRe
isDefined(workflowWithCurrentVersion) &&
isDefined(workflowWithCurrentVersion.currentVersion.trigger) &&
isDefined(workflowWithCurrentVersion.lastPublishedVersionId) &&
workflowWithCurrentVersion.currentVersion.status !== 'ACTIVE' &&
workflowWithCurrentVersion.lastPublishedVersionId !== '' &&
!workflowWithCurrentVersion.statuses?.includes('ACTIVE') &&
isDefined(workflowWithCurrentVersion.currentVersion?.steps) &&
workflowWithCurrentVersion.currentVersion?.steps.length !== 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SingleRecordActionHookWithoutObjectMetadataItem } from '@/action-menu/actions/types/SingleRecordActionHook';
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
import { FilterQueryParams } from '@/views/hooks/internal/useViewFromQueryParams';
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
import qs from 'qs';
Expand All @@ -20,10 +19,12 @@ export const useSeeRunsWorkflowSingleRecordAction: SingleRecordActionHookWithout
return;
}

const filterQueryParams: FilterQueryParams = {
const filterQueryParams = {
filter: {
workflow: {
[ViewFilterOperand.Is]: [workflowWithCurrentVersion.id],
[ViewFilterOperand.Is]: {
selectedRecordIds: [workflowWithCurrentVersion.id],
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SingleRecordActionHookWithoutObjectMetadataItem } from '@/action-menu/actions/types/SingleRecordActionHook';
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
import { FilterQueryParams } from '@/views/hooks/internal/useViewFromQueryParams';
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
import qs from 'qs';
Expand All @@ -20,10 +19,12 @@ export const useSeeVersionsWorkflowSingleRecordAction: SingleRecordActionHookWit
return;
}

const filterQueryParams: FilterQueryParams = {
const filterQueryParams = {
filter: {
workflow: {
[ViewFilterOperand.Is]: [workflowWithCurrentVersion.id],
[ViewFilterOperand.Is]: {
selectedRecordIds: [workflowWithCurrentVersion.id],
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useAddToFavoritesSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useAddToFavoritesSingleRecordAction';
import { useNavigateToNextRecordSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useNavigateToNextRecordSingleRecordAction';
import { useNavigateToPreviousRecordSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useNavigateToPreviousRecordSingleRecordAction';
import { useRemoveFromFavoritesSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useRemoveFromFavoritesSingleRecordAction';
import { SingleRecordActionKeys } from '@/action-menu/actions/record-actions/single-record/types/SingleRecordActionsKey';
import { ActionAvailableOn } from '@/action-menu/actions/types/ActionAvailableOn';
import { SingleRecordActionHook } from '@/action-menu/actions/types/SingleRecordActionHook';
import {
ActionMenuEntry,
ActionMenuEntryScope,
ActionMenuEntryType,
} from '@/action-menu/types/ActionMenuEntry';
import {
IconChevronDown,
IconChevronUp,
IconHeart,
IconHeartOff,
} from 'twenty-ui';

export const WORKFLOW_RUNS_SINGLE_RECORD_ACTIONS_CONFIG: Record<
string,
ActionMenuEntry & {
actionHook: SingleRecordActionHook;
}
> = {
addToFavoritesSingleRecord: {
type: ActionMenuEntryType.Standard,
scope: ActionMenuEntryScope.RecordSelection,
key: SingleRecordActionKeys.ADD_TO_FAVORITES,
label: 'Add to favorites',
shortLabel: 'Add to favorites',
position: 0,
isPinned: true,
Icon: IconHeart,
availableOn: [
ActionAvailableOn.INDEX_PAGE_SINGLE_RECORD_SELECTION,
ActionAvailableOn.SHOW_PAGE,
],
actionHook: useAddToFavoritesSingleRecordAction,
},
removeFromFavoritesSingleRecord: {
type: ActionMenuEntryType.Standard,
scope: ActionMenuEntryScope.RecordSelection,
key: SingleRecordActionKeys.REMOVE_FROM_FAVORITES,
label: 'Remove from favorites',
shortLabel: 'Remove from favorites',
isPinned: true,
position: 1,
Icon: IconHeartOff,
availableOn: [
ActionAvailableOn.INDEX_PAGE_SINGLE_RECORD_SELECTION,
ActionAvailableOn.SHOW_PAGE,
],
actionHook: useRemoveFromFavoritesSingleRecordAction,
},
navigateToPreviousRecord: {
type: ActionMenuEntryType.Standard,
scope: ActionMenuEntryScope.RecordSelection,
key: SingleRecordActionKeys.NAVIGATE_TO_PREVIOUS_RECORD,
label: 'Navigate to previous record',
shortLabel: '',
position: 2,
isPinned: true,
Icon: IconChevronUp,
availableOn: [ActionAvailableOn.SHOW_PAGE],
actionHook: useNavigateToPreviousRecordSingleRecordAction,
},
navigateToNextRecord: {
type: ActionMenuEntryType.Standard,
scope: ActionMenuEntryScope.RecordSelection,
key: SingleRecordActionKeys.NAVIGATE_TO_NEXT_RECORD,
label: 'Navigate to next record',
shortLabel: '',
position: 3,
isPinned: true,
Icon: IconChevronDown,
availableOn: [ActionAvailableOn.SHOW_PAGE],
actionHook: useNavigateToNextRecordSingleRecordAction,
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { useAddToFavoritesSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useAddToFavoritesSingleRecordAction';
import { useDeleteSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useDeleteSingleRecordAction';
import { useDestroySingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useDestroySingleRecordAction';
import { useNavigateToNextRecordSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useNavigateToNextRecordSingleRecordAction';
import { useNavigateToPreviousRecordSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useNavigateToPreviousRecordSingleRecordAction';
import { useRemoveFromFavoritesSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/hooks/useRemoveFromFavoritesSingleRecordAction';
Expand All @@ -24,8 +22,6 @@ import {
IconHistory,
IconHistoryToggle,
IconPencil,
IconTrash,
IconTrashX,
} from 'twenty-ui';

export const WORKFLOW_VERSIONS_SINGLE_RECORD_ACTIONS_CONFIG: Record<
Expand All @@ -37,6 +33,7 @@ export const WORKFLOW_VERSIONS_SINGLE_RECORD_ACTIONS_CONFIG: Record<
useAsDraftWorkflowVersionSingleRecord: {
key: WorkflowVersionSingleRecordActionKeys.USE_AS_DRAFT,
label: 'Use as draft',
shortLabel: 'Use as draft',
position: 1,
isPinned: true,
type: ActionMenuEntryType.Standard,
Expand All @@ -51,6 +48,7 @@ export const WORKFLOW_VERSIONS_SINGLE_RECORD_ACTIONS_CONFIG: Record<
seeWorkflowRunsSingleRecord: {
key: WorkflowVersionSingleRecordActionKeys.SEE_RUNS,
label: 'See runs',
shortLabel: 'See runs',
position: 2,
type: ActionMenuEntryType.Standard,
scope: ActionMenuEntryScope.RecordSelection,
Expand All @@ -64,6 +62,7 @@ export const WORKFLOW_VERSIONS_SINGLE_RECORD_ACTIONS_CONFIG: Record<
seeWorkflowVersionsHistorySingleRecord: {
key: WorkflowVersionSingleRecordActionKeys.SEE_VERSIONS,
label: 'See versions history',
shortLabel: 'See versions',
position: 3,
type: ActionMenuEntryType.Standard,
scope: ActionMenuEntryScope.RecordSelection,
Expand Down Expand Up @@ -126,36 +125,4 @@ export const WORKFLOW_VERSIONS_SINGLE_RECORD_ACTIONS_CONFIG: Record<
],
actionHook: useRemoveFromFavoritesSingleRecordAction,
},
deleteSingleRecord: {
type: ActionMenuEntryType.Standard,
scope: ActionMenuEntryScope.RecordSelection,
key: SingleRecordActionKeys.DELETE,
label: 'Delete record',
shortLabel: 'Delete',
position: 8,
Icon: IconTrash,
accent: 'danger',
isPinned: false,
availableOn: [
ActionAvailableOn.INDEX_PAGE_SINGLE_RECORD_SELECTION,
ActionAvailableOn.SHOW_PAGE,
],
actionHook: useDeleteSingleRecordAction,
},
destroySingleRecord: {
type: ActionMenuEntryType.Standard,
scope: ActionMenuEntryScope.RecordSelection,
key: SingleRecordActionKeys.DESTROY,
label: 'Permanently destroy record',
shortLabel: 'Destroy',
position: 9,
Icon: IconTrashX,
accent: 'danger',
isPinned: false,
availableOn: [
ActionAvailableOn.INDEX_PAGE_SINGLE_RECORD_SELECTION,
ActionAvailableOn.SHOW_PAGE,
],
actionHook: useDestroySingleRecordAction,
},
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SingleRecordActionHookWithoutObjectMetadataItem } from '@/action-menu/actions/types/SingleRecordActionHook';
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { FilterQueryParams } from '@/views/hooks/internal/useViewFromQueryParams';
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
import qs from 'qs';
Expand All @@ -24,13 +23,17 @@ export const useSeeRunsWorkflowVersionSingleRecordAction: SingleRecordActionHook
const onClick = () => {
if (!shouldBeRegistered) return;

const filterQueryParams: FilterQueryParams = {
const filterQueryParams = {
filter: {
workflow: {
[ViewFilterOperand.Is]: [workflowWithCurrentVersion.id],
[ViewFilterOperand.Is]: {
selectedRecordIds: [workflowWithCurrentVersion.id],
},
},
workflowVersion: {
[ViewFilterOperand.Is]: [recordId],
[ViewFilterOperand.Is]: {
selectedRecordIds: [recordId],
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const RecordShowRightDrawerActionMenu = () => {
<ActionMenuContext.Provider
value={{
isInRightDrawer: true,
onActionExecutedCallback: () => {},
}}
>
<RightDrawerActionMenuDropdown />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ObjectOptionsDropdownContextValue } from '@/object-record/object-options-dropdown/states/contexts/ObjectOptionsDropdownContext';
import { RecordBoardColumnHeaderAggregateDropdownContextValue } from '@/object-record/record-board/record-board-column/components/RecordBoardColumnHeaderAggregateDropdownContext';
import { RecordTableColumnAggregateFooterDropdownContextValue } from '@/object-record/record-table/record-table-footer/components/RecordTableColumnAggregateFooterDropdownContext';
import { useDropdown as useDropdownUi } from '@/ui/layout/dropdown/hooks/useDropdown';
import { Context, useCallback, useContext } from 'react';

export const useDropdown = <
T extends
| RecordBoardColumnHeaderAggregateDropdownContextValue
| RecordTableColumnAggregateFooterDropdownContextValue
| ObjectOptionsDropdownContextValue,
>({
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FavoritesDragContext } from '@/favorites/contexts/FavoritesDragContext'
import { useDeleteFavorite } from '@/favorites/hooks/useDeleteFavorite';
import { useDeleteFavoriteFolder } from '@/favorites/hooks/useDeleteFavoriteFolder';
import { useRenameFavoriteFolder } from '@/favorites/hooks/useRenameFavoriteFolder';
import { activeFavoriteFolderIdState } from '@/favorites/states/activeFavoriteFolderIdState';
import { openFavoriteFolderIdsState } from '@/favorites/states/openFavoriteFolderIdsState';
import { isLocationMatchingFavorite } from '@/favorites/utils/isLocationMatchingFavorite';
import { ProcessedFavorite } from '@/favorites/utils/sortFavorites';
import { DraggableItem } from '@/ui/layout/draggable-list/components/DraggableItem';
Expand Down Expand Up @@ -50,13 +50,20 @@ export const CurrentWorkspaceMemberFavorites = ({
folder.folderName,
);
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [activeFavoriteFolderId, setActiveFavoriteFolderId] = useRecoilState(
activeFavoriteFolderIdState,

const [openFavoriteFolderIds, setOpenFavoriteFolderIds] = useRecoilState(
openFavoriteFolderIdsState,
);
const isOpen = activeFavoriteFolderId === folder.folderId;
const isOpen = openFavoriteFolderIds.includes(folder.folderId);

const handleToggle = () => {
setActiveFavoriteFolderId(isOpen ? null : folder.folderId);
setOpenFavoriteFolderIds((currentOpenFolders) => {
if (isOpen) {
return currentOpenFolders.filter((id) => id !== folder.folderId);
} else {
return [...currentOpenFolders, folder.folderId];
}
});
};

const { renameFavoriteFolder } = useRenameFavoriteFolder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FAVORITE_DROPPABLE_IDS } from '@/favorites/constants/FavoriteDroppableIds';
import { useSortedFavorites } from '@/favorites/hooks/useSortedFavorites';
import { activeFavoriteFolderIdState } from '@/favorites/states/activeFavoriteFolderIdState';
import { openFavoriteFolderIdsState } from '@/favorites/states/openFavoriteFolderIdsState';
import { calculateNewPosition } from '@/favorites/utils/calculateNewPosition';
import { validateAndExtractFolderId } from '@/favorites/utils/validateAndExtractFolderId';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
Expand All @@ -15,10 +15,21 @@ export const useHandleFavoriteDragAndDrop = () => {
const { updateOneRecord: updateOneFavorite } = useUpdateOneRecord({
objectNameSingular: CoreObjectNameSingular.Favorite,
});
const setActiveFavoriteFolderId = useSetRecoilState(
activeFavoriteFolderIdState,
const setOpenFavoriteFolderIds = useSetRecoilState(
openFavoriteFolderIdsState,
);

const openDestinationFolder = (folderId: string | null) => {
if (!folderId) return;

setOpenFavoriteFolderIds((current) => {
if (!current.includes(folderId)) {
return [...current, folderId];
}
return current;
});
};

const handleFavoriteDragAndDrop: OnDragEndResponder = (result) => {
const { destination, source, draggableId } = result;

Expand Down Expand Up @@ -64,7 +75,7 @@ export const useHandleFavoriteDragAndDrop = () => {
},
});

setActiveFavoriteFolderId(destinationFolderId);
openDestinationFolder(destinationFolderId);
return;
}

Expand Down
Loading

0 comments on commit 8c3f91c

Please sign in to comment.