Fix manual trigger output schema (#8150)
- add schema for manual trigger - split into sub functions - handle case with no variables
This commit is contained in:
@ -87,6 +87,7 @@ export const WorkflowEditTriggerManualForm = ({
|
||||
...trigger,
|
||||
settings: {
|
||||
objectType: updatedObject,
|
||||
outputSchema: {},
|
||||
},
|
||||
});
|
||||
}}
|
||||
|
||||
@ -6,13 +6,13 @@ import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
||||
import { SearchVariablesDropdownStepItem } from '@/workflow/search-variables/components/SearchVariablesDropdownStepItem';
|
||||
import SearchVariablesDropdownStepSubItem from '@/workflow/search-variables/components/SearchVariablesDropdownStepSubItem';
|
||||
import { SEARCH_VARIABLES_DROPDOWN_ID } from '@/workflow/search-variables/constants/SearchVariablesDropdownId';
|
||||
import { useAvailableVariablesInWorkflowStep } from '@/workflow/search-variables/hooks/useAvailableVariablesInWorkflowStep';
|
||||
import { StepOutputSchema } from '@/workflow/search-variables/types/StepOutputSchema';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import styled from '@emotion/styled';
|
||||
import { Editor } from '@tiptap/react';
|
||||
import { useState } from 'react';
|
||||
import { IconVariable } from 'twenty-ui';
|
||||
import { useAvailableVariablesInWorkflowStep } from '@/workflow/hooks/useAvailableVariablesInWorkflowStep';
|
||||
|
||||
const StyledDropdownVariableButtonContainer = styled(
|
||||
StyledDropdownButtonContainer,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
|
||||
import { MenuItemSelect } from '@/ui/navigation/menu-item/components/MenuItemSelect';
|
||||
import { StepOutputSchema } from '@/workflow/search-variables/types/StepOutputSchema';
|
||||
|
||||
@ -10,7 +11,7 @@ export const SearchVariablesDropdownStepItem = ({
|
||||
steps,
|
||||
onSelect,
|
||||
}: SearchVariablesDropdownStepItemProps) => {
|
||||
return (
|
||||
return steps.length > 0 ? (
|
||||
<>
|
||||
{steps.map((item, _index) => (
|
||||
<MenuItemSelect
|
||||
@ -24,5 +25,13 @@ export const SearchVariablesDropdownStepItem = ({
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
) : (
|
||||
<MenuItem
|
||||
key="no-steps"
|
||||
onClick={() => {}}
|
||||
text="No variables available"
|
||||
LeftIcon={undefined}
|
||||
hasSubMenu={false}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { workflowIdState } from '@/workflow/states/workflowIdState';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { StepOutputSchema } from '@/workflow/search-variables/types/StepOutputSchema';
|
||||
import { getTriggerStepName } from '@/workflow/search-variables/utils/getTriggerStepName';
|
||||
import { workflowIdState } from '@/workflow/states/workflowIdState';
|
||||
import { workflowSelectedNodeState } from '@/workflow/states/workflowSelectedNodeState';
|
||||
import { getStepDefinitionOrThrow } from '@/workflow/utils/getStepDefinitionOrThrow';
|
||||
import isEmpty from 'lodash.isempty';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
import { StepOutputSchema } from '@/workflow/search-variables/types/StepOutputSchema';
|
||||
import { isEmptyObject } from '~/utils/isEmptyObject';
|
||||
|
||||
export const useAvailableVariablesInWorkflowStep = (): StepOutputSchema[] => {
|
||||
const workflowId = useRecoilValue(workflowIdState);
|
||||
@ -41,20 +43,22 @@ export const useAvailableVariablesInWorkflowStep = (): StepOutputSchema[] => {
|
||||
const result = [];
|
||||
|
||||
if (
|
||||
workflow.currentVersion.trigger?.type === 'DATABASE_EVENT' &&
|
||||
isDefined(workflow.currentVersion.trigger?.settings?.outputSchema)
|
||||
isDefined(workflow.currentVersion.trigger) &&
|
||||
isDefined(workflow.currentVersion.trigger?.settings?.outputSchema) &&
|
||||
!isEmptyObject(workflow.currentVersion.trigger?.settings?.outputSchema)
|
||||
) {
|
||||
const [object, action] =
|
||||
workflow.currentVersion.trigger.settings.eventName.split('.');
|
||||
result.push({
|
||||
id: 'trigger',
|
||||
name: `${capitalize(object)} is ${capitalize(action)}`,
|
||||
name: getTriggerStepName(workflow.currentVersion.trigger),
|
||||
outputSchema: workflow.currentVersion.trigger.settings.outputSchema,
|
||||
});
|
||||
}
|
||||
|
||||
previousSteps.forEach((previousStep) => {
|
||||
if (isDefined(previousStep.settings.outputSchema)) {
|
||||
if (
|
||||
isDefined(previousStep.settings.outputSchema) &&
|
||||
!isEmpty(previousStep.settings.outputSchema)
|
||||
) {
|
||||
result.push({
|
||||
id: previousStep.id,
|
||||
name: previousStep.name,
|
||||
@ -0,0 +1,28 @@
|
||||
import {
|
||||
WorkflowDatabaseEventTrigger,
|
||||
WorkflowTrigger,
|
||||
} from '@/workflow/types/Workflow';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const getTriggerStepName = (trigger: WorkflowTrigger): string => {
|
||||
switch (trigger.type) {
|
||||
case 'DATABASE_EVENT':
|
||||
return getDatabaseEventTriggerStepName(trigger);
|
||||
case 'MANUAL':
|
||||
if (!trigger.settings.objectType) {
|
||||
return 'Manual trigger';
|
||||
}
|
||||
|
||||
return 'Manual trigger for ' + capitalize(trigger.settings.objectType);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const getDatabaseEventTriggerStepName = (
|
||||
trigger: WorkflowDatabaseEventTrigger,
|
||||
): string => {
|
||||
const [object, action] = trigger.settings.eventName.split('.');
|
||||
|
||||
return `${capitalize(object)} is ${capitalize(action)}`;
|
||||
};
|
||||
@ -69,6 +69,7 @@ export type WorkflowManualTrigger = BaseTrigger & {
|
||||
type: 'MANUAL';
|
||||
settings: {
|
||||
objectType?: string;
|
||||
outputSchema: object;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -16,11 +16,13 @@ export const getManualTriggerDefaultSettings = ({
|
||||
case 'EVERYWHERE': {
|
||||
return {
|
||||
objectType: undefined,
|
||||
outputSchema: {},
|
||||
};
|
||||
}
|
||||
case 'WHEN_RECORD_SELECTED': {
|
||||
return {
|
||||
objectType: activeObjectMetadataItems[0].nameSingular,
|
||||
outputSchema: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user