From 25dd8af145b53666858935cb6f75492890ab20fe Mon Sep 17 00:00:00 2001 From: pjdotson Date: Sat, 2 Nov 2024 17:36:38 -0700 Subject: [PATCH] clean up duplicated code --- console/src/hardware/device/Configure.tsx | 5 ++++- console/src/hardware/labjack/device/types.ts | 13 ++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/console/src/hardware/device/Configure.tsx b/console/src/hardware/device/Configure.tsx index f70339cbfd..a49e02a07a 100644 --- a/console/src/hardware/device/Configure.tsx +++ b/console/src/hardware/device/Configure.tsx @@ -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, diff --git a/console/src/hardware/labjack/device/types.ts b/console/src/hardware/labjack/device/types.ts index 6b796accfe..6bf9c10858 100644 --- a/console/src/hardware/labjack/device/types.ts +++ b/console/src/hardware/labjack/device/types.ts @@ -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; -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; - const commandStatePairZ = z.object({ command: z.number(), state: z.number() }); export const propertiesZ = z.object({ @@ -122,7 +115,6 @@ export const portsZ = z.object({ AI: aiPortZ.array(), DI: diPortZ.array(), }); - export type Ports = z.infer; // T4 @@ -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 {} export const T4: ModelInfo = { key: "LJM_dtT4", name: "T4", ports: T4_PORTS };