Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {DEFAULT_SCHEMA} from '@/components/JsonSchemaBuilder/utils/constants';
import {SchemaRecordType} from '@/components/JsonSchemaBuilder/utils/types';
import RequiredMark from '@/components/RequiredMark';
import {Label} from '@/components/ui/label';
import {Skeleton} from '@/components/ui/skeleton';
import {Tooltip, TooltipContent, TooltipTrigger} from '@/components/ui/tooltip';
import InputTypeSwitchButton from '@/pages/platform/workflow-editor/components/Properties/components/InputTypeSwitchButton';
import PropertyCodeEditor from '@/pages/platform/workflow-editor/components/Properties/components/PropertyCodeEditor/PropertyCodeEditor';
Expand All @@ -22,6 +23,7 @@ import deleteProperty from '@/pages/platform/workflow-editor/utils/deletePropert
import getInputHTMLType from '@/pages/platform/workflow-editor/utils/getInputHTMLType';
import saveProperty from '@/pages/platform/workflow-editor/utils/saveProperty';
import {Option} from '@/shared/middleware/platform/configuration';
import {useGetWorkflowNodeParameterDisplayConditionsQuery} from '@/shared/queries/platform/workflowNodeParameters.queries';
import {ArrayPropertyType, PropertyAllType} from '@/shared/types';
import {QuestionMarkCircledIcon} from '@radix-ui/react-icons';
import {TooltipPortal} from '@radix-ui/react-tooltip';
Expand Down Expand Up @@ -122,6 +124,15 @@ const Property = ({
const {showPropertyCodeEditorSheet, showPropertyJsonSchemaBuilder, showWorkflowCodeEditorSheet} =
useWorkflowEditorStore();

const {isFetching: isFetchingDisplayConditions} = useGetWorkflowNodeParameterDisplayConditionsQuery(
{
id: workflow.id!,
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
workflowNodeName: currentNode?.workflowNodeName!,
},
!!currentNode?.workflowNodeName
);

const previousOperationName = usePrevious(currentNode?.operationName);
const previousMentionInputValue = usePrevious(mentionInputValue);

Expand Down Expand Up @@ -906,6 +917,16 @@ const Property = ({
return <></>;
}

if (displayCondition && currentComponent?.displayConditions?.[displayCondition] && isFetchingDisplayConditions) {
return (
<div className="flex flex-col gap-y-2">
<Skeleton className="h-6 w-1/4" />

<Skeleton className="h-10 w-full" />
</div>
);
}

return (
<li
className={twMerge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
NodeDataType,
PropertyAllType,
UpdateWorkflowMutationType,
WorkflowDefinitionType,
} from '@/shared/types';
import {Cross2Icon, InfoCircledIcon} from '@radix-ui/react-icons';
import {TooltipPortal} from '@radix-ui/react-tooltip';
Expand All @@ -47,7 +46,6 @@ import {twMerge} from 'tailwind-merge';

import useWorkflowDataStore from '../stores/useWorkflowDataStore';
import useWorkflowNodeDetailsPanelStore from '../stores/useWorkflowNodeDetailsPanelStore';
import getAllTaskNames from '../utils/getAllTaskNames';
import getDataPillsFromProperties from '../utils/getDataPillsFromProperties';
import getParametersWithDefaultValues from '../utils/getParametersWithDefaultValues';
import saveWorkflowDefinition from '../utils/saveWorkflowDefinition';
Expand Down Expand Up @@ -93,7 +91,6 @@ const WorkflowNodeDetailsPanel = ({
const [availableDataPills, setAvailableDataPills] = useState<Array<DataPillType>>();
const [currentOperationName, setCurrentOperationName] = useState('');
const [currentOperationProperties, setCurrentOperationProperties] = useState<Array<PropertyAllType>>([]);
const [workflowDefinition, setWorkflowDefinition] = useState<WorkflowDefinitionType>({});

const {currentComponent, currentNode, setCurrentComponent, setCurrentNode, workflowNodeDetailsPanelOpen} =
useWorkflowNodeDetailsPanelStore();
Expand All @@ -102,7 +99,7 @@ const WorkflowNodeDetailsPanel = ({

const {data: currentComponentDefinition} = useGetComponentDefinitionQuery(
{
componentName: currentNode?.componentName || currentNode?.id || '',
componentName: currentNode?.componentName || '',
componentVersion: currentNode?.version || 1,
},
!!currentNode && !currentNode.taskDispatcher
Expand All @@ -111,7 +108,7 @@ const WorkflowNodeDetailsPanel = ({
const {data: workflowTestConfigurationConnections} = useGetWorkflowTestConfigurationConnectionsQuery(
{
workflowId: workflow.id as string,
workflowNodeName: currentNode?.name as string,
workflowNodeName: currentNode?.workflowNodeName as string,
},
!!workflow.id && !!currentNode
);
Expand Down Expand Up @@ -149,7 +146,7 @@ const WorkflowNodeDetailsPanel = ({

const {data: currentTaskDispatcherDefinition} = useGetTaskDispatcherDefinitionQuery(
{
taskDispatcherName: currentNode?.componentName || currentNode?.id || '',
taskDispatcherName: currentNode?.componentName || '',
taskDispatcherVersion: currentNode?.version || 1,
},
!!currentNode && !!currentNode.taskDispatcher
Expand All @@ -163,7 +160,7 @@ const WorkflowNodeDetailsPanel = ({

const {nodeNames} = workflow;

const currentNodeIndex = currentNode && nodeNames?.indexOf(currentNode?.name);
const currentNodeIndex = currentNode && nodeNames?.indexOf(currentNode?.workflowNodeName);

const previousNodeNames = nodeNames.length > 1 ? nodeNames?.slice(0, currentNodeIndex) : [];

Expand Down Expand Up @@ -191,8 +188,8 @@ const WorkflowNodeDetailsPanel = ({
);

const hasOutputData = currentNodeDefinition?.outputDefined;
const currentWorkflowTrigger = workflow.triggers?.find((trigger) => trigger.name === currentNode?.name);
const currentWorkflowTask = workflow.tasks?.find((task) => task.name === currentNode?.name);
const currentWorkflowTrigger = workflow.triggers?.find((trigger) => trigger.name === currentNode?.workflowNodeName);
const currentWorkflowTask = workflow.tasks?.find((task) => task.name === currentNode?.workflowNodeName);

const componentConnections: WorkflowConnection[] =
currentWorkflowTask?.connections || currentWorkflowTrigger?.connections || [];
Expand All @@ -219,6 +216,20 @@ const WorkflowNodeDetailsPanel = ({
return true;
});

const currentTaskData = currentComponentDefinition || currentTaskDispatcherDefinition;
const currentOperationFetched = currentActionFetched || currentTriggerFetched;

const operationDataMissing =
currentComponent?.operationName && (!matchingOperation?.name || !currentOperationFetched);

const tabDataExists =
(!currentNode?.trigger && !currentNode?.taskDispatcher && currentActionFetched) ||
currentNode?.taskDispatcher ||
(currentNode?.trigger &&
currentTriggerFetched &&
nodeTabs.length > 1 &&
currentNode.componentName !== 'manual');

const queryClient = useQueryClient();

const handleOperationSelectChange = async (newOperationName: string) => {
Expand Down Expand Up @@ -264,17 +275,18 @@ const WorkflowNodeDetailsPanel = ({

const {componentName, description, label, workflowNodeName} = currentComponent;

let nodeData = {
let nodeData: NodeDataType = {
componentName,
description,
label,
name: workflowNodeName || currentNode?.name || '',
name: workflowNodeName || currentNode?.workflowNodeName || '',
operationName: newOperationName,
parameters: getParametersWithDefaultValues({
properties: operationData.properties as Array<PropertyAllType>,
}),
trigger: currentNode?.trigger,
type: `${componentName}/v${currentComponentDefinition.version}/${newOperationName}`,
workflowNodeName,
};

if (currentNode?.conditionData) {
Expand Down Expand Up @@ -312,7 +324,7 @@ const WorkflowNodeDetailsPanel = ({
return;
}

const updatedRootConditionNode = updateConditionSubtask({
nodeData = updateConditionSubtask({
conditionCase,
conditionId: currentNode.conditionData.conditionId,
nodeIndex: taskIndex,
Expand All @@ -322,8 +334,6 @@ const WorkflowNodeDetailsPanel = ({
updatedParentConditionTask,
workflow,
});

nodeData = updatedRootConditionNode.data ?? (updatedRootConditionNode as NodeDataType);
}
}
}
Expand Down Expand Up @@ -426,6 +436,10 @@ const WorkflowNodeDetailsPanel = ({
if (activeTab === 'output' && !hasOutputData) {
setActiveTab('description');
}

if (activeTab === 'properties' && !operationDataMissing && !currentOperationProperties?.length) {
setActiveTab('description');
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
activeTab,
Expand All @@ -435,13 +449,6 @@ const WorkflowNodeDetailsPanel = ({
currentComponentDefinition?.name,
]);

// Close the panel if the current node is deleted
useEffect(() => {
if (!currentNode?.name || !nodeNames.includes(currentNode?.name)) {
useWorkflowNodeDetailsPanelStore.getState().reset();
}
}, [currentNode?.name, nodeNames]);

// If the current component requires a connection, set the active tab to 'connection'
useEffect(() => {
if (currentComponentDefinition?.connectionRequired && !workflowTestConfigurationConnections?.length) {
Expand All @@ -461,31 +468,6 @@ const WorkflowNodeDetailsPanel = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [workflowTestConfigurationConnections]);

// Parse the workflow definition to an object
useEffect(() => {
if (workflow.definition) {
setWorkflowDefinition(JSON.parse(workflow.definition));
}
}, [workflow.definition]);

// Close the panel if the current node is deleted from the workflow definition
useEffect(() => {
if (currentNode?.trigger) {
return;
}

if (!workflowDefinition.tasks) {
return;
}

const taskNames = getAllTaskNames(workflowDefinition.tasks);

if (currentNode && taskNames && !taskNames?.includes(currentNode?.name)) {
useWorkflowNodeDetailsPanelStore.getState().reset();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentNode, workflowDefinition.tasks?.length]);

// Store new operationName into currentNode
useEffect(() => {
if (currentNode?.operationName && currentOperationName) {
Expand All @@ -502,38 +484,24 @@ const WorkflowNodeDetailsPanel = ({
useEffect(() => {
if (componentActions?.length) {
const currentComponentAction = componentActions.find(
(action) => action.workflowNodeName === currentNode?.name
(action) => action.workflowNodeName === currentNode?.workflowNodeName
);

if (currentComponentAction) {
setCurrentOperationName(currentComponentAction.operationName);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [componentActions, currentNode?.name]);

const currentTaskData = currentComponentDefinition || currentTaskDispatcherDefinition;
const currentOperationFetched = currentActionFetched || currentTriggerFetched;

const operationDataMissing =
currentComponent?.operationName && (!matchingOperation?.name || !currentOperationFetched);
}, [componentActions, currentNode?.workflowNodeName]);

const tabDataExists =
(!currentNode?.trigger && !currentNode?.taskDispatcher && currentActionFetched) ||
currentNode?.taskDispatcher ||
(currentNode?.trigger &&
currentTriggerFetched &&
nodeTabs.length > 1 &&
currentNode.componentName !== 'manual');

if (!workflowNodeDetailsPanelOpen || !currentNode?.name || !currentTaskData) {
if (!workflowNodeDetailsPanelOpen || !currentNode?.workflowNodeName || !currentTaskData) {
return <></>;
}

return (
<div
className="absolute inset-y-4 right-4 z-10 w-screen max-w-workflow-node-details-panel-width overflow-hidden rounded-xl border border-border/50 bg-white shadow-lg"
key={currentNode?.name}
key={currentNode?.workflowNodeName}
>
<div className="flex h-full flex-col divide-y divide-gray-100 bg-white">
<header className="flex items-center p-4 text-lg font-medium">
Expand All @@ -547,7 +515,7 @@ const WorkflowNodeDetailsPanel = ({

{currentNode?.label}

<span className="mx-2 text-sm text-gray-500">({currentNode?.name})</span>
<span className="mx-2 text-sm text-gray-500">({currentNode?.workflowNodeName})</span>

{currentTaskData.description && (
<Tooltip delayDuration={500}>
Expand Down Expand Up @@ -639,7 +607,7 @@ const WorkflowNodeDetailsPanel = ({
<div className="absolute left-0 top-0 size-full">
{activeTab === 'description' && (
<DescriptionTab
key={`${currentNode?.name}_description`}
key={`${currentNode?.workflowNodeName}_description`}
updateWorkflowMutation={updateWorkflowMutation}
/>
)}
Expand All @@ -652,29 +620,26 @@ const WorkflowNodeDetailsPanel = ({
currentComponentDefinition && (
<ConnectionTab
componentDefinition={currentComponentDefinition}
key={`${currentNode?.name}_connection`}
key={`${currentNode?.workflowNodeName}_connection`}
workflowConnections={componentConnections}
workflowId={workflow.id!}
workflowNodeName={currentNode?.name}
workflowNodeName={currentNode?.workflowNodeName}
workflowTestConfigurationConnections={workflowTestConfigurationConnections}
/>
)}

{activeTab === 'properties' &&
currentTaskData &&
!operationDataMissing &&
(currentOperationProperties?.length ? (
<Properties
customClassName="p-4"
key={`${currentNode?.name}_${currentOperationName}_properties`}
operationName={currentOperationName}
properties={currentOperationProperties}
/>
) : (
<div className="flex h-full items-center justify-center text-xl">
Loading...
</div>
))}
!operationDataMissing &&
currentOperationProperties?.length ? (
<Properties
customClassName="p-4"
key={`${currentNode?.workflowNodeName}_${currentOperationName}_properties`}
operationName={currentOperationName}
properties={currentOperationProperties}
/>
) : (
<div className="flex h-full items-center justify-center text-xl">Loading...</div>
)}

{activeTab === 'output' && currentNode && currentComponentDefinition && (
<OutputTab
Expand All @@ -683,7 +648,7 @@ const WorkflowNodeDetailsPanel = ({
!workflowTestConfigurationConnections?.length
}
currentNode={currentNode}
key={`${currentNode?.name}_output`}
key={`${currentNode?.workflowNodeName}_output`}
outputDefined={currentActionDefinition?.outputDefined ?? false}
workflowId={workflow.id!}
/>
Expand Down
Loading
Loading