fix(plugin-workflow): fix trigger context getters (#1149)
This commit is contained in:
parent
1ebb70e4c5
commit
4a113774bd
@ -11,7 +11,7 @@ export const FilterItems = observer((props) => {
|
||||
<div>
|
||||
{field?.value?.map((item, index) => {
|
||||
return (
|
||||
<RemoveConditionContext.Provider value={() => field.remove(index)}>
|
||||
<RemoveConditionContext.Provider key={index} value={() => field.remove(index)}>
|
||||
<ObjectField name={index} component={[item.$and || item.$or ? FilterGroup : FilterItem]} />
|
||||
</RemoveConditionContext.Provider>
|
||||
);
|
||||
|
@ -297,18 +297,32 @@ export const VariableTypes = {
|
||||
}
|
||||
},
|
||||
$context: {
|
||||
title: `{{t("Trigger context", { ns: "${NAMESPACE}" })}}`,
|
||||
title: `{{t("Trigger variables", { ns: "${NAMESPACE}" })}}`,
|
||||
value: '$context',
|
||||
options() {
|
||||
const { workflow } = useFlowContext();
|
||||
const trigger = triggers.get(workflow.type);
|
||||
return trigger?.getOptions?.(workflow.config) ?? null;
|
||||
},
|
||||
component() {
|
||||
const { workflow } = useFlowContext();
|
||||
const trigger = triggers.get(workflow.type);
|
||||
return trigger?.getter ?? NullRender;
|
||||
},
|
||||
parse([prefix, ...path]) {
|
||||
return { path: path.join('.') };
|
||||
appendTypeValue({ options }) {
|
||||
return options.type ? [options.type] : [];
|
||||
},
|
||||
onTypeChange(old, [type, optionType], onChange) {
|
||||
onChange({ type, options: { type: optionType } });
|
||||
},
|
||||
parse([type, ...path]) {
|
||||
return { type, ...( path?.length ? { path: path.join('.') } : {}) };
|
||||
},
|
||||
stringify({ options }) {
|
||||
const stack = ['$context'];
|
||||
if (options?.type) {
|
||||
stack.push(options.type);
|
||||
}
|
||||
if (options?.path) {
|
||||
stack.push(options.path);
|
||||
}
|
||||
@ -345,7 +359,7 @@ export function Operand({
|
||||
const { type } = operand;
|
||||
|
||||
const { component, appendTypeValue } = Types[type] || {};
|
||||
const VariableComponent = typeof component === 'function' ? component(operand) : NullRender;
|
||||
const Variable = typeof component === 'function' ? component(operand) : NullRender;
|
||||
|
||||
return (
|
||||
<div className={css`
|
||||
@ -377,7 +391,7 @@ export function Operand({
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{children ?? <VariableComponent {...operand} onChange={op => onChange({ ...op })} />}
|
||||
{children ?? <Variable {...operand} onChange={op => onChange({ ...op })} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ export default {
|
||||
"Advanced": "Advanced",
|
||||
"Advanced type": "Advanced",
|
||||
"End": "End",
|
||||
"Trigger context": "Trigger context",
|
||||
"Trigger variables": "Trigger variables",
|
||||
"Node result": "Node result",
|
||||
"Constant": "Constant",
|
||||
"Boolean": "Boolean",
|
||||
|
@ -46,7 +46,7 @@ export default {
|
||||
"Advanced": "アドバンスド",
|
||||
"Advanced type": "アドバンスタイプ",
|
||||
"End": "終了",
|
||||
"Trigger context": "トリガーフィールド",
|
||||
"Trigger variables": "トリガーフィールド",
|
||||
"Node result": "ノードの結果",
|
||||
"Constant": "定数",
|
||||
"Boolean": "論理値",
|
||||
|
@ -46,7 +46,7 @@ export default {
|
||||
"Advanced": "Продвинутый",
|
||||
"Advanced type": "Продвинутый",
|
||||
"End": "Окончание",
|
||||
"Trigger context": "Контекст триггера",
|
||||
"Trigger variables": "Контекст триггера",
|
||||
"Node result": "Результат Узла",
|
||||
"Constant": "Константа",
|
||||
"Boolean": "Логический",
|
||||
|
@ -46,7 +46,7 @@ export default {
|
||||
"Advanced": "Gelişmiş",
|
||||
"Advanced type": "Gelişmiş",
|
||||
"End": "Son",
|
||||
"Trigger context": "Tetikleyici bağlamı",
|
||||
"Trigger variables": "Tetikleyici bağlamı",
|
||||
"Node result": "Düğüm sonucu",
|
||||
"Constant": "Devamlı",
|
||||
"Boolean": "Boolean",
|
||||
|
@ -12,7 +12,7 @@ export default {
|
||||
'Load failed': '加载失败',
|
||||
|
||||
'Trigger': '触发器',
|
||||
'Trigger context': '触发数据',
|
||||
'Trigger variables': '触发器变量',
|
||||
'Trigger data': '触发数据',
|
||||
'Trigger time': '触发时间',
|
||||
'Triggered at': '触发时间',
|
||||
|
@ -9,7 +9,7 @@ import { collection, filter } from '../schemas/collection';
|
||||
import { css } from '@emotion/css';
|
||||
import { onFieldValueChange } from '@formily/core';
|
||||
import CollectionFieldSelect from '../components/CollectionFieldSelect';
|
||||
import { NAMESPACE } from '../locale';
|
||||
import { NAMESPACE, useWorkflowTranslation } from '../locale';
|
||||
|
||||
const FieldsSelect = observer((props) => {
|
||||
const compile = useCompile();
|
||||
@ -139,17 +139,23 @@ export default {
|
||||
components: {
|
||||
FieldsSelect
|
||||
},
|
||||
getOptions(config) {
|
||||
const { t } = useWorkflowTranslation();
|
||||
const options: any[] = [
|
||||
{ value: 'data', label: t('Trigger data') },
|
||||
];
|
||||
return options;
|
||||
},
|
||||
getter(props) {
|
||||
const { type, options, onChange } = props;
|
||||
const { workflow } = useFlowContext();
|
||||
const value = options?.path?.replace(/^data\./, '');
|
||||
|
||||
return (
|
||||
<CollectionFieldSelect
|
||||
collection={workflow.config.collection}
|
||||
value={value}
|
||||
onChange={(value) => {
|
||||
onChange({ type, options: { ...options, path: `data.${value}` } });
|
||||
value={options?.path}
|
||||
onChange={(path) => {
|
||||
onChange({ type, options: { ...options, path } });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
@ -43,7 +43,7 @@ export interface Trigger {
|
||||
title: string;
|
||||
type: string;
|
||||
// group: string;
|
||||
options?: { label: string; value: any; key: string }[];
|
||||
getOptions?(config: any): { label: string; value: any; key: string }[];
|
||||
fieldset: { [key: string]: ISchema };
|
||||
view?: ISchema;
|
||||
scope?: { [key: string]: any };
|
||||
@ -108,7 +108,7 @@ function TriggerExecution() {
|
||||
},
|
||||
context: {
|
||||
type: 'object',
|
||||
title: `{{t("Trigger context", { ns: "${NAMESPACE}" })}}`,
|
||||
title: `{{t("Trigger variables", { ns: "${NAMESPACE}" })}}`,
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Input.JSON',
|
||||
'x-component-props': {
|
||||
|
@ -27,33 +27,39 @@ export default {
|
||||
components: {
|
||||
ScheduleConfig
|
||||
},
|
||||
getOptions(config) {
|
||||
const { t } = useWorkflowTranslation();
|
||||
const options: any[] = [
|
||||
{ value: 'date', label: t('Trigger time') },
|
||||
];
|
||||
if (config.mode === SCHEDULE_MODE.COLLECTION_FIELD) {
|
||||
options.push({
|
||||
value: 'data',
|
||||
label: t('Trigger data')
|
||||
});
|
||||
}
|
||||
return options;
|
||||
},
|
||||
getter({ type, options, onChange }) {
|
||||
const { t } = useWorkflowTranslation();
|
||||
const compile = useCompile();
|
||||
const { workflow } = useFlowContext();
|
||||
const { collections = [] } = useCollectionManager();
|
||||
const { workflow } = useFlowContext();
|
||||
const path = options?.path ? options.path.split('.') : [];
|
||||
const varOptions: any[] = [
|
||||
{ value: 'date', label: t('Trigger time') },
|
||||
];
|
||||
if (workflow.config.mode === SCHEDULE_MODE.COLLECTION_FIELD) {
|
||||
const collection = collections.find(item => item.name === workflow.config.collection) ?? { fields: [] };
|
||||
varOptions.push({
|
||||
value: 'data',
|
||||
label: t('Trigger data'),
|
||||
children: collection.fields
|
||||
if (!options.type || options.type === 'date') {
|
||||
return null;
|
||||
}
|
||||
const collection = collections.find(item => item.name === workflow.config.collection) ?? { fields: [] };
|
||||
return (
|
||||
<Cascader
|
||||
placeholder={t('Trigger data')}
|
||||
value={path}
|
||||
options={collection.fields
|
||||
.filter(field => BaseTypeSet.has(field?.uiSchema?.type))
|
||||
.map(field => ({
|
||||
value: field.name,
|
||||
label: compile(field.uiSchema?.title),
|
||||
}))
|
||||
});
|
||||
}
|
||||
return (
|
||||
<Cascader
|
||||
placeholder={t('Trigger context')}
|
||||
value={path}
|
||||
options={varOptions}
|
||||
}))}
|
||||
onChange={(next) => {
|
||||
onChange({ type, options: { ...options, path: next.join('.') } });
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user