From 46e0015ad813004b450610af45ece0a6bfb4e90d Mon Sep 17 00:00:00 2001
From: Paul2803k
Date: Mon, 30 Nov 2026 23:33:13 +0100
Subject: [PATCH 1/3] Centralize reduced-motion and base CSS resets in
GlobalStyles
---
src/components/CodeBlock.tsx | 1 -
src/components/Link.tsx | 1 -
src/components/Sidebar.tsx | 1 -
src/pages/LoginPage.tsx | 7 -------
.../PlaybookDetailPage.styles.tsx | 10 ----------
.../visual-editor/pages/VisualEditor.styles.tsx | 10 ----------
.../visual-editor/panels/Panel.styles.tsx | 5 -----
src/theme/GlobalStyles.ts | 15 +++++++++++++++
8 files changed, 15 insertions(+), 35 deletions(-)
diff --git a/src/components/CodeBlock.tsx b/src/components/CodeBlock.tsx
index c1dd3855..d1eafcc6 100644
--- a/src/components/CodeBlock.tsx
+++ b/src/components/CodeBlock.tsx
@@ -22,7 +22,6 @@ const Frame = styled(ScrollArea)<{ $maxHeight?: string }>`
const Pre = styled.pre<{ $copyable?: boolean }>`
counter-reset: line;
- margin: 0;
padding: ${({ theme }) => theme.spacing.sm} 0;
padding-right: ${({ $copyable }) => ($copyable ? "2.5rem" : 0)};
diff --git a/src/components/Link.tsx b/src/components/Link.tsx
index c3f792ec..572125b7 100644
--- a/src/components/Link.tsx
+++ b/src/components/Link.tsx
@@ -8,7 +8,6 @@ const StyledLink = styled.a<{ $subtle?: boolean }>`
align-items: center;
font: ${({ theme }) => theme.typography.body.font};
- text-decoration: none;
${({ $subtle, theme }) =>
$subtle
? `
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 18be1cca..9d04eeb2 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -143,7 +143,6 @@ export const NavItem = styled.a<{ $isActive?: boolean }>`
font: ${({ theme }) => theme.typography.bodyMedium.font};
color: ${({ theme }) => theme.colors.text.secondary};
- text-decoration: none;
transition:
color ${({ theme }) => theme.transitions.base},
diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx
index bf29d333..2a4b381a 100644
--- a/src/pages/LoginPage.tsx
+++ b/src/pages/LoginPage.tsx
@@ -267,13 +267,6 @@ const ProviderButton = styled(Button)`
pointer-events: none;
opacity: ${({ theme }) => theme.interactions.disabledOpacity};
}
-
- @media (prefers-reduced-motion: reduce) {
- .provider-arrow {
- transform: none;
- transition: none;
- }
- }
`;
const ProviderIdentity = styled.span`
diff --git a/src/pages/main-page/playbooks-page/playbook-detail-page/PlaybookDetailPage.styles.tsx b/src/pages/main-page/playbooks-page/playbook-detail-page/PlaybookDetailPage.styles.tsx
index 48c47a63..5d67d2c2 100644
--- a/src/pages/main-page/playbooks-page/playbook-detail-page/PlaybookDetailPage.styles.tsx
+++ b/src/pages/main-page/playbooks-page/playbook-detail-page/PlaybookDetailPage.styles.tsx
@@ -36,8 +36,6 @@ export const TitleRow = styled.div`
export const PageTitle = styled.h2`
overflow: hidden;
- margin: 0;
-
font: ${({ theme }) => theme.typography.h2.font};
color: ${({ theme }) => theme.colors.text.primary};
text-overflow: ellipsis;
@@ -64,10 +62,6 @@ export const DetailBody = styled.div<{
min-height: 0;
transition: grid-template-columns ${({ theme }) => theme.transitions.base};
-
- @media (prefers-reduced-motion: reduce) {
- transition: none;
- }
`;
export const DiagramFrame = styled.div`
@@ -92,7 +86,6 @@ export const FieldGrid = styled.dl`
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: ${({ theme }) => theme.spacing.lg};
- margin: 0;
`;
export const Field = styled.div<{ $wide?: boolean }>`
@@ -110,7 +103,6 @@ export const FieldLabel = styled.dt`
`;
export const FieldValue = styled.dd`
- margin: 0;
font: ${({ theme }) => theme.typography.body.font};
color: ${({ theme }) => theme.colors.text.primary};
`;
@@ -149,14 +141,12 @@ export const ReferenceItem = styled.div`
`;
export const Description = styled.p`
- margin: 0;
font: ${({ theme }) => theme.typography.body.font};
color: ${({ theme }) => theme.colors.text.primary};
white-space: pre-line;
`;
export const EmptyText = styled.p`
- margin: 0;
font: ${({ theme }) => theme.typography.caption.font};
color: ${({ theme }) => theme.colors.text.secondary};
`;
diff --git a/src/pages/main-page/playbooks-page/visual-editor/pages/VisualEditor.styles.tsx b/src/pages/main-page/playbooks-page/visual-editor/pages/VisualEditor.styles.tsx
index d84f6fa3..c9fba4c3 100644
--- a/src/pages/main-page/playbooks-page/visual-editor/pages/VisualEditor.styles.tsx
+++ b/src/pages/main-page/playbooks-page/visual-editor/pages/VisualEditor.styles.tsx
@@ -9,10 +9,6 @@ const PANEL_BORDERS_WIDTH = "2px";
const fadeWhenCollapsed = css<{ $collapsed: boolean }>`
opacity: ${({ $collapsed }) => ($collapsed ? 0 : 1)};
transition: opacity ${({ theme }) => theme.transitions.base};
-
- @media (prefers-reduced-motion: reduce) {
- transition: none;
- }
`;
export const EditorScroll = styled(ScrollArea)`
@@ -37,10 +33,6 @@ export const EditorLayout = styled.div<{
padding: ${({ theme }) => theme.spacing.lg};
transition: grid-template-columns ${({ theme }) => theme.transitions.base};
-
- @media (prefers-reduced-motion: reduce) {
- transition: none;
- }
`;
export const EditorFallback = styled.div`
@@ -56,7 +48,6 @@ export const Toolbar = styled.div`
export const ToolbarTitle = styled.h2`
flex: 1;
- margin: 0;
font: ${({ theme }) => theme.typography.h2.font};
color: ${({ theme }) => theme.colors.text.primary};
`;
@@ -115,7 +106,6 @@ export const SidePanelTitle = styled.h3`
align-items: center;
min-width: 0;
- margin: 0;
font: ${({ theme }) => theme.typography.h3.font};
color: ${({ theme }) => theme.colors.text.primary};
diff --git a/src/pages/main-page/playbooks-page/visual-editor/panels/Panel.styles.tsx b/src/pages/main-page/playbooks-page/visual-editor/panels/Panel.styles.tsx
index 53198212..8e59b23b 100644
--- a/src/pages/main-page/playbooks-page/visual-editor/panels/Panel.styles.tsx
+++ b/src/pages/main-page/playbooks-page/visual-editor/panels/Panel.styles.tsx
@@ -28,13 +28,11 @@ export const SectionTitle = styled.div`
`;
export const Hint = styled.p`
- margin: 0;
font: ${({ theme }) => theme.typography.caption.font};
color: ${({ theme }) => theme.colors.text.tertiary};
`;
export const IssueList = styled.ul`
- margin: 0;
padding-left: ${({ theme }) => theme.spacing.lg};
font: ${({ theme }) => theme.typography.caption.font};
`;
@@ -152,11 +150,8 @@ export const IssueCount = styled.span<{ $blocking: boolean }>`
`;
export const EntryList = styled.ul`
- margin: 0;
- padding: 0;
border: 1px solid ${({ theme }) => theme.colors.border.light};
border-radius: ${({ theme }) => theme.radius.md};
-
list-style: none;
`;
diff --git a/src/theme/GlobalStyles.ts b/src/theme/GlobalStyles.ts
index d0ae3327..cc0f9c81 100644
--- a/src/theme/GlobalStyles.ts
+++ b/src/theme/GlobalStyles.ts
@@ -18,6 +18,10 @@ export const GlobalStyles = createGlobalStyle`
background: none;
}
+ a {
+ text-decoration: none;
+ }
+
/* Headings are chosen for document structure; their look comes from theme.typography. */
h1, h2, h3, h4, h5, h6 {
font-size: inherit;
@@ -54,4 +58,15 @@ export const GlobalStyles = createGlobalStyle`
scrollbar-color: ${({ theme }) => theme.colors.primary.main} transparent;
scrollbar-width: thin;
}
+
+ @media (prefers-reduced-motion: reduce) {
+ *,
+ *::before,
+ *::after {
+ scroll-behavior: auto !important;
+ transition-duration: 0.01ms !important;
+ animation-duration: 0.01ms !important;
+ animation-iteration-count: 1 !important;
+ }
+ }
`;
From d95e21e34a1e46670d48eea306269c4daef21789 Mon Sep 17 00:00:00 2001
From: Paul2803k
Date: Tue, 1 Dec 2026 00:09:35 +0100
Subject: [PATCH 2/3] Replace native Select with SearchSelect, add DataTable
and store API client
---
.env.example | 1 +
README.md | 19 +
docker-compose.dev.yml | 1 +
package-lock.json | 34 ++
package.json | 1 +
src/api/store.ts | 64 +++
src/api/storeQueries.ts | 28 ++
src/auth/AuthProvider.tsx | 6 +-
src/auth/permissions.ts | 16 +
src/cacaoResources.ts | 18 +
src/components/Containers.tsx | 4 -
src/components/CopyButton.tsx | 6 +-
src/components/DataTable.tsx | 354 ++++++++++++++
src/components/Form.tsx | 136 +-----
src/components/SearchSelect.tsx | 4 +
src/components/VariableInput.test.ts | 73 +++
src/components/VariableInput.tsx | 134 +++--
src/components/index.ts | 1 +
src/mock/storeApi.test.ts | 117 +++++
src/mock/storeApi.ts | 458 ++++++++++++++++++
.../visual-editor/model/specs/cacao-2.0.ts | 21 +-
.../visual-editor/panels/PlaybookPanel.tsx | 16 +-
src/theme/theme.ts | 20 +
src/types/index.ts | 1 +
src/types/store.d.ts | 81 ++++
src/vite-env.d.ts | 5 +
vite.config.ts | 90 +++-
27 files changed, 1503 insertions(+), 206 deletions(-)
create mode 100644 src/api/store.ts
create mode 100644 src/api/storeQueries.ts
create mode 100644 src/cacaoResources.ts
create mode 100644 src/components/DataTable.tsx
create mode 100644 src/components/VariableInput.test.ts
create mode 100644 src/mock/storeApi.test.ts
create mode 100644 src/mock/storeApi.ts
create mode 100644 src/types/store.d.ts
diff --git a/.env.example b/.env.example
index 58e4eb26..6628138d 100644
--- a/.env.example
+++ b/.env.example
@@ -17,6 +17,7 @@ VITE_HTTPS_CERT_FILE= # required when VITE_ENABLE_HTTPS=true
VITE_HTTPS_KEY_FILE= # required when VITE_ENABLE_HTTPS=true
VITE_VERIFY_SSL=false # set true to verify the backend TLS certificate
VITE_USE_POLLING=false # set true when the filesystem does not emit file events reliably
+VITE_MOCK_STORE_API=false # set true to serve mock secret and variable routes until SOARCA has them
########## Docker Compose (dev) ##########
# Values used by `docker-compose.dev.yml`. Compose will substitute ${VAR} from the
diff --git a/README.md b/README.md
index 2c7433a5..0cf68a18 100644
--- a/README.md
+++ b/README.md
@@ -121,6 +121,7 @@ flowchart TB
- `VITE_HTTPS_CERT_FILE` - Path to the TLS certificate used by Vite
- `VITE_HTTPS_KEY_FILE` - Path to the TLS certificate key used by Vite
- `VITE_VERIFY_SSL` - Set to `true` to verify the backend certificate when Vite proxies API requests
+- `VITE_MOCK_STORE_API` - Set to `true` for the Resources page's temporary secret and variable endpoints (see [Mock store API](#mock-store-api))
- `DOCKER_HOST_PORT` - The port of the host machine that is mapped to the `VITE_SERVER_PORT` of the Vite dev server running in the container. This is only relevant when running the Development Container.
- `HOST_PORT` - is the same of the `VITE_SERVER_PORT` if run locally or `DOCKER_HOST_PORT` if running the Development Container.
@@ -172,6 +173,24 @@ flowchart TB
```
The app will be available at `http://localhost:HOST_PORT` with hot-reload enabled.
+#### Mock store API
+
+The Resources page groups global variables and read-only secrets into two tabs.
+SOARCA does not serve this API yet. Set `VITE_MOCK_STORE_API=true` to let the
+development server answer these routes with in-memory seed data:
+
+- `/api/secret/...`: read-only metadata and version history. Secret values are never returned.
+- `/api/variable/...`: create, edit, delete and restore global variable versions.
+
+All other `/api` requests still go to SOARCA. The flag also grants
+`secret:read`, `variable:read` and `variable:write` to signed-in users because
+SOARCA does not issue those permissions yet. The flag defaults to off, and the
+mock is not served by preview or production builds. Data resets on server restart.
+
+Playbook mappings, resolution and changes to execution inputs are not included
+yet. How global, external and step variables work together still needs planning.
+Existing playbook inputs keep their behavior.
+
### Enable sign-in
The GUI reads its login providers from `/auth-config.json`, a file you deploy
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index a5817011..e2b4574c 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -20,6 +20,7 @@ services:
- VITE_HTTPS_CERT_FILE=${VITE_HTTPS_CERT_FILE:-/app/certs/server.crt}
- VITE_HTTPS_KEY_FILE=${VITE_HTTPS_KEY_FILE:-/app/certs/server.key}
- VITE_VERIFY_SSL=${VITE_VERIFY_SSL:-false}
+ - VITE_MOCK_STORE_API=${VITE_MOCK_STORE_API:-false}
- VITE_IS_DOCKER=true
volumes:
- .:/app
diff --git a/package-lock.json b/package-lock.json
index af7fe23d..6c332f2e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -12,6 +12,7 @@
"@radix-ui/react-scroll-area": "^1.4.0",
"@tabler/icons-react": "^3.49.0",
"@tanstack/react-query": "^5.108.4",
+ "@tanstack/react-table": "^8.21.3",
"@xyflow/react": "^12.12.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
@@ -3178,6 +3179,39 @@
}
}
},
+ "node_modules/@tanstack/react-table": {
+ "version": "8.21.3",
+ "resolved": "https://registry.npmjs.org/@tanstack/react-table/-/react-table-8.21.3.tgz",
+ "integrity": "sha512-5nNMTSETP4ykGegmVkhjcS8tTLW6Vl4axfEGQN3v0zdHYbK4UfoqfPChclTrJ4EoK9QynqAu9oUf8VEmrpZ5Ww==",
+ "license": "MIT",
+ "dependencies": {
+ "@tanstack/table-core": "8.21.3"
+ },
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/tannerlinsley"
+ },
+ "peerDependencies": {
+ "react": ">=16.8",
+ "react-dom": ">=16.8"
+ }
+ },
+ "node_modules/@tanstack/table-core": {
+ "version": "8.21.3",
+ "resolved": "https://registry.npmjs.org/@tanstack/table-core/-/table-core-8.21.3.tgz",
+ "integrity": "sha512-ldZXEhOBb8Is7xLs01fR3YEc3DERiz5silj8tnGkFZytt1abEvl/GhUmCE0PMLaMPTa3Jk4HbKmRlHmu+gCftg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/tannerlinsley"
+ }
+ },
"node_modules/@testing-library/dom": {
"version": "10.4.2",
"resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.2.tgz",
diff --git a/package.json b/package.json
index a4662da7..01624d1b 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
"@radix-ui/react-scroll-area": "^1.4.0",
"@tabler/icons-react": "^3.49.0",
"@tanstack/react-query": "^5.108.4",
+ "@tanstack/react-table": "^8.21.3",
"@xyflow/react": "^12.12.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
diff --git a/src/api/store.ts b/src/api/store.ts
new file mode 100644
index 00000000..3fe0291b
--- /dev/null
+++ b/src/api/store.ts
@@ -0,0 +1,64 @@
+import type {
+ NewStoredVariable,
+ SecretBackend,
+ SecretMetadata,
+ SecretVersion,
+ StoredVariable,
+ StoredVariableVersion,
+} from "@/types";
+import {
+ deleteToApi,
+ fetchFromApi,
+ HttpMutationMethod,
+ mutationToApi,
+} from "./utils";
+
+const segment = (value: string) => encodeURIComponent(value);
+
+export const getSecretBackend = () =>
+ fetchFromApi(`/api/secret/backend`);
+
+export const getSecrets = () => fetchFromApi(`/api/secret/`);
+
+export const getSecretVersions = (secret: string) =>
+ fetchFromApi(`/api/secret/${segment(secret)}/versions`);
+
+export const getVariables = () =>
+ fetchFromApi(`/api/variable/`);
+
+export const getVariableVersions = (variable: string) =>
+ fetchFromApi(
+ `/api/variable/${segment(variable)}/versions`,
+ );
+
+export const createVariable = (variable: NewStoredVariable) =>
+ mutationToApi(
+ HttpMutationMethod.POST,
+ `/api/variable/`,
+ variable,
+ );
+
+/** Writes a new version. `version` is the one the user saw; a stale one gives 409. */
+export const updateVariableValue = (
+ variable: string,
+ version: number,
+ value: string,
+) =>
+ mutationToApi(
+ HttpMutationMethod.PUT,
+ `/api/variable/${segment(variable)}`,
+ { version, value },
+ );
+
+export const updateVariableDescription = (
+ variable: string,
+ description: string,
+) =>
+ mutationToApi(
+ HttpMutationMethod.PATCH,
+ `/api/variable/${segment(variable)}`,
+ { description },
+ );
+
+export const deleteVariable = (variable: string) =>
+ deleteToApi(`/api/variable/${segment(variable)}`);
diff --git a/src/api/storeQueries.ts b/src/api/storeQueries.ts
new file mode 100644
index 00000000..25505506
--- /dev/null
+++ b/src/api/storeQueries.ts
@@ -0,0 +1,28 @@
+import { queryOptions } from "@tanstack/react-query";
+
+import {
+ getSecretBackend,
+ getSecrets,
+ getSecretVersions,
+ getVariables,
+ getVariableVersions,
+} from "./store";
+
+/** Every component that reads the store uses these, so keys and caching match. */
+export const storeQueries = {
+ secretBackend: () =>
+ queryOptions({ queryKey: ["secret-backend"], queryFn: getSecretBackend }),
+ secrets: () => queryOptions({ queryKey: ["secrets"], queryFn: getSecrets }),
+ secretVersions: (secret: string) =>
+ queryOptions({
+ queryKey: ["secret", secret, "versions"],
+ queryFn: () => getSecretVersions(secret),
+ }),
+ variables: () =>
+ queryOptions({ queryKey: ["variables"], queryFn: getVariables }),
+ variableVersions: (variable: string) =>
+ queryOptions({
+ queryKey: ["variable", variable, "versions"],
+ queryFn: () => getVariableVersions(variable),
+ }),
+};
diff --git a/src/auth/AuthProvider.tsx b/src/auth/AuthProvider.tsx
index ff611a5b..5097c2a4 100644
--- a/src/auth/AuthProvider.tsx
+++ b/src/auth/AuthProvider.tsx
@@ -4,6 +4,7 @@ import toast from "react-hot-toast";
import { redirectToLogin } from "@/api/utils";
import { AuthContext } from "@/auth/AuthContext";
import { beginSignOut, isSigningOut, resetSigningOut } from "@/auth/oidc";
+import { MOCKED_PERMISSIONS } from "@/auth/permissions";
import { loadSession } from "@/auth/session";
export function AuthProvider({ children }: PropsWithChildren) {
@@ -50,7 +51,10 @@ export function AuthProvider({ children }: PropsWithChildren) {
isLoading: session.isLoading,
// Only the initial check blocks; a failed background refetch keeps the cached user.
isError: session.isLoadingError,
- can: (permission) => user?.permissions.includes(permission) ?? false,
+ can: (permission) =>
+ !!user &&
+ (user.permissions.includes(permission) ||
+ MOCKED_PERMISSIONS.includes(permission)),
logout: () => {
if (isSigningOut()) return;
void beginSignOut().then(
diff --git a/src/auth/permissions.ts b/src/auth/permissions.ts
index 248d99ad..28695ff6 100644
--- a/src/auth/permissions.ts
+++ b/src/auth/permissions.ts
@@ -3,6 +3,22 @@ export const Permissions = {
PlaybookRead: "playbook:read",
PlaybookWrite: "playbook:write",
PlaybookExecute: "playbook:execute",
+ SecretRead: "secret:read",
+ VariableRead: "variable:read",
+ VariableWrite: "variable:write",
} as const;
export type Permission = (typeof Permissions)[keyof typeof Permissions];
+
+// SOARCA does not issue the store permissions yet. While the mock store API
+// answers those routes, the GUI grants them to every signed-in user.
+export const MOCKED_PERMISSIONS: readonly Permission[] =
+ import.meta.env.DEV &&
+ import.meta.env.MODE !== "test" &&
+ import.meta.env.VITE_MOCK_STORE_API === "true"
+ ? [
+ Permissions.SecretRead,
+ Permissions.VariableRead,
+ Permissions.VariableWrite,
+ ]
+ : [];
diff --git a/src/cacaoResources.ts b/src/cacaoResources.ts
new file mode 100644
index 00000000..648ae176
--- /dev/null
+++ b/src/cacaoResources.ts
@@ -0,0 +1,18 @@
+/** CACAO 2.0 variable-type-ov values. */
+export const VARIABLE_TYPES = [
+ "bool",
+ "dictionary",
+ "float",
+ "hexstring",
+ "integer",
+ "ipv4-addr",
+ "ipv6-addr",
+ "long",
+ "mac-addr",
+ "hash",
+ "md5-hash",
+ "sha256-hash",
+ "string",
+ "uri",
+ "uuid",
+] as const;
diff --git a/src/components/Containers.tsx b/src/components/Containers.tsx
index 871b857c..96b9a8e5 100644
--- a/src/components/Containers.tsx
+++ b/src/components/Containers.tsx
@@ -57,8 +57,4 @@ export const HeaderActions = styled.div`
width: 15rem;
max-width: 100%;
}
-
- > select {
- width: 9rem;
- }
`;
diff --git a/src/components/CopyButton.tsx b/src/components/CopyButton.tsx
index f2c534f2..4c4a006e 100644
--- a/src/components/CopyButton.tsx
+++ b/src/components/CopyButton.tsx
@@ -3,10 +3,10 @@ import React from "react";
import toast from "react-hot-toast";
import { formatErrorForToast } from "@/api/utils";
-import { Button } from "./Button";
+import { Button, type ButtonProps } from "./Button";
import Icon from "./Icon";
-export interface CopyButtonProps extends React.ButtonHTMLAttributes {
+export interface CopyButtonProps extends ButtonProps {
$value: string;
}
@@ -25,7 +25,7 @@ export const CopyButton: React.FC = ({
}) => {
const handleClick = async (e: React.MouseEvent) => {
e.stopPropagation();
- if (disabled || !$value) return;
+ if (disabled) return;
try {
await navigator.clipboard.writeText($value);
diff --git a/src/components/DataTable.tsx b/src/components/DataTable.tsx
new file mode 100644
index 00000000..62d3b72a
--- /dev/null
+++ b/src/components/DataTable.tsx
@@ -0,0 +1,354 @@
+import {
+ IconArrowsSort,
+ IconSortAscending,
+ IconSortDescending,
+} from "@tabler/icons-react";
+import {
+ flexRender,
+ getCoreRowModel,
+ getSortedRowModel,
+ useReactTable,
+ type ColumnDef,
+ type SortingState,
+} from "@tanstack/react-table";
+import { Fragment, useState, type ReactNode } from "react";
+import styled from "styled-components";
+
+import { ScrollArea } from "./ScrollArea";
+
+export const TablePage = styled.section`
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+
+ min-width: 0;
+ min-height: 0;
+
+ background-color: ${({ theme }) => theme.colors.background.primary};
+`;
+
+export const TableToolbar = styled.div`
+ display: flex;
+ flex-shrink: 0;
+ flex-wrap: wrap;
+ gap: ${({ theme }) => theme.spacing.md};
+ align-items: center;
+ justify-content: space-between;
+
+ padding: ${({ theme }) => theme.spacing.lg};
+`;
+
+export const TableInset = styled.div`
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+
+ min-width: 0;
+ min-height: 0;
+ padding: 0 ${({ theme }) => theme.spacing.lg}
+ ${({ theme }) => theme.spacing.lg};
+`;
+
+const TableScrollArea = styled(ScrollArea)`
+ --scroll-area-radius: calc(${({ theme }) => theme.radius.md} - 1px)
+ calc(${({ theme }) => theme.radius.md} - 1px) 0 0;
+
+ flex: 1 1 auto;
+
+ width: 100%;
+ min-height: 0;
+ border: 1px solid ${({ theme }) => theme.colors.dataTable.border};
+ border-bottom: 0;
+ border-radius: ${({ theme }) => theme.radius.md}
+ ${({ theme }) => theme.radius.md} 0 0;
+
+ background: ${({ theme }) => theme.colors.dataTable.bodyBg};
+
+ /* A size container, so the detail rows can use cqi units for the visible width. */
+ > [data-radix-scroll-area-viewport] {
+ container-type: inline-size;
+ }
+`;
+
+const Grid = styled.table<{ $minWidth: number }>`
+ table-layout: fixed;
+ border-collapse: collapse;
+
+ width: 100%;
+ min-width: ${({ $minWidth }) => $minWidth}px;
+
+ font: ${({ theme }) => theme.typography.caption.font};
+ text-align: left;
+
+ th,
+ td {
+ padding: ${({ theme }) => theme.spacing.sm};
+ border-bottom: 1px solid ${({ theme }) => theme.colors.dataTable.border};
+ white-space: nowrap;
+ }
+
+ th:first-child,
+ td:first-child {
+ padding-left: ${({ theme }) => theme.spacing.lg};
+ }
+
+ th:last-child,
+ td:last-child {
+ padding-right: ${({ theme }) => theme.spacing.lg};
+ }
+
+ th {
+ position: sticky;
+ z-index: 2;
+ top: 0;
+
+ border-bottom: 0;
+
+ font: ${({ theme }) => theme.typography.caption.font};
+ font-weight: ${({ theme }) => theme.fonts.weight.medium};
+ color: ${({ theme }) => theme.colors.dataTable.headerText};
+
+ background: ${({ theme }) => theme.colors.dataTable.headerBg};
+ box-shadow: inset 0 -1px ${({ theme }) => theme.colors.dataTable.border};
+ }
+
+ td {
+ overflow: hidden;
+ color: ${({ theme }) => theme.colors.text.primary};
+ text-overflow: ellipsis;
+ }
+
+ td > span {
+ max-width: 100%;
+ }
+
+ tbody tr:not([data-detail]) {
+ background: ${({ theme }) => theme.colors.background.primary};
+ }
+
+ tbody tr:not([data-detail]):hover {
+ background: ${({ theme }) => theme.colors.dataTable.rowHoverBg};
+ }
+
+ tbody tr:not([data-detail]):hover td:first-child {
+ box-shadow: inset 3px 0 ${({ theme }) => theme.colors.primary.main};
+ }
+
+ tr[data-clickable="true"] {
+ cursor: pointer;
+ }
+
+ tr[data-clickable="true"]:focus-visible {
+ outline: 2px solid ${({ theme }) => theme.colors.primary.main};
+ outline-offset: -2px;
+ }
+
+ [data-actions="true"] {
+ position: sticky;
+ z-index: 1;
+ right: 0;
+
+ text-align: right;
+
+ background: ${({ theme }) => theme.colors.background.primary};
+ }
+
+ th[data-actions="true"] {
+ z-index: 3;
+ background: ${({ theme }) => theme.colors.dataTable.headerBg};
+ }
+
+ tbody tr:hover [data-actions="true"] {
+ background: ${({ theme }) => theme.colors.dataTable.rowHoverBg};
+ }
+
+ td[data-detail-cell] {
+ overflow: visible;
+ padding: 0;
+ white-space: normal;
+ background: ${({ theme }) => theme.colors.dataTable.detailBg};
+ }
+`;
+
+const DetailBox = styled.div`
+ position: sticky;
+ left: 0;
+ width: min(100%, 100cqi);
+ padding: ${({ theme }) => `${theme.spacing.sm} ${theme.spacing.lg}`};
+`;
+
+const SortButton = styled.button`
+ display: inline-flex;
+ gap: ${({ theme }) => theme.spacing.xs};
+ align-items: center;
+
+ &:hover {
+ color: ${({ theme }) => theme.colors.dataTable.headerHoverText};
+ }
+
+ &:focus-visible {
+ outline: 2px solid ${({ theme }) => theme.colors.dataTable.headerHoverText};
+ outline-offset: 3px;
+ }
+`;
+
+const Footer = styled.div`
+ flex-shrink: 0;
+
+ padding: ${({ theme }) => `${theme.spacing.sm} ${theme.spacing.lg}`};
+ border: 1px solid ${({ theme }) => theme.colors.dataTable.border};
+
+ font: ${({ theme }) => theme.typography.caption.font};
+ color: ${({ theme }) => theme.colors.text.secondary};
+
+ background: ${({ theme }) => theme.colors.dataTable.footerBg};
+`;
+
+export interface DataTableProps {
+ data: T[];
+ columns: ColumnDef[];
+ label: string;
+ emptyMessage: string;
+ initialSorting?: SortingState;
+ renderDetail?: (row: T) => ReactNode;
+ /** Makes rows clickable, with Enter on a focused row doing the same. */
+ onRowClick?: (row: T) => void;
+ getRowId?: (row: T) => string;
+ /** Below this width in pixels the table scrolls horizontally. */
+ minWidth?: number;
+}
+
+export function DataTable({
+ data,
+ columns,
+ label,
+ emptyMessage,
+ initialSorting = [],
+ renderDetail,
+ onRowClick,
+ getRowId,
+ minWidth = 850,
+}: DataTableProps) {
+ const [sorting, setSorting] = useState(initialSorting);
+ // TanStack Table v8 returns mutable callbacks that React Compiler cannot memoize.
+ // oxlint-disable-next-line react/incompatible-library
+ const table = useReactTable({
+ data,
+ columns,
+ state: { sorting },
+ onSortingChange: setSorting,
+ getCoreRowModel: getCoreRowModel(),
+ getSortedRowModel: getSortedRowModel(),
+ getRowId,
+ getRowCanExpand: () => !!renderDetail,
+ autoResetExpanded: false,
+ });
+ const rows = table.getRowModel().rows;
+ const visibleColumns = table.getVisibleLeafColumns();
+ const totalSize = visibleColumns.reduce(
+ (sum, column) => sum + column.getSize(),
+ 0,
+ );
+
+ return (
+ <>
+
+
+
+ {visibleColumns.map((column) => (
+ 0
+ ? { width: `${(column.getSize() / totalSize) * 100}%` }
+ : undefined
+ }
+ />
+ ))}
+
+
+ {table.getHeaderGroups().map((group) => (
+
+ {group.headers.map((header) => {
+ const sorted = header.column.getIsSorted();
+ const SortIcon =
+ sorted === "asc"
+ ? IconSortAscending
+ : sorted === "desc"
+ ? IconSortDescending
+ : IconArrowsSort;
+ return (
+ |
+ {header.isPlaceholder ? null : header.column.getCanSort() ? (
+
+ {flexRender(
+ header.column.columnDef.header,
+ header.getContext(),
+ )}
+
+
+ ) : (
+ flexRender(
+ header.column.columnDef.header,
+ header.getContext(),
+ )
+ )}
+ |
+ );
+ })}
+
+ ))}
+
+
+ {rows.map((row) => (
+
+ onRowClick(row.original))}
+ onKeyDown={
+ onRowClick &&
+ ((e) => {
+ if (e.key === "Enter" && e.target === e.currentTarget)
+ onRowClick(row.original);
+ })
+ }
+ >
+ {row.getVisibleCells().map((cell) => (
+ |
+ {flexRender(
+ cell.column.columnDef.cell,
+ cell.getContext(),
+ )}
+ |
+ ))}
+
+ {renderDetail && row.getIsExpanded() && (
+
+ |
+ {renderDetail(row.original)}
+ |
+
+ )}
+
+ ))}
+
+
+
+
+ >
+ );
+}
diff --git a/src/components/Form.tsx b/src/components/Form.tsx
index eeb8b7af..0e732b5c 100644
--- a/src/components/Form.tsx
+++ b/src/components/Form.tsx
@@ -15,9 +15,11 @@ interface ControlSizeProps {
* @example
*
*/
-export const Input = styled.input`
+export const Input = styled.input`
width: 100%;
- border: 1px solid ${({ theme }) => theme.colors.border.medium};
+ border: 1px solid
+ ${({ theme, $hasError }) =>
+ $hasError ? theme.colors.error.border : theme.colors.border.medium};
border-radius: ${({ theme }) => theme.radius.md};
${({ $size = ThemeSize.Medium, theme }) => {
@@ -59,136 +61,6 @@ export const Input = styled.input`
}
`;
-/**
- * Styled select element keeping the same visuals as the `Input` component.
- * Option elements are styled where supported by the browser.
- */
-const StyledSelect = styled.select`
- width: 100%;
- border: 1px solid ${({ theme }) => theme.colors.border.medium};
- border-radius: ${({ theme }) => theme.radius.md};
-
- ${({ $size = ThemeSize.Medium, theme }) => {
- const { height, paddingX } = getControlSize(theme, $size);
- return `
- height: ${height};
- padding: 0 ${theme.spacing["2xl"]} 0 ${paddingX};
- `;
- }};
-
- font: ${({ theme }) => theme.typography.body.font};
- font-size: ${({ $size = ThemeSize.Medium, theme }) =>
- getControlSize(theme, $size).fontSize};
- color: ${({ theme }) => theme.colors.text.primary};
-
- -webkit-appearance: none;
- appearance: none;
- background-color: ${({ theme }) => theme.colors.background.primary};
- background-image: ${({ theme }) => {
- const color = theme.colors.text.tertiary.replace("#", "%23");
- return `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='${color}' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C%2Fsvg%3E")`;
- }};
- background-repeat: no-repeat;
- background-position: right ${({ theme }) => theme.spacing.md} center;
-
- transition: border-color ${({ theme }) => theme.transitions.base};
-
- &:hover {
- border-color: ${({ theme }) => theme.colors.primary.hover};
- }
- &:focus {
- border-color: ${({ theme }) => theme.colors.primary.main};
- outline: none;
- box-shadow:
- 0 0 8px 0px ${({ theme }) => theme.colors.primary.main}20,
- 0 0 12px 0px ${({ theme }) => theme.colors.primary.main}10;
- }
-
- &:disabled {
- cursor: not-allowed;
- opacity: 0.5;
- background-color: ${({ theme }) => theme.colors.background.secondary};
- }
-
- & > option {
- padding: ${({ theme }) => `${theme.spacing.md}`};
- border-radius: ${({ theme }) => theme.radius.md};
-
- font: ${({ theme }) => theme.typography.body.font};
- line-height: 1.75;
- color: ${({ theme }) => theme.colors.text.primary};
-
- background: ${({ theme }) => theme.colors.background.primary};
- }
-
- & > option:hover {
- background: ${({ theme }) => theme.colors.background.secondary};
- }
-`;
-
-const StyledOption = styled.option`
- padding: ${({ theme }) => `${theme.spacing.md}`};
- border-radius: ${({ theme }) => theme.radius.md};
-
- font: ${({ theme }) => theme.typography.body.font};
- line-height: 1.75;
- color: ${({ theme }) => theme.colors.text.primary};
-
- background: ${({ theme }) => theme.colors.background.primary};
-`;
-
-export interface SelectProps
- extends
- Omit, "value">,
- ControlSizeProps {
- $value?: string | number;
- $onChange?: (value: string) => void;
- $options: Array<{
- value: string;
- label: React.ReactNode;
- disabled?: boolean;
- }>;
- $placeholder?: string;
-}
-
-/**
- * Controlled Select component that accepts `$value`, `$onChange` and `$options`.
- * Renders styled options and falls back to children if provided.
- * @param $value - Controlled value of the select (string|number).
- * @param $onChange - Handler invoked with the selected value.
- * @param $options - Array of options to render: { value, label, disabled? }.
- * @param $placeholder - Optional placeholder entry rendered with empty value.
- * @param $size - Same sizes as Button. Defaults to Medium.
- */
-export const Select: React.FC = ({
- $value,
- $onChange,
- $options,
- $placeholder,
- children,
- ...rest
-}) => {
- const handleChange: React.ChangeEventHandler = (e) => {
- if ($onChange) $onChange(e.target.value);
- if (rest.onChange)
- (rest.onChange as React.ChangeEventHandler)(e);
- };
-
- return (
-
- {typeof $placeholder === "string" && (
- {$placeholder}
- )}
- {($options || []).map((opt) => (
-
- {opt.label}
-
- ))}
- {children}
-
- );
-};
-
/**
* Form group container for label + input pairs with consistent spacing.
* Stacks label and input vertically with a small gap and adds bottom margin between groups.
diff --git a/src/components/SearchSelect.tsx b/src/components/SearchSelect.tsx
index 45bbcb14..2cd4aaf9 100644
--- a/src/components/SearchSelect.tsx
+++ b/src/components/SearchSelect.tsx
@@ -31,6 +31,8 @@ type CommonProps = {
$disabled?: boolean;
$loading?: boolean;
$ariaLabel?: string;
+ title?: string;
+ $searchable?: boolean;
$clearable?: boolean;
$required?: boolean;
};
@@ -175,6 +177,7 @@ export const SearchSelect: React.FC = (props) => {
"aria-label": props.$ariaLabel,
required: props.$required,
isMulti: !!props.$multi,
+ isSearchable: props.$searchable ?? true,
isClearable: props.$clearable ?? true,
placeholder: $placeholder ?? "Select…",
value: props.$multi
@@ -205,6 +208,7 @@ export const SearchSelect: React.FC = (props) => {
return (
{
if (event.key === "Escape") {
escapeClosedMenu.current = menuOpen.current;
diff --git a/src/components/VariableInput.test.ts b/src/components/VariableInput.test.ts
new file mode 100644
index 00000000..2fef9738
--- /dev/null
+++ b/src/components/VariableInput.test.ts
@@ -0,0 +1,73 @@
+import { describe, expect, it } from "vitest";
+
+import { validateVariableValue } from "./VariableInput";
+
+describe("validateVariableValue", () => {
+ it("treats empty values as valid unless required", () => {
+ expect(validateVariableValue("string", "")).toBeUndefined();
+ expect(validateVariableValue("integer", "")).toBeUndefined();
+ expect(validateVariableValue("bool", "", false)).toBeUndefined();
+ expect(validateVariableValue("bool", "", true)).toBe("Value is required.");
+ });
+
+ it("requires dictionaries to be JSON objects rather than arrays or primitives", () => {
+ expect(validateVariableValue("dictionary", '{"a": 1}')).toBeUndefined();
+ expect(validateVariableValue("dictionary", "{}")).toBeUndefined();
+ expect(validateVariableValue("dictionary", "[1, 2]")).toBeTruthy();
+ expect(validateVariableValue("dictionary", "null")).toBeTruthy();
+ expect(validateVariableValue("dictionary", '"hello"')).toBeTruthy();
+ expect(validateVariableValue("dictionary", "{bad json")).toBeTruthy();
+ });
+
+ it("validates numeric, boolean, and URI values", () => {
+ expect(validateVariableValue("integer", "-42")).toBeUndefined();
+ expect(validateVariableValue("integer", "3.14")).toBeTruthy();
+ expect(validateVariableValue("long", "9001")).toBeUndefined();
+ expect(validateVariableValue("float", "-3.14")).toBeUndefined();
+ expect(validateVariableValue("float", "1e5")).toBeUndefined();
+ expect(validateVariableValue("float", " ")).toBeTruthy();
+ expect(validateVariableValue("bool", "true")).toBeUndefined();
+ expect(validateVariableValue("bool", "false")).toBeUndefined();
+ expect(validateVariableValue("bool", "maybe")).toBeTruthy();
+ expect(
+ validateVariableValue("uri", "https://example.com/a"),
+ ).toBeUndefined();
+ expect(validateVariableValue("uri", "not a uri")).toBeTruthy();
+ });
+
+ it("validates simple regex formats", () => {
+ expect(validateVariableValue("hexstring", "4a6f686e")).toBeUndefined();
+ expect(validateVariableValue("hexstring", "0x4a6f")).toBeTruthy();
+ expect(
+ validateVariableValue("mac-addr", "00:1A:2B:3C:4D:5E"),
+ ).toBeUndefined();
+ expect(validateVariableValue("mac-addr", "invalid")).toBeTruthy();
+ expect(
+ validateVariableValue("uuid", "550e8400-e29b-41d4-a716-446655440000"),
+ ).toBeUndefined();
+ expect(validateVariableValue("uuid", "not-a-uuid")).toBeTruthy();
+ expect(validateVariableValue("hash", "deadbeef")).toBeUndefined();
+ expect(validateVariableValue("hash", "xyz")).toBeTruthy();
+ expect(validateVariableValue("md5-hash", "a".repeat(32))).toBeUndefined();
+ expect(validateVariableValue("md5-hash", "a".repeat(31))).toBeTruthy();
+ expect(
+ validateVariableValue("sha256-hash", "f".repeat(64)),
+ ).toBeUndefined();
+ expect(validateVariableValue("sha256-hash", "f".repeat(63))).toBeTruthy();
+ });
+
+ it("validates IPv4 and IPv6 addresses with optional CIDR prefixes", () => {
+ expect(validateVariableValue("ipv4-addr", "192.168.1.1")).toBeUndefined();
+ expect(validateVariableValue("ipv4-addr", "10.0.0.0/24")).toBeUndefined();
+ expect(validateVariableValue("ipv4-addr", "999.168.1.1")).toBeTruthy();
+ expect(validateVariableValue("ipv4-addr", "192.168.1.1/33")).toBeTruthy();
+ expect(
+ validateVariableValue("ipv6-addr", "2001:0db8:85a3::8a2e:0370:7334"),
+ ).toBeUndefined();
+ expect(validateVariableValue("ipv6-addr", "::1")).toBeUndefined();
+ expect(validateVariableValue("ipv6-addr", "fe80::1/64")).toBeUndefined();
+ expect(validateVariableValue("ipv6-addr", "not-an-ip")).toBeTruthy();
+ expect(validateVariableValue("ipv6-addr", "192.168.1.1")).toBeTruthy();
+ expect(validateVariableValue("ipv6-addr", "fe80::1/129")).toBeTruthy();
+ });
+});
diff --git a/src/components/VariableInput.tsx b/src/components/VariableInput.tsx
index 16bfcd3a..7f58ecfa 100644
--- a/src/components/VariableInput.tsx
+++ b/src/components/VariableInput.tsx
@@ -1,5 +1,6 @@
import { CodeEditor } from "./CodeEditor";
-import { Input, Select } from "./Form";
+import { Input } from "./Form";
+import { SearchSelect } from "./SearchSelect";
import { ThemeSize } from "./utils";
interface VariableInputProps {
@@ -15,17 +16,15 @@ interface VariableInputProps {
}
type TextFormat = {
- inputType?: "number" | "url";
+ inputType?: "number";
step?: string;
placeholder: string;
- pattern?: string;
};
const INTEGER_FORMAT: TextFormat = {
inputType: "number",
step: "1",
placeholder: "Enter integer value",
- pattern: "^-?\\d+$",
};
const TEXT_FORMATS: Record = {
@@ -35,47 +34,108 @@ const TEXT_FORMATS: Record = {
inputType: "number",
step: "any",
placeholder: "Enter float value",
- pattern: "^-?\\d+(\\.\\d+)?$",
+ },
+ hexstring: {
+ placeholder: "4a6f686e",
},
"ipv4-addr": {
placeholder: "192.168.1.1",
- pattern: "^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$",
},
"ipv6-addr": {
placeholder: "2001:0db8:85a3::8a2e:0370:7334",
- pattern: "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$",
},
"mac-addr": {
placeholder: "00:1A:2B:3C:4D:5E",
- pattern: "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$",
},
- uri: { inputType: "url", placeholder: "https://example.com" },
+ uri: { placeholder: "https://example.com" },
uuid: {
placeholder: "550e8400-e29b-41d4-a716-446655440000",
- pattern:
- "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
},
- hash: { placeholder: "Hash value (hex string)", pattern: "^[a-fA-F0-9]+$" },
+ hash: { placeholder: "Hash value (hex string)" },
"md5-hash": {
placeholder: "MD5 hash (32 characters)",
- pattern: "^[a-fA-F0-9]{32}$",
},
"sha256-hash": {
placeholder: "SHA-256 hash (64 characters)",
- pattern: "^[a-fA-F0-9]{64}$",
},
};
-const isInvalidJson = (text: string) => {
- if (text.trim() === "") return false;
+const isValidDictionary = (text: string): boolean => {
try {
- JSON.parse(text);
- return false;
+ const parsed: unknown = JSON.parse(text);
+ return (
+ typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
+ );
} catch {
- return true;
+ return false;
}
};
+const FORMAT_CHECKS: Record = {
+ integer: { pattern: /^-?\d+$/, message: "Enter a whole number." },
+ long: { pattern: /^-?\d+$/, message: "Enter a whole number." },
+ hexstring: {
+ pattern: /^[0-9a-fA-F]+$/,
+ message: "Use hexadecimal digits only (0-9, a-f).",
+ },
+ "ipv4-addr": {
+ pattern:
+ /^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\/(?:3[0-2]|[12]?\d))?$/,
+ message: "Enter a valid IPv4 address (e.g. 192.168.1.1).",
+ },
+ "ipv6-addr": {
+ pattern: /^[0-9a-fA-F]*:[0-9a-fA-F:.]*(?:\/(?:12[0-8]|1[01]\d|[1-9]?\d))?$/,
+ message: "Enter a valid IPv6 address (e.g. 2001:db8::1).",
+ },
+ "mac-addr": {
+ pattern: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
+ message: "Enter a valid MAC address (e.g. 00:1A:2B:3C:4D:5E).",
+ },
+ uuid: {
+ pattern:
+ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
+ message: "Enter a valid UUID.",
+ },
+ hash: { pattern: /^[a-fA-F0-9]+$/, message: "Enter a hexadecimal hash." },
+ "md5-hash": {
+ pattern: /^[a-fA-F0-9]{32}$/,
+ message: "Enter a 32-character hexadecimal MD5 hash.",
+ },
+ "sha256-hash": {
+ pattern: /^[a-fA-F0-9]{64}$/,
+ message: "Enter a 64-character hexadecimal SHA-256 hash.",
+ },
+};
+
+/** Validates a CACAO variable value for the given type. Returns an error message or undefined. */
+export function validateVariableValue(
+ type: string,
+ value: string,
+ required = false,
+): string | undefined {
+ if (value === "") return required ? "Value is required." : undefined;
+ if (type === "bool")
+ return value === "true" || value === "false"
+ ? undefined
+ : "Select True or False.";
+ if (type === "float")
+ return value.trim() !== "" && Number.isFinite(Number(value))
+ ? undefined
+ : "Enter a valid number.";
+ if (type === "dictionary")
+ return isValidDictionary(value) ? undefined : "Enter a valid JSON object.";
+ if (type === "uri") {
+ try {
+ new URL(value);
+ return undefined;
+ } catch {
+ return "Enter a valid URI (e.g. https://example.com).";
+ }
+ }
+ const check = FORMAT_CHECKS[type];
+ return check && !check.pattern.test(value) ? check.message : undefined;
+}
+
/** Input for a CACAO variable value. The control and its checks depend on the variable type. */
export const VariableInput: React.FC = ({
id,
@@ -88,17 +148,20 @@ export const VariableInput: React.FC = ({
onChange,
}) => {
const change = (next: string) => onChange(variableKey, next);
+ const invalid = value !== "" && !!validateVariableValue(type, value);
switch (type) {
case "bool":
return (
-