Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,96 @@
import clsx from "clsx";
import { GridLayoutDto } from "~/application/dtos/layout/GridLayoutDto";
type Props = GridLayoutDto & {
children: React.ReactNode;
className?: string;
};
export default function GridContainer({ children, className, columns, sm, md, lg, xl, xl2, gap }: Props) {
return (
<div
className={clsx(
className,
"grid",
gap === "xs" && "gap-2",
gap === "sm" && "gap-4",
gap === "md" && "gap-6",
gap === "lg" && "gap-8",
gap === "xl" && "gap-10",
columns === 1 && "grid-cols-1",
columns === 2 && "grid-cols-2",
columns === 3 && "grid-cols-3",
columns === 4 && "grid-cols-4",
columns === 5 && "grid-cols-5",
columns === 6 && "grid-cols-6",
columns === 7 && "grid-cols-7",
columns === 8 && "grid-cols-8",
columns === 9 && "grid-cols-9",
columns === 10 && "grid-cols-10",
columns === 11 && "grid-cols-11",
columns === 12 && "grid-cols-12",
sm === 1 && "sm:grid-cols-1",
sm === 2 && "sm:grid-cols-2",
sm === 3 && "sm:grid-cols-3",
sm === 4 && "sm:grid-cols-4",
sm === 5 && "sm:grid-cols-5",
sm === 6 && "sm:grid-cols-6",
sm === 7 && "sm:grid-cols-7",
sm === 8 && "sm:grid-cols-8",
sm === 9 && "sm:grid-cols-9",
sm === 10 && "sm:grid-cols-10",
sm === 11 && "sm:grid-cols-11",
sm === 12 && "sm:grid-cols-12",
md === 1 && "md:grid-cols-1",
md === 2 && "md:grid-cols-2",
md === 3 && "md:grid-cols-3",
md === 4 && "md:grid-cols-4",
md === 5 && "md:grid-cols-5",
md === 6 && "md:grid-cols-6",
md === 7 && "md:grid-cols-7",
md === 8 && "md:grid-cols-8",
md === 9 && "md:grid-cols-9",
md === 10 && "md:grid-cols-10",
md === 11 && "md:grid-cols-11",
md === 12 && "md:grid-cols-12",
lg === 1 && "lg:grid-cols-1",
lg === 2 && "lg:grid-cols-2",
lg === 3 && "lg:grid-cols-3",
lg === 4 && "lg:grid-cols-4",
lg === 5 && "lg:grid-cols-5",
lg === 6 && "lg:grid-cols-6",
lg === 7 && "lg:grid-cols-7",
lg === 8 && "lg:grid-cols-8",
lg === 9 && "lg:grid-cols-9",
lg === 10 && "lg:grid-cols-10",
lg === 11 && "lg:grid-cols-11",
lg === 12 && "lg:grid-cols-12",
xl === 1 && "xl:grid-cols-1",
xl === 2 && "xl:grid-cols-2",
xl === 3 && "xl:grid-cols-3",
xl === 4 && "xl:grid-cols-4",
xl === 5 && "xl:grid-cols-5",
xl === 6 && "xl:grid-cols-6",
xl === 7 && "xl:grid-cols-7",
xl === 8 && "xl:grid-cols-8",
xl === 9 && "xl:grid-cols-9",
xl === 10 && "xl:grid-cols-10",
xl === 11 && "xl:grid-cols-11",
xl === 12 && "xl:grid-cols-12",
xl2 === 1 && "2xl:grid-cols-1",
xl2 === 2 && "2xl:grid-cols-2",
xl2 === 3 && "2xl:grid-cols-3",
xl2 === 4 && "2xl:grid-cols-4",
xl2 === 5 && "2xl:grid-cols-5",
xl2 === 6 && "2xl:grid-cols-6",
xl2 === 7 && "2xl:grid-cols-7",
xl2 === 8 && "2xl:grid-cols-8",
xl2 === 9 && "2xl:grid-cols-9",
xl2 === 10 && "2xl:grid-cols-10",
xl2 === 11 && "2xl:grid-cols-11",
xl2 === 12 && "2xl:grid-cols-12"
)}
>
{children}
</div>
);
}
@@ -0,0 +1,102 @@
import clsx from "clsx";
import { Fragment, ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router";
import { Colors } from "~/application/enums/shared/Colors";
import ColorBadge from "../badges/ColorBadge";
import PlusIcon from "../icons/PlusIcon";
export type KanbanColumn<T> = {
name: string;
title: string | ReactNode;
items: T[];
color?: Colors;
card: (item: T) => any;
onNewRoute?: (columnValue: string) => string;
};
interface Props<T> {
columns: KanbanColumn<T>[];
className?: string;
withTitle?: boolean;
}
export default function Kanban<T>({ columns, className, withTitle }: Props<T>) {
return (
<div className={clsx(className, "flex w-full")}>
{columns.map((column, idx) => {
return <KanbanColumnCard idx={idx + 1} key={idx + 1} items={column.items} columns={columns} column={column} withTitle={withTitle} />;
})}
</div>
);
}
interface KanbanColumnCardProps<T> {
idx: number;
columns: KanbanColumn<T>[];
column: KanbanColumn<T>;
items: T[];
withTitle?: boolean;
}
function KanbanColumnCard<T>({ idx, columns, column, items, withTitle }: KanbanColumnCardProps<T>) {
const { t } = useTranslation();
return (
<div
className={clsx(
"w-64 shrink-0 space-y-2 divide-y divide-gray-300 text-sm",
columns.length === 1 && "lg:w-full",
columns.length === 2 && "lg:w-1/2",
columns.length === 3 && "lg:w-1/3",
columns.length === 4 && "lg:w-1/4",
columns.length === 5 && "lg:w-1/5"
)}
>
{withTitle !== false && (
<div className="flex justify-between space-x-2">
<div className="flex items-center space-x-2">
{column?.color !== undefined && (
<div>
<ColorBadge color={column.color} />
</div>
)}
<div>{column?.title ?? t("shared.notSet")}</div>
</div>
{/* {column.onNew && (
<button type="button" onClick={() => column.onNew && column.onNew()}>
<PlusIcon className="h-3 w-3" />
</button>
)} */}
</div>
)}
<div
className={clsx(
"border-border-default bg-surface-neutral-secondary group h-full overflow-x-hidden border-0 border-dashed px-2 py-3",
idx === 0 && "border-r-0",
idx === columns.length && "border-l-0"
)}
>
<div className="space-y-3">
{/* {getItems(column.name).length === 0 && (
<div className="p-2 flex justify-center">
<div className="text-muted-foreground">{t("shared.noRecords")}</div>
</div>
)} */}
{items.map((item, idx) => {
return <Fragment key={idx}>{column.card(item)}</Fragment>;
})}
{column?.onNewRoute && (
<Link
className="border-border-default text-text-neutral-tertiary hover:bg-surface-neutral-primary hover:text-text-neutral-primary/80 flex w-full items-center justify-center space-x-2 rounded-md border p-2 text-center text-xs font-medium"
to={column.onNewRoute(column.name)}
>
<div>{t("shared.add")}</div>
<PlusIcon className="h-3 w-3" />
</Link>
)}
</div>
</div>
</div>
);
}
@@ -0,0 +1,133 @@
import clsx from "clsx";
import { Fragment, ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router";
import { Colors } from "~/application/enums/shared/Colors";
import ColorBadge from "../badges/ColorBadge";
import PlusIcon from "../icons/PlusIcon";
export type KanbanColumn<T> = {
name: string;
title: string | ReactNode;
color?: Colors;
value: (item: T) => any;
onClick?: (item: T) => void;
onClickRoute?: (item: T) => string;
onNewRoute?: (columnValue: string) => string;
};
interface Props<T> {
columns: KanbanColumn<T>[];
column: string;
items: T[];
filterValue: (item: T, column: KanbanColumn<T> | null) => boolean;
undefinedColumn?: KanbanColumn<T>;
className?: string;
renderEmpty?: ReactNode;
classNameWidth?: string;
}
export default function KanbanSimple<T>({ columns, items, column, filterValue, undefinedColumn, className, renderEmpty, classNameWidth }: Props<T>) {
function getItems(column: KanbanColumn<T> | null) {
return items.filter((f: T) => filterValue(f, column));
}
return (
<div>
<div className={clsx(className, "flex overflow-hidden overflow-x-auto")}>
{undefinedColumn && getItems(null).length > 0 && (
<KanbanColumnCard idx={0} key={column.length} items={getItems(null)} columns={columns} column={undefinedColumn} classNameWidth={classNameWidth} />
)}
<Fragment>
{columns.map((column, idx) => {
return <KanbanColumnCard idx={idx + 1} key={idx + 1} items={getItems(column)} columns={columns} column={column} classNameWidth={classNameWidth} />;
})}
</Fragment>
</div>
{items.length === 0 && renderEmpty && <Fragment>{renderEmpty}</Fragment>}
</div>
);
}
interface KanbanColumnCardProps<T> {
idx: number;
columns: KanbanColumn<T>[];
column: KanbanColumn<T>;
items: T[];
classNameWidth?: string;
}
function KanbanColumnCard<T>({ idx, columns, column, items, classNameWidth }: KanbanColumnCardProps<T>) {
const { t } = useTranslation();
return (
<div
className={clsx(
"shrink-0 space-y-2 divide-y divide-gray-300 text-sm",
classNameWidth
? classNameWidth
: clsx(
columns.length === 1 && "w-64 lg:w-full",
columns.length === 2 && "w-64 lg:w-1/2",
columns.length === 3 && "w-64 lg:w-1/3",
columns.length === 4 && "w-64 lg:w-1/4",
columns.length === 5 && "w-64 lg:w-1/5",
columns.length > 5 && "w-64"
)
)}
>
<div className="flex justify-between space-x-2">
<div className="flex items-center space-x-2">
{column?.color !== undefined && (
<div>
<ColorBadge color={column.color} />
</div>
)}
<div>{column?.title ?? t("shared.notSet")}</div>
</div>
{/* {column.onNew && (
<button type="button" onClick={() => column.onNew && column.onNew()}>
<PlusIcon className="h-3 w-3" />
</button>
)} */}
</div>
<div
className={clsx(
"border-border-default bg-surface-neutral-secondary h-full overflow-x-hidden border-0 border-dashed px-2 py-3",
idx === 0 && "border-r-0",
idx === columns.length && "border-l-0"
)}
>
<div className="space-y-3">
{/* {getItems(column.name).length === 0 && (
<div className="p-2 flex justify-center">
<div className="text-muted-foreground">{t("shared.noRecords")}</div>
</div>
)} */}
{items.map((item, idx) => {
return (
<div key={idx} className="hover:bg-surface-neutral-secondary group w-full text-left shadow-2xs">
{column?.onClickRoute ? (
<Link to={column.onClickRoute(item)}>{column.value(item)}</Link>
) : (
<button type="button" onClick={() => column?.onClick && column?.onClick(item)}>
{column.value(item)}
</button>
)}
</div>
);
})}
{column?.onNewRoute && (
<Link
className="border-border-default text-text-neutral-tertiary hover:bg-surface-neutral-primary hover:text-text-neutral-primary/80 flex w-full items-center justify-center space-x-2 rounded-md border p-2 text-center text-xs font-medium"
to={column.onNewRoute(column.name)}
>
<div>{t("shared.add")}</div>
<PlusIcon className="h-3 w-3" />
</Link>
)}
</div>
</div>
</div>
);
}
@@ -0,0 +1,36 @@
import "@testing-library/jest-dom";
import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { expectNoAxeViolations } from "@toolctrl/ui-app/test-setup/axe";
import ViewToggle from "./ViewToggle";
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) =>
({
"shared.viewMode": "View mode",
"shared.tableView": "Table view",
"shared.boardView": "Board view",
})[key] ?? key,
}),
}));
describe("ViewToggle accessibility", () => {
it("gives icon-only controls names and selected state", () => {
const setView = vi.fn();
render(<ViewToggle view="table" setView={setView} />);
expect(screen.getByRole("group", { name: "View mode" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Table view" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("button", { name: "Board view" })).toHaveAttribute("aria-pressed", "false");
fireEvent.click(screen.getByRole("button", { name: "Board view" }));
expect(setView).toHaveBeenCalledWith("board");
});
it("has no axe violations", async () => {
await expectNoAxeViolations(<ViewToggle view="board" setView={() => {}} />);
});
});
@@ -0,0 +1,44 @@
import clsx from "clsx";
import { useTranslation } from "react-i18next";
import TableIcon from "../icons/TableIcon";
import ViewBoardsIcon from "../icons/ViewBoardsIcon";
interface Props {
view: "table" | "board";
setView: (value: "table" | "board") => void;
}
export default function ViewToggle({ view, setView }: Props) {
const { t } = useTranslation();
return (
<span aria-label={t("shared.viewMode")} className="relative z-0 inline-flex rounded-md shadow-2xs" role="group">
<button
aria-label={t("shared.tableView")}
aria-pressed={view === "table"}
onClick={() => setView("table")}
type="button"
className={clsx(
"border-border-default focus:border-brand-brand-border-solid-default focus:shadow-focus hover:bg-surface-neutral-secondary/90 relative inline-flex items-center rounded-l-md border px-4 py-2.5 text-sm font-medium focus:z-10 focus:outline-hidden",
view === "table" ? "bg-accent-100 text-accent-500" : "text-text-neutral-tertiary bg-surface-neutral-primary"
)}
>
<span aria-hidden="true">
<TableIcon className="h-4 w-4" />
</span>
</button>
<button
aria-label={t("shared.boardView")}
aria-pressed={view === "board"}
onClick={() => setView("board")}
type="button"
className={clsx(
"border-border-default focus:border-brand-brand-border-solid-default focus:shadow-focus hover:bg-surface-neutral-secondary/90 relative -ml-px inline-flex items-center rounded-r-md border px-4 py-2.5 text-sm font-medium focus:z-10 focus:outline-hidden",
view === "board" ? "bg-accent-100 text-accent-500" : "text-text-neutral-tertiary bg-surface-neutral-primary"
)}
>
<span aria-hidden="true">
<ViewBoardsIcon className="h-4 w-4" />
</span>
</button>
</span>
);
}
@@ -0,0 +1,47 @@
import "@testing-library/jest-dom";
import { fireEvent, render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router";
import { describe, expect, it, vi } from "vitest";
import { expectNoAxeViolations } from "@toolctrl/ui-app/test-setup/axe";
import ViewToggleWithUrl from "./ViewToggleWithUrl";
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) =>
({
"shared.viewMode": "View mode",
"shared.tableView": "Table view",
"shared.boardView": "Board view",
})[key] ?? key,
}),
}));
function renderWithRouter(initialEntry = "/items") {
return render(
<MemoryRouter initialEntries={[initialEntry]}>
<ViewToggleWithUrl />
</MemoryRouter>
);
}
describe("ViewToggleWithUrl accessibility", () => {
it("gives icon-only controls names and selected state from the URL", () => {
renderWithRouter("/items?view=board");
expect(screen.getByRole("group", { name: "View mode" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Table view" })).toHaveAttribute("aria-pressed", "false");
expect(screen.getByRole("button", { name: "Board view" })).toHaveAttribute("aria-pressed", "true");
fireEvent.click(screen.getByRole("button", { name: "Table view" }));
expect(screen.getByRole("button", { name: "Table view" })).toHaveAttribute("aria-pressed", "true");
});
it("has no axe violations", async () => {
await expectNoAxeViolations(
<MemoryRouter>
<ViewToggleWithUrl />
</MemoryRouter>
);
});
});
@@ -0,0 +1,65 @@
import clsx from "clsx";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useSearchParams } from "react-router";
import TableIcon from "../icons/TableIcon";
import ViewBoardsIcon from "../icons/ViewBoardsIcon";
interface Props {
defaultView?: "table" | "board";
className?: string;
}
export default function ViewToggleWithUrl({ defaultView, className }: Props) {
const { t } = useTranslation();
const [searchParams, setSearchParams] = useSearchParams();
const [view, setView] = useState(searchParams.get("view") ?? defaultView ?? "table");
useEffect(() => {
const view = searchParams.get("view");
if (view) {
setView(view);
}
}, [searchParams]);
// useEffect(() => {
// searchParams.set("view", view);
// setSearchParams(searchParams);
// }, [view]);
function onChange(value: "table" | "board") {
searchParams.set("view", value);
setSearchParams(searchParams);
}
return (
<span aria-label={t("shared.viewMode")} className={clsx("relative z-0 inline-flex rounded-md shadow-2xs", className)} role="group">
<button
aria-label={t("shared.tableView")}
aria-pressed={view === "table"}
onClick={() => onChange("table")}
type="button"
className={clsx(
"border-border-default focus:border-brand-brand-border-solid-default focus:shadow-focus hover:bg-surface-neutral-secondary/90 relative inline-flex items-center rounded-l-md border px-4 py-2.5 font-medium focus:z-10 focus:outline-hidden sm:text-sm",
view === "table" ? "bg-accent-100 text-accent-500" : "bg-surface-neutral-primary text-text-neutral-primary/80"
)}
>
<span aria-hidden="true">
<TableIcon className="h-4 w-4" />
</span>
</button>
<button
aria-label={t("shared.boardView")}
aria-pressed={view === "board"}
onClick={() => onChange("board")}
type="button"
className={clsx(
"border-border-default focus:border-brand-brand-border-solid-default focus:shadow-focus hover:bg-surface-neutral-secondary/90 relative -ml-px inline-flex items-center rounded-r-md border px-4 py-2.5 text-sm font-medium focus:z-10 focus:outline-hidden",
view === "board" ? "bg-accent-100 text-accent-500" : "bg-surface-neutral-primary text-text-neutral-primary/80"
)}
>
<span aria-hidden="true">
<ViewBoardsIcon className="h-4 w-4" />
</span>
</button>
</span>
);
}