Skip to content

Commit 8161abe

Browse files
feat: Variable aggregation supports outputting dictionary types.
1 parent 15b1466 commit 8161abe

File tree

8 files changed

+51
-14
lines changed

8 files changed

+51
-14
lines changed

apps/application/flow/step_node/variable_aggregation_node/i_variable_aggregation_node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class VariableListSerializer(serializers.Serializer):
1313
v_id = serializers.CharField(required=True, label=_("Variable id"))
14+
key = serializers.CharField(required=False, label=_("Key"))
1415
variable = serializers.ListField(required=True, label=_("Variable"))
1516

1617

apps/application/flow/step_node/variable_aggregation_node/impl/base_variable_aggregation_node.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def save_context(self, details, workflow_manage):
3131
self.context['exception_message'] = details.get('err_message')
3232

3333
def get_first_non_null(self, variable_list):
34-
3534
for variable in variable_list:
3635
v = self.workflow_manage.get_reference_field(
3736
variable.get('variable')[0],
@@ -40,12 +39,16 @@ def get_first_non_null(self, variable_list):
4039
return v
4140
return None
4241

43-
def set_variable_to_json(self, variable_list):
44-
42+
def set_variable_to_array(self, variable_list):
4543
return [self.workflow_manage.get_reference_field(
4644
variable.get('variable')[0],
4745
variable.get('variable')[1:]) for variable in variable_list]
4846

47+
def set_variable_to_dict(self, variable_list):
48+
return {(variable.get('key') or variable.get('variable')[-1]): self.workflow_manage.get_reference_field(
49+
variable.get('variable')[0],
50+
variable.get('variable')[1:]) for variable in variable_list}
51+
4952
def reset_variable(self, variable):
5053
value = self.workflow_manage.get_reference_field(
5154
variable.get('variable')[0],
@@ -65,9 +68,14 @@ def reset_group_list(self, group_list):
6568

6669
def execute(self, strategy, group_list, **kwargs) -> NodeResult:
6770
strategy_map = {'first_non_null': self.get_first_non_null,
68-
'variable_to_json': self.set_variable_to_json,
71+
'variable_to_array': self.set_variable_to_array,
72+
'variable_to_dict': self.set_variable_to_dict,
6973
}
7074

75+
# 向下兼容
76+
if strategy == 'variable_to_json':
77+
strategy = 'variable_to_array'
78+
7179
result = {item.get('field'): strategy_map[strategy](item.get('variable_list')) for item in group_list}
7280

7381
return NodeResult(

ui/src/components/execution-detail-card/index.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,11 @@
936936
</h5>
937937
<div class="p-8-12 border-t-dashed lighter pre-wrap">
938938
{{
939-
data.strategy === 'variable_to_json'
940-
? t('workflow.nodes.variableAggregationNode.placeholder1')
941-
: t('workflow.nodes.variableAggregationNode.placeholder')
939+
data.strategy === 'first_non_null'
940+
? t('workflow.nodes.variableAggregationNode.placeholder')
941+
: data.strategy === 'variable_to_dict'
942+
? t('workflow.nodes.variableAggregationNode.placeholder2')
943+
: t('workflow.nodes.variableAggregationNode.placeholder1')
942944
}}
943945
</div>
944946
</div>

ui/src/locales/lang/en-US/workflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ You are a master of problem optimization, adept at accurately inferring user int
323323
text: 'Aggregate variables of each group according to the aggregation strategy',
324324
Strategy: 'Aggregation Strategy',
325325
placeholder: 'Return the first non-null value of each group',
326-
placeholder1: 'Return the set of variables for each group',
326+
placeholder1: 'Return the array of variables for each group',
327+
placeholder2: 'Return the dict of variables for each group',
328+
placeholder_key: 'Input key',
327329
group: {
328330
noneError: 'Name cannot be empty',
329331
dupError: 'Name cannot be duplicated',

ui/src/locales/lang/zh-CN/workflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ export default {
304304
text: '按聚合策略聚合每组的变量',
305305
Strategy: '聚合策略',
306306
placeholder: '返回每组的第一个非空值',
307-
placeholder1: '返回每组变量的集合',
307+
placeholder1: '返回每组变量的数组(Array)',
308+
placeholder2: '返回每组变量的字典(Dict)',
309+
placeholder_key: '输入键名',
308310
group: {
309311
noneError: '名称不能为空',
310312
dupError: '名称不能重复',

ui/src/locales/lang/zh-Hant/workflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ export default {
322322
text: '按聚合策略聚合每組的變量',
323323
Strategy: '聚合策略',
324324
placeholder: '返回每組的第一個非空值',
325-
placeholder1: '返回每組變量的集合',
325+
placeholder1: '返回每組變量的數組(Array)',
326+
placeholder2: '返回每組變量的字典(Dict)',
327+
placeholder_key: '輸入鍵名',
326328
group: {
327329
noneError: '名稱不能為空',
328330
dupError: '名稱不能重複',

ui/src/workflow/nodes/variable-aggregation-node/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ class VariableAggregationNode extends AppNode {
1010
}
1111
}
1212

13+
class VariableAggregationNodeModel extends AppNodeModel {
14+
get_width() {
15+
return 450
16+
}
17+
}
18+
1319
export default {
1420
type: 'variable-aggregation-node',
15-
model: AppNodeModel,
21+
model: VariableAggregationNodeModel,
1622
view: VariableAggregationNode,
1723
}

ui/src/workflow/nodes/variable-aggregation-node/index.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
/>
3535
<el-option
3636
:label="t('workflow.nodes.variableAggregationNode.placeholder1')"
37-
value="variable_to_json"
37+
value="variable_to_array"
38+
/>
39+
<el-option
40+
:label="t('workflow.nodes.variableAggregationNode.placeholder2')"
41+
value="variable_to_dict"
3842
/>
3943
</el-select>
4044
</el-form-item>
@@ -77,10 +81,17 @@
7781
trigger: 'change',
7882
}"
7983
>
84+
<el-input
85+
v-if="form_data.strategy === 'variable_to_dict'"
86+
v-model="item.key"
87+
:placeholder="$t('workflow.variable.placeholder_key')"
88+
style="width: 100px; margin-right: 8px"
89+
maxlength="256"
90+
/>
8091
<NodeCascader
8192
ref="nodeCascaderRef"
8293
:nodeModel="nodeModel"
83-
style="width: 200px"
94+
:style="{ width: form_data.strategy === 'variable_to_dict' ? '200px' : '310px'}"
8495
:placeholder="$t('workflow.variable.placeholder')"
8596
v-model="item.variable"
8697
/>
@@ -149,7 +160,10 @@ const form = {
149160
const form_data = computed({
150161
get: () => {
151162
if (props.nodeModel.properties.node_data) {
152-
return props.nodeModel.properties.node_data
163+
// 向下兼容
164+
if (props.nodeModel.properties.node_data.strategy === 'variable_to_json') {
165+
props.nodeModel.properties.node_data.strategy = 'variable_to_array'
166+
}
153167
} else {
154168
set(props.nodeModel.properties, 'node_data', form)
155169
}

0 commit comments

Comments
 (0)