import React from "react"; import { css, cx } from "@emotion/css"; import { Button, Select } from "antd"; import { CloseCircleOutlined } from '@ant-design/icons'; import { Trans, useTranslation } from "react-i18next"; import { NodeDefaultView } from "."; import { Branch, useFlowContext } from "../WorkflowCanvas"; import { branchBlockClass, nodeSubtreeClass } from "../style"; import { Calculation } from "../calculators"; import { i18n } from "../../i18n"; // import { SchemaComponent } from "../../schema-component"; function CalculationItem({ value, onChange, onRemove }) { if (!value) { return null; } const { calculator, operands = [] } = value; return (
{value.group ? ( onChange({ ...value, group })} /> ) : }
); } function CalculationGroup({ value, onChange }) { const { t } = useTranslation(); const { type = 'and', calculations = [] } = value; function onAddSingle() { onChange({ ...value, calculations: [...calculations, { not: false, calculator: 'equal' }] }); } function onAddGroup() { onChange({ ...value, calculations: [...calculations, { not: false, group: { type: 'and', calculations: [] } }] }); } function onRemove(i: number) { calculations.splice(i, 1); onChange({ ...value, calculations: [...calculations] }); } function onItemChange(i: number, v) { calculations.splice(i, 1, v); onChange({ ...value, calculations: [...calculations] }); } return (
{'Meet '} {' conditions in the group'}
{calculations.map((calculation, i) => ( onRemove(i)} /> ))}
); } function CalculationConfig({ value, onChange }) { const rule = value && Object.keys(value).length ? value : { group: { type: 'and', calculations: [] } }; return ( onChange({ ...rule, group })} /> ); } export default { title: '{{t("Condition")}}', type: 'condition', group: 'control', fieldset: { 'config.rejectOnFalse': { type: 'boolean', name: 'config.rejectOnFalse', title: '{{t("Mode")}}', 'x-decorator': 'FormItem', 'x-component': 'Radio.Group', 'x-component-props': { disabled: true, }, enum: [ { value: true, label: i18n.t('Continue when "Yes"') }, { value: false, label: i18n.t('Branch into "Yes" and "No"') } ], }, 'config.calculation': { type: 'string', name: 'config.calculation', title: '{{t("Conditions")}}', 'x-decorator': 'FormItem', 'x-component': 'CalculationConfig', } }, view: { }, options: [ { label: i18n.t('Continue when "Yes"'), key: 'rejectOnFalse', value: { rejectOnFalse: true } }, { label: i18n.t('Branch into "Yes" and "No"'), key: 'branch', value: { rejectOnFalse: false } } ], render(data) { const { id, config: { rejectOnFalse } } = data; const { nodes } = useFlowContext(); const trueEntry = nodes.find(item => item.upstreamId === id && item.branchIndex === 1); const falseEntry = nodes.find(item => item.upstreamId === id && item.branchIndex === 0); return ( {rejectOnFalse ? null : (
* > .workflow-branch-lines{ > button{ display: none; } } `)} >
span{ position: absolute; top: calc(1.5em - 1px); line-height: 1em; color: #999; background-color: #f0f2f5; padding: 1px; } `} > {i18n.t('No')} {i18n.t('Yes')}
)}
) }, components: { CalculationConfig } };