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