Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Oct 25, 2024
1 parent b58f7a5 commit 1404e0e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -71,14 +70,12 @@ export const DateConditionRender: React.FC<DateConditionRenderProps> = ({
/>
</SelectTrigger>
<SelectContent className="text-muted-foreground">
<SelectItem value={ReleaseOperator.Before}>before</SelectItem>
<SelectItem value={ReleaseOperator.After}>after</SelectItem>
<SelectItem value={ReleaseOperator.BeforeOrOn}>
<SelectItem value={DateOperator.Before}>before</SelectItem>
<SelectItem value={DateOperator.After}>after</SelectItem>
<SelectItem value={DateOperator.BeforeOrOn}>
before or on
</SelectItem>
<SelectItem value={ReleaseOperator.AfterOrOn}>
after or on
</SelectItem>
<SelectItem value={DateOperator.AfterOrOn}>after or on</SelectItem>
</SelectContent>
</Select>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 ?? "" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions packages/validators/src/conditions/date-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions packages/validators/src/conditions/metadata-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 1404e0e

Please sign in to comment.