diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/filter/DateConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/filter/DateConditionRender.tsx index 8fe9863a..c55a35f5 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/filter/DateConditionRender.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/filter/DateConditionRender.tsx @@ -1,4 +1,3 @@ -import type { DateOperator } from "@ctrlplane/validators/conditions"; import type { DateValue } from "@internationalized/date"; import { ZonedDateTime } from "@internationalized/date"; import ms from "ms"; @@ -12,7 +11,7 @@ import { SelectTrigger, SelectValue, } from "@ctrlplane/ui/select"; -import { ReleaseOperator } from "@ctrlplane/validators/releases"; +import { DateOperator } from "@ctrlplane/validators/conditions"; const toZonedDateTime = (date: Date): ZonedDateTime => { const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; @@ -71,14 +70,12 @@ export const DateConditionRender: React.FC = ({ /> - before - after - + before + after + before or on - - after or on - + after or on diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/filter/MetadataConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/filter/MetadataConditionRender.tsx index b501dce8..b4a7b074 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/filter/MetadataConditionRender.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/filter/MetadataConditionRender.tsx @@ -1,4 +1,7 @@ -import type { MetadataCondition } from "@ctrlplane/validators/conditions"; +import type { + MetadataCondition, + MetadataOperatorType, +} from "@ctrlplane/validators/conditions"; import { useState } from "react"; import { cn } from "@ctrlplane/ui"; @@ -31,13 +34,7 @@ export const MetadataConditionRender: React.FC< condition.operator !== MetadataOperator.Null && onChange({ ...condition, value }); - const setOperator = ( - operator: - | MetadataOperator.Equals - | MetadataOperator.Like - | MetadataOperator.Regex - | MetadataOperator.Null, - ) => + const setOperator = (operator: MetadataOperatorType) => operator === MetadataOperator.Null ? onChange({ ...condition, operator, value: undefined }) : onChange({ ...condition, operator, value: condition.value ?? "" }); diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseConditionRender.tsx index 0c00b9d6..b273d357 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseConditionRender.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseConditionRender.tsx @@ -11,7 +11,7 @@ import { import type { ReleaseConditionRenderProps } from "./release-condition-props"; import { ComparisonConditionRender } from "./ComparisonConditionRender"; import { CreatedAtConditionRender } from "./CreatedAtConditionRender"; -import { ReleaseMetadataConditionRender } from "./MetadataConditionRender"; +import { ReleaseMetadataConditionRender } from "./ReleaseMetadataConditionRender"; import { VersionConditionRender } from "./VersionConditionRender"; /** diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/release-condition/MetadataConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseMetadataConditionRender.tsx similarity index 100% rename from apps/webservice/src/app/[workspaceSlug]/_components/release-condition/MetadataConditionRender.tsx rename to apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseMetadataConditionRender.tsx diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx index 0d8fd0d4..61c6017e 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx @@ -12,9 +12,9 @@ import { import type { TargetConditionRenderProps } from "./target-condition-props"; import { ComparisonConditionRender } from "./ComparisonConditionRender"; import { KindConditionRender } from "./KindConditionRender"; -import { TargetMetadataConditionRender } from "./MetadataConditionRender"; import { NameConditionRender } from "./NameConditionRender"; import { ProviderConditionRender } from "./ProviderConditionRender"; +import { TargetMetadataConditionRender } from "./TargetMetadataConditionRender"; /** * The parent container should have min width of 1000px diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/MetadataConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetMetadataConditionRender.tsx similarity index 100% rename from apps/webservice/src/app/[workspaceSlug]/_components/target-condition/MetadataConditionRender.tsx rename to apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetMetadataConditionRender.tsx diff --git a/packages/validators/src/conditions/date-condition.ts b/packages/validators/src/conditions/date-condition.ts index dd828196..1c0e09c4 100644 --- a/packages/validators/src/conditions/date-condition.ts +++ b/packages/validators/src/conditions/date-condition.ts @@ -7,9 +7,8 @@ const operator = z.union([ z.literal("after-or-on"), ]); -const value = z.string().refine((v) => !isNaN(new Date(v).getTime()), { - message: "Invalid date", -}); +const isValidDate = (v: string) => !Number.isNaN(new Date(v).getTime()); +const value = z.string().refine(isValidDate, { message: "Invalid date" }); const createdAt = z.literal("created-at"); const updatedAt = z.literal("updated-at"); diff --git a/packages/validators/src/conditions/metadata-condition.ts b/packages/validators/src/conditions/metadata-condition.ts index 15d08b56..91d899ca 100644 --- a/packages/validators/src/conditions/metadata-condition.ts +++ b/packages/validators/src/conditions/metadata-condition.ts @@ -52,6 +52,12 @@ export enum MetadataOperator { Null = "null", } +export type MetadataOperatorType = + | MetadataOperator.Equals + | MetadataOperator.Like + | MetadataOperator.Regex + | MetadataOperator.Null; + export enum ReservedMetadataKey { ExternalId = "ctrlplane/external-id", Links = "ctrlplane/links", diff --git a/packages/validators/src/releases/conditions/comparison-condition.ts b/packages/validators/src/releases/conditions/comparison-condition.ts index 9ada5145..8b2abdff 100644 --- a/packages/validators/src/releases/conditions/comparison-condition.ts +++ b/packages/validators/src/releases/conditions/comparison-condition.ts @@ -1,7 +1,7 @@ import { z } from "zod"; import type { CreatedAtCondition } from "../../conditions/date-condition.js"; -import type { MetadataCondition } from "../../conditions/metadata-condition.js"; +import type { MetadataCondition } from "../../conditions/index.js"; import type { VersionCondition } from "./version-condition.js"; import { createdAtCondition } from "../../conditions/date-condition.js"; import { metadataCondition } from "../../conditions/index.js";