Skip to content

Commit

Permalink
fix: Allow empty string for metadata condition value (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 authored Dec 3, 2024
1 parent add1441 commit 0683c14
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export const CombinationsTable: React.FC<{
([key, value]) => ({
type: "metadata",
key,
value,
operator: "equals",
...(value != null
? { value, operator: "equals" }
: { operator: "null" }),
}),
),
}),
Expand Down
6 changes: 3 additions & 3 deletions packages/validators/src/conditions/metadata-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type NullCondition = z.infer<typeof nullCondition>;
export const equalsCondition = z.object({
type: z.literal("metadata"),
key: z.string().min(1),
value: z.string().min(1),
value: z.string(),
operator: z.literal("equals").optional(),
});

Expand All @@ -21,7 +21,7 @@ export type EqualCondition = z.infer<typeof equalsCondition>;
export const regexCondition = z.object({
type: z.literal("metadata"),
key: z.string().min(1),
value: z.string().min(1),
value: z.string(),
operator: z.literal("regex"),
});

Expand All @@ -30,7 +30,7 @@ export type RegexCondition = z.infer<typeof regexCondition>;
export const likeCondition = z.object({
type: z.literal("metadata"),
key: z.string().min(1),
value: z.string().min(1),
value: z.string(),
operator: z.literal("like"),
});

Expand Down
2 changes: 1 addition & 1 deletion packages/validators/src/jobs/conditions/job-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const isValidJobCondition = (condition: JobCondition): boolean => {
if (isMetadataCondition(condition)) {
if (condition.operator === MetadataOperator.Null)
return condition.value == null && condition.key.length > 0;
return condition.value.length > 0 && condition.key.length > 0;
return condition.key.length > 0;
}
return condition.value.length > 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const isValidReleaseCondition = (
if (isMetadataCondition(condition)) {
if (condition.operator === ReleaseOperator.Null)
return condition.value == null && condition.key.length > 0;
return condition.value.length > 0 && condition.key.length > 0;
return condition.key.length > 0;
}
return false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const isValidTargetCondition = (
if (isMetadataCondition(condition)) {
if (condition.operator === ResourceOperator.Null)
return condition.value == null && condition.key.length > 0;
return condition.value.length > 0 && condition.key.length > 0;
return condition.key.length > 0;
}
return condition.value.length > 0;
};

0 comments on commit 0683c14

Please sign in to comment.