Skip to content

Scheduling infrastructure for absolutely everyone.

fix: is Empty and is Not empty operators (#17317)

Hariom Balhara4c6f242345d2
diff --git a/packages/app-store/routing-forms/__tests__/zod.test.ts b/packages/app-store/routing-forms/__tests__/zod.test.ts
index 54f581d695f..da7ca17b9f8 100644
--- a/packages/app-store/routing-forms/__tests__/zod.test.ts
+++ b/packages/app-store/routing-forms/__tests__/zod.test.ts
@@ -15,6 +15,7 @@ describe("queryValueValidationSchema", () => {
field: "name",
operator: "equal",
value: ["John"],
+ valueSrc: ["value"],
},
},
},
@@ -48,6 +49,7 @@ describe("queryValueValidationSchema", () => {
field: "name",
operator: "equal",
value: [],
+ valueSrc: ["value"],
},
},
},
@@ -84,6 +86,7 @@ describe("queryValueValidationSchema", () => {
field: "name",
operator: "equal",
value: [],
+ valueSrc: ["value"],
},
},
},
@@ -110,6 +113,7 @@ describe("queryValueValidationSchema", () => {
field: "name",
operator: "equal",
value: [[]],
+ valueSrc: ["value"],
},
},
},
@@ -136,6 +140,7 @@ describe("queryValueValidationSchema", () => {
field: "name",
operator: "equal",
value: [undefined, undefined],
+ valueSrc: ["value"],
},
},
},
@@ -162,6 +167,7 @@ describe("queryValueValidationSchema", () => {
field: "name",
operator: "equal",
value: [null],
+ valueSrc: ["value"],
},
},
},
@@ -183,6 +189,7 @@ describe("queryValueValidationSchema", () => {
field: "name",
operator: "equal",
value: [""],
+ valueSrc: ["value"],
},
},
},
@@ -209,4 +216,42 @@ describe("queryValueValidationSchema", () => {
const result2 = queryValueSaveValidationSchema.safeParse(undefined);
expect(result2.success).toBe(true);
});
+
+ it("should allow fields with no value if valueSrc is empty", () => {
+ const result = queryValueSaveValidationSchema.safeParse({
+ id: "7",
+ type: "group",
+ children1: {
+ rule1: {
+ type: "rule",
+ properties: {
+ field: "name",
+ operator: "is_empty",
+ value: [],
+ valueSrc: [],
+ },
+ },
+ },
+ });
+ expect(result.success).toBe(true);
+ });
+
+ it("should not allow fields with no value if valueSrc is not empty", () => {
+ const result = queryValueSaveValidationSchema.safeParse({
+ id: "7",
+ type: "group",
+ children1: {
+ rule1: {
+ type: "rule",
+ properties: {
+ field: "name",
+ operator: "is_empty",
+ value: [],
+ valueSrc: ["value"],
+ },
+ },
+ },
+ });
+ expect(result.success).toBe(false);
+ });
});
diff --git a/packages/app-store/routing-forms/zod.ts b/packages/app-store/routing-forms/zod.ts
index 60f076b684c..95e2522026a 100644
--- a/packages/app-store/routing-forms/zod.ts
+++ b/packages/app-store/routing-forms/zod.ts
@@ -64,6 +64,7 @@ export enum RouteActionType {
export const routeActionTypeSchema = z.nativeEnum(RouteActionType);
/**
* Stricter schema for validating before saving to DB
+ * It doesn't decide what will be saved, it is just to validate the data before saving
*/
export const queryValueSaveValidationSchema = queryValueSchema
.omit({ children1: true })
@@ -78,6 +79,7 @@ export const queryValueSaveValidationSchema = queryValueSchema
field: z.any().optional(),
operator: z.any().optional(),
value: z.any().optional(),
+ valueSrc: z.any().optional(),
})
.optional(),
})
@@ -94,7 +96,13 @@ export const queryValueSaveValidationSchema = queryValueSchema
if (!isObject(rule.properties)) return;
const value = rule.properties.value || [];
- if (!(value instanceof Array)) {
+ const valueSrc = rule.properties.valueSrc;
+ if (!(value instanceof Array) || !(valueSrc instanceof Array)) {
+ return;
+ }
+
+ if (!valueSrc.length) {
+ // If valueSrc is empty, value could be empty for operators like is_empty, is_not_empty
return;
}