Skip to content

Commit

Permalink
clean up duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdotson committed Nov 3, 2024
1 parent 9ff6f36 commit 25dd8af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
5 changes: 4 additions & 1 deletion console/src/hardware/device/Configure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import { CSS } from "@/css";
import { type Layout } from "@/layout";

const IDENTIFIER_MESSAGE = "Identifier must be between 2-12 characters";
const identifierZ = z.string().min(2, IDENTIFIER_MESSAGE).max(12, IDENTIFIER_MESSAGE);
export const identifierZ = z
.string()
.min(2, IDENTIFIER_MESSAGE)
.max(12, IDENTIFIER_MESSAGE);
const configurablePropertiesZ = z.object({
name: z.string().min(1, "Name must be at least 1 character long"),
identifier: identifierZ,
Expand Down
13 changes: 2 additions & 11 deletions console/src/hardware/labjack/device/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@
import { bounds } from "@synnaxlabs/x";
import { z } from "zod";

import { identifierZ } from "@/hardware/device/Configure";

export const MODEL_KEYS = ["LJM_dtT4", "LJM_dtT7", "LJM_dtT8"] as const;
export const modelKeyZ = z.enum(MODEL_KEYS);
export type ModelKey = z.infer<typeof modelKeyZ>;

const IDENTIFIER_MESSAGE = "Identifier must be between 2-12 characters";
const identifierZ = z.string().min(2, IDENTIFIER_MESSAGE).max(12, IDENTIFIER_MESSAGE);

export const configurablePropertiesZ = z.object({
name: z.string().min(1, "Name must be at least 1 character long"),
identifier: identifierZ,
});
export type ConfigurableProperties = z.infer<typeof configurablePropertiesZ>;

const commandStatePairZ = z.object({ command: z.number(), state: z.number() });

export const propertiesZ = z.object({
Expand Down Expand Up @@ -122,7 +115,6 @@ export const portsZ = z.object({
AI: aiPortZ.array(),
DI: diPortZ.array(),
});

export type Ports = z.infer<typeof portsZ>;

// T4
Expand Down Expand Up @@ -174,7 +166,6 @@ export const T8_PORTS: Ports = {
};

export const modelInfoZ = z.object({ key: modelKeyZ, name: z.string(), ports: portsZ });

export interface ModelInfo extends z.infer<typeof modelInfoZ> {}

export const T4: ModelInfo = { key: "LJM_dtT4", name: "T4", ports: T4_PORTS };
Expand Down

0 comments on commit 25dd8af

Please sign in to comment.