Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Add isEmpty hook to each field to customizer the isEmpty check

天舟c0d82c25020e
diff --git a/frontend/src/plugins/task/DatabaseRequestTemplate.ts b/frontend/src/plugins/task/DatabaseRequestTemplate.ts
index 04d158e498..1431b183fe 100644
--- a/frontend/src/plugins/task/DatabaseRequestTemplate.ts
+++ b/frontend/src/plugins/task/DatabaseRequestTemplate.ts
@@ -1,3 +1,4 @@
+import isEmpty from "lodash-es/isEmpty";
import {
TaskTemplate,
TemplateContext,
@@ -56,12 +57,18 @@ const template: TaskTemplate = {
name: "DB name",
type: "NewDatabase",
required: true,
- preprocessor: (payload: DatabaseFieldPayload): DatabaseFieldPayload => {
+ isEmpty: (value: DatabaseFieldPayload): boolean => {
+ if (value.isNew) {
+ return isEmpty(value.name);
+ }
+ return isEmpty(value.id);
+ },
+ preprocessor: (value: DatabaseFieldPayload): DatabaseFieldPayload => {
// In case caller passes corrupted data.
// Handled here instead of the caller, because it's
// preprocessor specific behavior to handle fallback.
- payload.name = payload.name?.toLowerCase();
- return payload;
+ value.name = value.name?.toLowerCase();
+ return value;
},
placeholder: "New database name",
},
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
index 397082e1a9..ddc6da9699 100644
--- a/frontend/src/plugins/types.ts
+++ b/frontend/src/plugins/types.ts
@@ -41,8 +41,12 @@ export type TaskField = {
type: TaskFieldType;
// Whether the field is required.
required: boolean;
+ // Whether the value is empty, one use case is together with "required" field to validate
+ // whether it's ready to submit the data.
+ // If not present, we will use the loadash/isEmpty check.
+ isEmpty?: (value: any) => boolean;
// Preprocessor such as enforcing lowercase.
- preprocessor?: (item: any) => any;
+ preprocessor?: (value: any) => any;
// Placeholder displayed on UI.
placeholder?: string;
};
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 4623f6eef5..5ac75edb8d 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -501,7 +501,8 @@ export default {
if (
field.type != "Switch" && // Switch is boolean value which always presents
field.required &&
- isEmpty(state.task.payload[field.id])
+ ((field.isEmpty && field.isEmpty(state.task.payload[field.id])) ||
+ isEmpty(state.task.payload[field.id]))
) {
return false;
}