Fix error when workflows aren't enabled (#11388)

Fix Uncaught Error: Workflow is not enabled. If you want to use it,
please enable it in the lab.
<img width="505" alt="erroractionmenu"
src="https://github.com/user-attachments/assets/66e60219-20fb-4b00-90e4-d6bd640be774"
/>

This error was due to using the hook `useWorkflowWithCurrentVersion`
outside of a workflow object. Adding a skip parameter wasn't enough
because the `useFindOneRecord` uses `useObjectMetadataItem` which throws
if workflows aren't enabled.
This commit is contained in:
Raphaël Bosi
2025-04-04 14:26:19 +02:00
committed by GitHub
parent 27256c960e
commit ad2357a6fd
6 changed files with 75 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import { ActionViewType } from '@/action-menu/actions/types/ActionViewType';
import { ShouldBeRegisteredFunctionParams } from '@/action-menu/actions/types/ShouldBeRegisteredFunctionParams';
import { getActionConfig } from '@/action-menu/actions/utils/getActionConfig';
import { getActionViewType } from '@/action-menu/actions/utils/getActionViewType';
import { useShouldActionBeRegisteredParams } from '@/action-menu/hooks/useShouldActionBeRegisteredParams';
import { contextStoreCurrentViewTypeComponentState } from '@/context-store/states/contextStoreCurrentViewTypeComponentState';
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
@ -10,13 +10,11 @@ import { isDefined } from 'twenty-shared/utils';
export const useRegisteredRecordActions = ({
objectMetadataItem,
shouldBeRegisteredParams,
}: {
objectMetadataItem: ObjectMetadataItem;
shouldBeRegisteredParams: ShouldBeRegisteredFunctionParams;
}) => {
const params = useShouldActionBeRegisteredParams({
objectMetadataItem,
});
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2(
contextStoreTargetedRecordsRuleComponentState,
);
@ -41,7 +39,7 @@ export const useRegisteredRecordActions = ({
: [];
const actions = actionsToRegister.filter((action) =>
action.shouldBeRegistered(params),
action.shouldBeRegistered(shouldBeRegisteredParams),
);
return actions;

View File

@ -10,7 +10,6 @@ import { recordStoreFamilyState } from '@/object-record/record-store/states/reco
import { isSoftDeleteFilterActiveComponentState } from '@/object-record/record-table/states/isSoftDeleteFilterActiveComponentState';
import { useHasObjectReadOnlyPermission } from '@/settings/roles/hooks/useHasObjectReadOnlyPermission';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { useContext } from 'react';
import { useRecoilValue } from 'recoil';
@ -67,11 +66,6 @@ export const useShouldActionBeRegisteredParams = ({
contextStoreNumberOfSelectedRecordsComponentState,
);
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(
recordId,
objectMetadataItem.nameSingular !== CoreObjectNameSingular.Workflow,
);
return {
isFavorite,
isRemoteObject,
@ -83,6 +77,5 @@ export const useShouldActionBeRegisteredParams = ({
selectedRecord,
isWorkflowsEnabled,
numberOfSelectedRecords,
workflowWithCurrentVersion,
};
};