-
Notifications
You must be signed in to change notification settings - Fork 2.6k
refactor: Support string,json,num types #2388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,29 +60,85 @@ | |
| </el-select> | ||
| </div> | ||
| </template> | ||
| <div v-if="item.source === 'custom'" class="flex"> | ||
| <el-select v-model="item.type" style="width: 130px;"> | ||
| <el-option v-for="item in typeOptions" :key="item" :label="item" :value="item" /> | ||
| </el-select> | ||
| <el-input | ||
| class="ml-4" | ||
| v-model="item.value" | ||
| :placeholder="$t('common.inputPlaceholder')" | ||
| show-word-limit | ||
| clearable | ||
| @wheel="wheel" | ||
| ></el-input> | ||
| </div> | ||
|
|
||
| </el-form-item> | ||
| <div v-if="item.source === 'custom'" class="flex"> | ||
| <el-row :gutter="8"> | ||
| <el-col :span="8"> | ||
| <el-select v-model="item.type" style="width: 130px;"> | ||
| <el-option v-for="item in typeOptions" :key="item" :label="item" | ||
| :value="item" /> | ||
| </el-select> | ||
| </el-col> | ||
| <el-col :span="16"> | ||
| <el-form-item v-if="item.type === 'string'" | ||
| :prop="'variable_list.' + index + '.value'" | ||
| :rules="{ | ||
| message: t('dynamicsForm.tip.requiredMessage'), | ||
| trigger: 'blur', | ||
| required: true | ||
| }" | ||
| > | ||
| <el-input | ||
| class="ml-4" | ||
| v-model="item.value" | ||
| :placeholder="$t('common.inputPlaceholder')" | ||
| show-word-limit | ||
| clearable | ||
| @wheel="wheel" | ||
| ></el-input> | ||
| </el-form-item> | ||
| <el-form-item v-else-if="item.type ==='num'" | ||
| :prop="'variable_list.' + index + '.value'" | ||
| :rules="{ | ||
| message: t('dynamicsForm.tip.requiredMessage'), | ||
| trigger: 'blur', | ||
| required: true | ||
| }" | ||
| > | ||
| <el-input-number | ||
| class="ml-4" | ||
| v-model="item.value" | ||
| ></el-input-number> | ||
| </el-form-item> | ||
| <el-form-item v-else-if="item.type === 'json'" | ||
| :prop="'variable_list.' + index + '.value'" | ||
| :rules="[{ | ||
| message: t('dynamicsForm.tip.requiredMessage'), | ||
| trigger: 'blur', | ||
| required: true | ||
| }, | ||
| { | ||
| validator: (rule:any, value:any, callback:any) => { | ||
| try { | ||
| JSON.parse(value); | ||
| callback(); // Valid JSON | ||
| } catch (e) { | ||
| callback(new Error('Invalid JSON format')); | ||
| } | ||
| }, | ||
| trigger: 'blur', | ||
| }]" | ||
| > | ||
| <el-input | ||
| class="ml-4" | ||
| v-model="item.value" | ||
| :placeholder="$t('common.inputPlaceholder')" | ||
| type="textarea" | ||
| ></el-input> | ||
| </el-form-item> | ||
| </el-col> | ||
| </el-row> | ||
| </div> | ||
| <el-form-item v-else> | ||
| <NodeCascader | ||
| v-else | ||
| ref="nodeCascaderRef2" | ||
| :nodeModel="nodeModel" | ||
| class="w-full" | ||
| :placeholder="$t('views.applicationWorkflow.variable.placeholder')" | ||
| v-model="item.reference" | ||
| /> | ||
| </el-form-item> | ||
|
|
||
| </el-card> | ||
| </template> | ||
| <el-button link type="primary" @click="addVariable"> | ||
|
|
@@ -101,10 +157,11 @@ import NodeCascader from '@/workflow/common/NodeCascader.vue' | |
| import { computed, onMounted, ref } from 'vue' | ||
| import { isLastNode } from '@/workflow/common/data' | ||
| import { randomId } from '@/utils/utils' | ||
| import { t } from '@/locales' | ||
|
|
||
| const props = defineProps<{ nodeModel: any }>() | ||
|
|
||
| const typeOptions = ['string', 'int', 'dict', 'array', 'float'] | ||
| const typeOptions = ['string', 'num', 'json'] | ||
|
|
||
| const wheel = (e: any) => { | ||
| if (e.ctrlKey === true) { | ||
|
|
@@ -149,8 +206,14 @@ function submitDialog(val: string) { | |
|
|
||
| const replyNodeFormRef = ref() | ||
| const nodeCascaderRef = ref() | ||
| const nodeCascaderRef2 = ref() | ||
| const validate = async () => { | ||
| return Promise.all([replyNodeFormRef.value?.validate()]).catch((err: any) => { | ||
| // console.log(replyNodeFormRef.value.validate()) | ||
| return Promise.all([ | ||
| replyNodeFormRef.value?.validate(), | ||
| ...nodeCascaderRef.value.map((item: any) => item.validate()), | ||
| ...nodeCascaderRef2.value.map((item: any) => item.validate()) | ||
| ]).catch((err: any) => { | ||
| return Promise.reject({ node: props.nodeModel, errMessage: err }) | ||
| }) | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code contains several improvements and optimizations: Regularities Found
Potential Issues
Optimization Suggestions
Here's a revised version of the code incorporating these suggestions: // Sort imports alphabetically
import t from "@/locales";
import NodeCascader from "@/workflow/common/NodeCascader.vue";
import { computed, onMounted, ref } from "vue";
const props = defineProps<{
nodeModel: any;
}>();
const typeOptions = ["string", "int", "dict", "array", "float"];
const wheel = (e: any) => {
if (e.ctrlKey === true) {
// Handle Ctrl+Wheel event here
}
};
function submitDialog(val: String): void {}
const replyNodeFormRef = ref();
const nodeCascaderRef = ref();
const nodeCascaderRef2 = ref();
async function validate(): Promise<any> {
const validations = [
replyNodeFormRef.value && replyNodeFormRef.value.validate(),
...nodeCascaderRef.value.map((item: any) => item.validate()),
...nodeCascaderRef2.value.map((item: any) => item.validate())
];
return Promise.all(validations).then(() => null)
.catch((err: any) => console.error("Form validation errors:", err));
}
onMounted(() => {
// On mounted lifecycle hook
});
export default {
components: {
NodeCascader,
},
setup(props) {
// Your existing code logic goes here
},
};By making these changes, the code becomes more maintainable, consistent, and potentially faster due to reduced overhead from accessing Vue components using |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code has a logical flaw related to how
variables['type']is checked, potentially leading to incorrect data handling depending on the type of structure present invariable['value']. Here's an optimized version with corrections:Key Changes:
variable['value'].try-exceptblock to catch invalid JSON errors.These changes ensure that only valid dictionaries or arrays can be parsed into Python objects, mitigating runtime exceptions.