Fix workflow with manual triggers and no selection not appearing in the command menu (#11544)

Fix workflow with manual triggers and no selection not appearing in the
command menu

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Raphaël Bosi
2025-04-14 11:03:29 +02:00
committed by GitHub
parent b5a1d1a895
commit ace515eea7
13 changed files with 86 additions and 70 deletions

View File

@ -1,10 +1,9 @@
import { ActionMenuContextType } from '@/action-menu/contexts/ActionMenuContext';
import { ActionMenuContextProviderWorkflowObjects } from '@/action-menu/contexts/ActionMenuContextProviderWorkflowObjects';
import { ActionMenuContextProviderWorkflowsEnabled } from '@/action-menu/contexts/ActionMenuContextProviderWorkflowsEnabled';
import { ActionMenuContextProviderWorkflowsEnabledSingleRecordSelection } from '@/action-menu/contexts/ActionMenuContextProviderWorkflowsEnabledSingleRecordSelection';
import { ActionMenuContextProviderWorkflowsNotEnabled } from '@/action-menu/contexts/ActionMenuContextProviderWorkflowsNotEnabled';
import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';
import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState';
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
@ -50,39 +49,30 @@ export const ActionMenuContextProvider = ({
const objectMetadataItem =
localContextStoreObjectMetadataItem ?? mainContextStoreObjectMetadataItem;
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2(
contextStoreTargetedRecordsRuleComponentState,
);
const isSingleRecordSelection =
contextStoreTargetedRecordsRule.mode === 'selection' &&
contextStoreTargetedRecordsRule.selectedRecordIds.length === 1;
const isWorkflowObject =
objectMetadataItem?.nameSingular === CoreObjectNameSingular.Workflow ||
objectMetadataItem?.nameSingular === CoreObjectNameSingular.WorkflowRun ||
objectMetadataItem?.nameSingular === CoreObjectNameSingular.WorkflowVersion;
if (
isWorkflowEnabled &&
isSingleRecordSelection &&
isDefined(objectMetadataItem) &&
(actionMenuType === 'command-menu' ||
actionMenuType === 'command-menu-show-page-action-menu-dropdown')
) {
if (isWorkflowEnabled && isDefined(objectMetadataItem) && isWorkflowObject) {
return (
<ActionMenuContextProviderWorkflowsEnabledSingleRecordSelection
<ActionMenuContextProviderWorkflowObjects
isInRightDrawer={isInRightDrawer}
displayType={displayType}
actionMenuType={actionMenuType}
objectMetadataItem={objectMetadataItem}
>
{children}
</ActionMenuContextProviderWorkflowsEnabledSingleRecordSelection>
</ActionMenuContextProviderWorkflowObjects>
);
}
if (isWorkflowEnabled && isDefined(objectMetadataItem) && isWorkflowObject) {
if (
isWorkflowEnabled &&
isDefined(objectMetadataItem) &&
(actionMenuType === 'command-menu' ||
actionMenuType === 'command-menu-show-page-action-menu-dropdown')
) {
return (
<ActionMenuContextProviderWorkflowsEnabled
isInRightDrawer={isInRightDrawer}

View File

@ -1,4 +1,4 @@
import { useWorkflowRunRecordActions } from '@/action-menu/actions/record-actions/workflow-run-record-actions/hooks/useWorkflowRunRecordActions';
import { useRunWorkflowRecordAgnosticActions } from '@/action-menu/actions/record-agnostic-actions/run-workflow-actions/hooks/useRunWorkflowRecordAgnosticActions';
import {
ActionMenuContext,
ActionMenuContextType,
@ -8,7 +8,7 @@ import { useShouldActionBeRegisteredParams } from '@/action-menu/hooks/useShould
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
export const ActionMenuContextProviderWorkflowsEnabledSingleRecordSelection = ({
export const ActionMenuContextProviderWorkflowObjects = ({
objectMetadataItem,
isInRightDrawer,
displayType,
@ -36,9 +36,8 @@ export const ActionMenuContextProviderWorkflowsEnabledSingleRecordSelection = ({
const actions = useRegisteredActions(shouldBeRegisteredParams);
const workflowRunRecordActions = useWorkflowRunRecordActions({
objectMetadataItem,
});
const runWorkflowRecordAgnosticActions =
useRunWorkflowRecordAgnosticActions();
return (
<ActionMenuContext.Provider
@ -46,7 +45,7 @@ export const ActionMenuContextProviderWorkflowsEnabledSingleRecordSelection = ({
isInRightDrawer,
displayType,
actionMenuType,
actions: [...actions, ...workflowRunRecordActions],
actions: [...actions, ...runWorkflowRecordAgnosticActions],
}}
>
{children}

View File

@ -1,10 +1,14 @@
import { useRunWorkflowRecordActions } from '@/action-menu/actions/record-actions/run-workflow-actions/hooks/useRunWorkflowRecordActions';
import { useRunWorkflowRecordAgnosticActions } from '@/action-menu/actions/record-agnostic-actions/run-workflow-actions/hooks/useRunWorkflowRecordAgnosticActions';
import {
ActionMenuContext,
ActionMenuContextType,
} from '@/action-menu/contexts/ActionMenuContext';
import { useRegisteredActions } from '@/action-menu/hooks/useRegisteredActions';
import { useShouldActionBeRegisteredParams } from '@/action-menu/hooks/useShouldActionBeRegisteredParams';
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
export const ActionMenuContextProviderWorkflowsEnabled = ({
@ -35,13 +39,33 @@ export const ActionMenuContextProviderWorkflowsEnabled = ({
const actions = useRegisteredActions(shouldBeRegisteredParams);
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2(
contextStoreTargetedRecordsRuleComponentState,
);
const isSingleRecordSelection =
contextStoreTargetedRecordsRule.mode === 'selection' &&
contextStoreTargetedRecordsRule.selectedRecordIds.length === 1;
const runWorkflowRecordActions = useRunWorkflowRecordActions({
objectMetadataItem,
skip: !isSingleRecordSelection,
});
const runWorkflowRecordAgnosticActions =
useRunWorkflowRecordAgnosticActions();
return (
<ActionMenuContext.Provider
value={{
isInRightDrawer,
displayType,
actionMenuType,
actions,
actions: [
...actions,
...runWorkflowRecordActions,
...runWorkflowRecordAgnosticActions,
],
}}
>
{children}