refactor: Blueprint UI — catalog-based field selection

Replace manual field definition with a visual field catalog where admins
toggle available attributes on/off and set defaults inline.

New files:
- blueprint-field-catalog.ts: 36 pre-defined fields across 7 categories
  (Client & Billing, Technical Specs, Scope, Person Info, Organization,
  Contract, Skills & Work) for both PROJECT and RESOURCE targets
- FieldCard.tsx: toggle card with type icon, expandable default value
  editor, required/show-in-list toggles, helper text
- BlueprintFieldCatalog.tsx: main catalog modal with category sidebar,
  search bar, collapsible sections, custom field support

UX improvements:
- All standard fields pre-defined — users toggle instead of typing
- Default values set inline on each card (type-appropriate inputs)
- Fields grouped by category with enable counts
- Search/filter to find fields quickly
- Custom fields still supported via "Add Custom Field"
- Full backward compatibility: existing fieldDefs auto-map to catalog

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-22 19:25:08 +01:00
parent da984da470
commit 5d9f4218a0
4 changed files with 1689 additions and 2 deletions
@@ -0,0 +1,786 @@
"use client";
import { useState, useMemo, useCallback } from "react";
import { FieldType } from "@planarchy/shared";
import type { BlueprintFieldDefinition, FieldOption, StaffingRequirement } from "@planarchy/shared";
import { trpc } from "~/lib/trpc/client.js";
import { RolePresetsEditor } from "./RolePresetsEditor.js";
import { FieldCard } from "./FieldCard.js";
import type { FieldOverrides } from "./FieldCard.js";
import {
getCatalogForTarget,
getCategoriesForTarget,
findCatalogField,
} from "~/lib/blueprint-field-catalog.js";
import type { CatalogField } from "~/lib/blueprint-field-catalog.js";
// ---------------------------------------------------------------------------
// Styles
// ---------------------------------------------------------------------------
const INPUT_CLS =
"px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-500 text-sm";
const BTN_PRIMARY =
"px-4 py-2 bg-brand-600 text-white rounded-lg hover:bg-brand-700 text-sm font-medium disabled:opacity-50";
const BTN_SECONDARY =
"px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 text-sm font-medium";
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
type BlueprintTargetValue = "RESOURCE" | "PROJECT";
/** Internal state for a field: catalog index or custom definition */
interface FieldState {
/** Catalog key (undefined for custom fields) */
catalogKey: string | undefined;
overrides: FieldOverrides;
/** For custom fields only */
custom?: {
key: string;
label: string;
type: FieldType;
options: FieldOption[];
};
}
// ---------------------------------------------------------------------------
// Helpers: Convert between FieldState and BlueprintFieldDefinition
// ---------------------------------------------------------------------------
function fieldDefToState(
def: BlueprintFieldDefinition,
target: BlueprintTargetValue,
): FieldState {
const catalogField = findCatalogField(target, def.key);
if (catalogField) {
return {
catalogKey: catalogField.key,
overrides: {
enabled: true,
required: def.required,
showInList: def.showInList ?? false,
defaultValue: def.defaultValue,
description: def.description ?? "",
},
};
}
// Custom field -- not in catalog
return {
catalogKey: undefined,
overrides: {
enabled: true,
required: def.required,
showInList: def.showInList ?? false,
defaultValue: def.defaultValue,
description: def.description ?? "",
},
custom: {
key: def.key,
label: def.label,
type: def.type,
options: def.options ?? [],
},
};
}
function stateToFieldDef(
state: FieldState,
order: number,
target: BlueprintTargetValue,
): BlueprintFieldDefinition | null {
if (!state.overrides.enabled) return null;
if (state.catalogKey) {
const catalogField = findCatalogField(target, state.catalogKey);
if (!catalogField) return null;
const desc = state.overrides.description || catalogField.description;
return {
id: catalogField.key,
key: catalogField.key,
label: catalogField.label,
type: catalogField.type,
required: state.overrides.required,
order,
...(state.overrides.showInList ? { showInList: true } : {}),
...(desc ? { description: desc } : {}),
defaultValue: state.overrides.defaultValue,
...(catalogField.options ? { options: catalogField.options } : {}),
};
}
// Custom field
if (!state.custom) return null;
const customDesc = state.overrides.description || undefined;
return {
id: state.custom.key,
key: state.custom.key,
label: state.custom.label,
type: state.custom.type,
required: state.overrides.required,
order,
...(state.overrides.showInList ? { showInList: true } : {}),
...(customDesc !== undefined ? { description: customDesc } : {}),
defaultValue: state.overrides.defaultValue,
...(state.custom.options.length > 0 ? { options: state.custom.options } : {}),
};
}
// ---------------------------------------------------------------------------
// Props
// ---------------------------------------------------------------------------
interface BlueprintFieldCatalogProps {
blueprintId: string;
blueprintName: string;
blueprintTarget: BlueprintTargetValue;
initialFieldDefs: BlueprintFieldDefinition[];
initialRolePresets?: StaffingRequirement[];
initialTab?: "fields" | "presets";
onClose: () => void;
}
// ---------------------------------------------------------------------------
// Component
// ---------------------------------------------------------------------------
const FIELD_TYPES: { value: FieldType; label: string }[] = [
{ value: FieldType.TEXT, label: "Text" },
{ value: FieldType.TEXTAREA, label: "Textarea" },
{ value: FieldType.NUMBER, label: "Number" },
{ value: FieldType.BOOLEAN, label: "Boolean" },
{ value: FieldType.DATE, label: "Date" },
{ value: FieldType.SELECT, label: "Select" },
{ value: FieldType.MULTI_SELECT, label: "Multi-Select" },
{ value: FieldType.URL, label: "URL" },
{ value: FieldType.EMAIL, label: "Email" },
];
export function BlueprintFieldCatalog({
blueprintId,
blueprintName,
blueprintTarget,
initialFieldDefs,
initialRolePresets = [],
initialTab = "fields",
onClose,
}: BlueprintFieldCatalogProps) {
const utils = trpc.useUtils();
const [activeTab, setActiveTab] = useState<"fields" | "presets">(initialTab);
const [searchQuery, setSearchQuery] = useState("");
const [activeCategory, setActiveCategory] = useState<string | null>(null);
const [saveError, setSaveError] = useState<string | null>(null);
const [presetSaveError, setPresetSaveError] = useState<string | null>(null);
// -- Custom field form state --
const [showCustomForm, setShowCustomForm] = useState(false);
const [customKey, setCustomKey] = useState("");
const [customLabel, setCustomLabel] = useState("");
const [customType, setCustomType] = useState<FieldType>(FieldType.TEXT);
const catalog = useMemo(() => getCatalogForTarget(blueprintTarget), [blueprintTarget]);
const categories = useMemo(() => getCategoriesForTarget(blueprintTarget), [blueprintTarget]);
// ---------------------------------------------------------------------------
// Build initial state from existing fieldDefs + catalog
// ---------------------------------------------------------------------------
const [catalogOverrides, setCatalogOverrides] = useState<
Record<string, FieldOverrides>
>(() => {
const map: Record<string, FieldOverrides> = {};
// Start with all catalog fields disabled
for (const cf of catalog) {
map[cf.key] = {
enabled: false,
required: false,
showInList: false,
defaultValue: cf.defaultValue,
description: "",
};
}
// Override from existing fieldDefs
for (const def of initialFieldDefs) {
const state = fieldDefToState(def, blueprintTarget);
if (state.catalogKey && map[state.catalogKey]) {
map[state.catalogKey] = state.overrides;
}
}
return map;
});
const [customFields, setCustomFields] = useState<FieldState[]>(() => {
return initialFieldDefs
.map((def) => fieldDefToState(def, blueprintTarget))
.filter((s) => !s.catalogKey);
});
// ---------------------------------------------------------------------------
// Mutations
// ---------------------------------------------------------------------------
const updateMutation = trpc.blueprint.update.useMutation();
const presetMutation = trpc.blueprint.updateRolePresets.useMutation();
// ---------------------------------------------------------------------------
// Derived data
// ---------------------------------------------------------------------------
const allCategoryNames = useMemo(
() => [...categories.map((c) => c.name), "Custom Fields"],
[categories],
);
const filteredCatalog = useMemo(() => {
if (!searchQuery.trim()) return catalog;
const q = searchQuery.toLowerCase();
return catalog.filter(
(f) =>
f.label.toLowerCase().includes(q) ||
f.key.toLowerCase().includes(q) ||
f.description.toLowerCase().includes(q) ||
f.category.toLowerCase().includes(q),
);
}, [catalog, searchQuery]);
const fieldsByCategory = useMemo(() => {
const map = new Map<string, CatalogField[]>();
for (const cat of categories) {
map.set(cat.name, []);
}
for (const f of filteredCatalog) {
const list = map.get(f.category);
if (list) list.push(f);
}
return map;
}, [filteredCatalog, categories]);
const enabledCount = useMemo(() => {
let count = 0;
for (const ov of Object.values(catalogOverrides)) {
if (ov.enabled) count++;
}
count += customFields.filter((f) => f.overrides.enabled).length;
return count;
}, [catalogOverrides, customFields]);
// ---------------------------------------------------------------------------
// Handlers
// ---------------------------------------------------------------------------
const handleCatalogFieldChange = useCallback(
(key: string, overrides: FieldOverrides) => {
setCatalogOverrides((prev) => ({ ...prev, [key]: overrides }));
},
[],
);
const handleCustomFieldChange = useCallback(
(idx: number, overrides: FieldOverrides) => {
setCustomFields((prev) =>
prev.map((f, i) => (i === idx ? { ...f, overrides } : f)),
);
},
[],
);
function removeCustomField(idx: number) {
setCustomFields((prev) => prev.filter((_, i) => i !== idx));
}
function addCustomField() {
if (!customKey.trim() || !customLabel.trim()) return;
// Check for duplicate key
const allKeys = new Set([
...catalog.map((f) => f.key),
...customFields.map((f) => f.custom?.key).filter(Boolean),
]);
if (allKeys.has(customKey.trim())) return;
setCustomFields((prev) => [
...prev,
{
catalogKey: undefined,
overrides: {
enabled: true,
required: false,
showInList: false,
defaultValue: undefined,
description: "",
},
custom: {
key: customKey.trim(),
label: customLabel.trim(),
type: customType,
options: [],
},
},
]);
setCustomKey("");
setCustomLabel("");
setCustomType(FieldType.TEXT);
setShowCustomForm(false);
}
function handleSave() {
setSaveError(null);
const defs: BlueprintFieldDefinition[] = [];
let order = 0;
// Catalog fields first (in catalog order)
for (const cf of catalog) {
const ov = catalogOverrides[cf.key];
if (!ov?.enabled) continue;
const state: FieldState = { catalogKey: cf.key, overrides: ov };
const def = stateToFieldDef(state, order, blueprintTarget);
if (def) {
defs.push(def);
order++;
}
}
// Custom fields
for (const cf of customFields) {
if (!cf.overrides.enabled) continue;
const def = stateToFieldDef(cf, order, blueprintTarget);
if (def) {
defs.push(def);
order++;
}
}
updateMutation.mutate(
{ id: blueprintId, data: { fieldDefs: defs } },
{
onSuccess: async () => {
await utils.blueprint.list.invalidate();
onClose();
},
onError: (err) => setSaveError(err.message),
},
);
}
function handleBackdropClick(e: React.MouseEvent<HTMLDivElement>) {
if (e.target === e.currentTarget) onClose();
}
// ---------------------------------------------------------------------------
// Collapsed categories
// ---------------------------------------------------------------------------
const [collapsedCategories, setCollapsedCategories] = useState<Set<string>>(
new Set(),
);
function toggleCategory(name: string) {
setCollapsedCategories((prev) => {
const next = new Set(prev);
if (next.has(name)) next.delete(name);
else next.add(name);
return next;
});
}
// ---------------------------------------------------------------------------
// Render
// ---------------------------------------------------------------------------
return (
<div
className="fixed inset-0 bg-black/50 z-50 flex items-start justify-center overflow-y-auto py-8"
onClick={handleBackdropClick}
>
<div className="bg-white rounded-xl shadow-2xl w-full max-w-4xl mx-4 flex flex-col max-h-[90vh]">
{/* Header */}
<div className="flex items-center justify-between px-6 py-4 border-b border-gray-200 shrink-0">
<div>
<h2 className="text-lg font-semibold text-gray-900">
Configure Fields:{" "}
<span className="text-gray-600 font-normal">{blueprintName}</span>
</h2>
<p className="text-xs text-gray-400 mt-0.5">
{enabledCount} field{enabledCount !== 1 ? "s" : ""} enabled
</p>
</div>
<button
type="button"
onClick={onClose}
className="text-gray-400 hover:text-gray-600 text-2xl leading-none"
aria-label="Close"
>
x
</button>
</div>
{/* Tabs */}
<div className="flex border-b border-gray-200 px-6 shrink-0">
{(["fields", "presets"] as const).map((tab) => (
<button
key={tab}
type="button"
onClick={() => setActiveTab(tab)}
className={`px-4 py-2.5 text-sm font-medium border-b-2 -mb-px transition-colors ${
activeTab === tab
? "border-brand-500 text-brand-600"
: "border-transparent text-gray-500 hover:text-gray-700"
}`}
>
{tab === "fields" ? "Fields" : "Role Presets"}
</button>
))}
</div>
{activeTab === "fields" ? (
<>
{/* Search + category sidebar layout */}
<div className="flex flex-1 overflow-hidden">
{/* Category sidebar */}
<div className="w-48 shrink-0 border-r border-gray-200 bg-gray-50/50 overflow-y-auto hidden md:block">
<nav className="py-2">
<button
type="button"
onClick={() => setActiveCategory(null)}
className={`w-full text-left px-4 py-2 text-sm transition-colors ${
activeCategory === null
? "bg-brand-50 text-brand-700 font-medium"
: "text-gray-600 hover:bg-gray-100"
}`}
>
All Fields
</button>
{allCategoryNames.map((name) => {
const catCount =
name === "Custom Fields"
? customFields.length
: (fieldsByCategory.get(name)?.length ?? 0);
const enabledInCat =
name === "Custom Fields"
? customFields.filter((f) => f.overrides.enabled).length
: (fieldsByCategory.get(name) ?? []).filter(
(f) => catalogOverrides[f.key]?.enabled,
).length;
return (
<button
key={name}
type="button"
onClick={() => setActiveCategory(name)}
className={`w-full text-left px-4 py-2 text-sm transition-colors ${
activeCategory === name
? "bg-brand-50 text-brand-700 font-medium"
: "text-gray-600 hover:bg-gray-100"
}`}
>
<span className="truncate block">{name}</span>
{catCount > 0 && (
<span className="text-xs text-gray-400">
{enabledInCat}/{catCount}
</span>
)}
</button>
);
})}
</nav>
</div>
{/* Main content */}
<div className="flex-1 flex flex-col overflow-hidden">
{/* Search bar */}
<div className="px-4 py-3 border-b border-gray-100 shrink-0">
<input
type="text"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
placeholder="Search fields..."
className={`${INPUT_CLS} w-full`}
autoFocus
/>
</div>
{/* Field cards */}
<div className="flex-1 overflow-y-auto px-4 py-4 space-y-6">
{categories
.filter(
(cat) =>
activeCategory === null ||
activeCategory === cat.name,
)
.map((cat) => {
const fields = fieldsByCategory.get(cat.name) ?? [];
if (fields.length === 0 && searchQuery.trim()) return null;
if (fields.length === 0 && activeCategory !== null && activeCategory !== cat.name) return null;
const isCollapsed = collapsedCategories.has(cat.name);
return (
<div key={cat.name}>
<button
type="button"
onClick={() => toggleCategory(cat.name)}
className="flex items-center gap-2 mb-3 w-full text-left group"
>
<span className="text-xs text-gray-400 transition-transform group-hover:text-gray-600">
{isCollapsed ? "\u25B6" : "\u25BC"}
</span>
<h3 className="text-sm font-semibold text-gray-700 uppercase tracking-wider">
{cat.name}
</h3>
<span className="text-xs text-gray-400">
{cat.description}
</span>
</button>
{!isCollapsed && (
<div className="grid grid-cols-1 gap-2">
{fields.map((field) => (
<FieldCard
key={field.key}
field={field}
overrides={catalogOverrides[field.key]!}
onChange={(ov) =>
handleCatalogFieldChange(field.key, ov)
}
/>
))}
{fields.length === 0 && (
<p className="text-sm text-gray-400 py-2">
No fields in this category.
</p>
)}
</div>
)}
</div>
);
})}
{/* Custom Fields section */}
{(activeCategory === null ||
activeCategory === "Custom Fields") && (
<div>
<button
type="button"
onClick={() => toggleCategory("Custom Fields")}
className="flex items-center gap-2 mb-3 w-full text-left group"
>
<span className="text-xs text-gray-400 transition-transform group-hover:text-gray-600">
{collapsedCategories.has("Custom Fields")
? "\u25B6"
: "\u25BC"}
</span>
<h3 className="text-sm font-semibold text-gray-700 uppercase tracking-wider">
Custom Fields
</h3>
<span className="text-xs text-gray-400">
User-defined fields not in the catalog
</span>
</button>
{!collapsedCategories.has("Custom Fields") && (
<div className="space-y-2">
{customFields.map((cf, idx) => {
if (!cf.custom) return null;
// Build a pseudo CatalogField for the FieldCard
const pseudoCatalog: CatalogField = {
key: cf.custom.key,
label: cf.custom.label,
type: cf.custom.type,
category: "Custom Fields",
description:
cf.overrides.description || "Custom field",
...(cf.custom.options.length > 0
? { options: cf.custom.options }
: {}),
builtIn: false,
};
return (
<div key={cf.custom.key} className="relative">
<FieldCard
field={pseudoCatalog}
overrides={cf.overrides}
onChange={(ov) =>
handleCustomFieldChange(idx, ov)
}
/>
<button
type="button"
onClick={() => removeCustomField(idx)}
className="absolute top-3 right-14 text-xs text-red-400 hover:text-red-600"
title="Remove custom field"
>
Remove
</button>
</div>
);
})}
{/* Add custom field */}
{showCustomForm ? (
<div className="border border-dashed border-gray-300 rounded-lg p-4 space-y-3 bg-gray-50/50">
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-gray-600">
Key{" "}
<span className="text-red-500">*</span>
</label>
<input
type="text"
value={customKey}
onChange={(e) =>
setCustomKey(
e.target.value.replace(
/[^a-zA-Z0-9_]/g,
"",
),
)
}
placeholder="field_key"
className={`${INPUT_CLS} font-mono`}
/>
</div>
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-gray-600">
Label{" "}
<span className="text-red-500">*</span>
</label>
<input
type="text"
value={customLabel}
onChange={(e) =>
setCustomLabel(e.target.value)
}
placeholder="Display Label"
className={INPUT_CLS}
/>
</div>
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-gray-600">
Type
</label>
<select
value={customType}
onChange={(e) =>
setCustomType(
e.target.value as FieldType,
)
}
className={INPUT_CLS}
>
{FIELD_TYPES.map((ft) => (
<option key={ft.value} value={ft.value}>
{ft.label}
</option>
))}
</select>
</div>
</div>
<div className="flex items-center gap-2">
<button
type="button"
onClick={addCustomField}
disabled={
!customKey.trim() || !customLabel.trim()
}
className={BTN_PRIMARY}
>
Add
</button>
<button
type="button"
onClick={() => {
setShowCustomForm(false);
setCustomKey("");
setCustomLabel("");
setCustomType(FieldType.TEXT);
}}
className={BTN_SECONDARY}
>
Cancel
</button>
</div>
</div>
) : (
<button
type="button"
onClick={() => setShowCustomForm(true)}
className="flex items-center gap-1.5 text-sm text-brand-600 hover:text-brand-800 font-medium py-2"
>
<span className="text-lg leading-none">+</span>{" "}
Add Custom Field
</button>
)}
</div>
)}
</div>
)}
</div>
</div>
</div>
{/* Error */}
{saveError && (
<div className="mx-6 mb-2 px-3 py-2 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700 shrink-0">
{saveError}
</div>
)}
{/* Footer */}
<div className="flex items-center justify-between gap-3 px-6 py-4 border-t border-gray-200 shrink-0">
<span className="text-xs text-gray-400">
{enabledCount} field{enabledCount !== 1 ? "s" : ""} will be
saved
</span>
<div className="flex items-center gap-3">
<button type="button" onClick={onClose} className={BTN_SECONDARY}>
Cancel
</button>
<button
type="button"
onClick={handleSave}
disabled={updateMutation.isPending}
className={BTN_PRIMARY}
>
{updateMutation.isPending ? "Saving..." : "Save Fields"}
</button>
</div>
</div>
</>
) : (
<div className="px-6 py-4 overflow-y-auto">
<p className="text-xs text-gray-500 mb-4">
Role presets are auto-loaded in Step 3 of the Project Creation
Wizard when this blueprint is selected.
</p>
<RolePresetsEditor
initialPresets={initialRolePresets}
onSave={(presets) =>
presetMutation.mutate(
{ id: blueprintId, rolePresets: presets },
{
onSuccess: async () => {
await utils.blueprint.list.invalidate();
setPresetSaveError(null);
onClose();
},
onError: (err) => {
setPresetSaveError(err.message);
},
},
)
}
isSaving={presetMutation.isPending}
saveError={presetSaveError}
/>
<div className="flex justify-start mt-4 border-t border-gray-200 pt-4">
<button type="button" onClick={onClose} className={BTN_SECONDARY}>
Close
</button>
</div>
</div>
)}
</div>
</div>
);
}
@@ -5,7 +5,7 @@ import type { FormEvent, MouseEvent } from "react";
import { BlueprintTarget } from "@planarchy/shared";
import type { BlueprintFieldDefinition } from "@planarchy/shared";
import { trpc } from "~/lib/trpc/client.js";
import { BlueprintFieldEditor } from "./BlueprintFieldEditor.js";
import { BlueprintFieldCatalog } from "./BlueprintFieldCatalog.js";
import { useSelection } from "~/hooks/useSelection.js";
import { BatchActionBar } from "~/components/ui/BatchActionBar.js";
import { ConfirmDialog } from "~/components/ui/ConfirmDialog.js";
@@ -496,9 +496,10 @@ export function BlueprintsClient() {
)}
{editingBlueprint && (
<BlueprintFieldEditor
<BlueprintFieldCatalog
blueprintId={editingBlueprint.id}
blueprintName={editingBlueprint.name}
blueprintTarget={editingBlueprint.target}
initialFieldDefs={Array.isArray(editingBlueprint.fieldDefs) ? (editingBlueprint.fieldDefs as BlueprintFieldDefinition[]) : []}
initialRolePresets={Array.isArray(editingBlueprint.rolePresets) ? (editingBlueprint.rolePresets as import("@planarchy/shared").StaffingRequirement[]) : []}
initialTab={editingTab}
@@ -0,0 +1,383 @@
"use client";
import { useState } from "react";
import { FieldType } from "@planarchy/shared";
import type { FieldOption } from "@planarchy/shared";
import type { CatalogField } from "~/lib/blueprint-field-catalog.js";
// ---------------------------------------------------------------------------
// Type icons
// ---------------------------------------------------------------------------
const TYPE_ICONS: Record<FieldType, string> = {
[FieldType.TEXT]: "Aa",
[FieldType.TEXTAREA]: "Aa",
[FieldType.NUMBER]: "#",
[FieldType.BOOLEAN]: "\u2611",
[FieldType.DATE]: "\u{1F4C5}",
[FieldType.SELECT]: "\u25BC",
[FieldType.MULTI_SELECT]: "\u25BC\u25BC",
[FieldType.URL]: "\u{1F517}",
[FieldType.EMAIL]: "@",
};
const TYPE_LABELS: Record<FieldType, string> = {
[FieldType.TEXT]: "Text",
[FieldType.TEXTAREA]: "Textarea",
[FieldType.NUMBER]: "Number",
[FieldType.BOOLEAN]: "Boolean",
[FieldType.DATE]: "Date",
[FieldType.SELECT]: "Select",
[FieldType.MULTI_SELECT]: "Multi-Select",
[FieldType.URL]: "URL",
[FieldType.EMAIL]: "Email",
};
// ---------------------------------------------------------------------------
// Field overrides that the user can set per-field
// ---------------------------------------------------------------------------
export interface FieldOverrides {
enabled: boolean;
required: boolean;
showInList: boolean;
defaultValue: unknown;
description: string;
}
// ---------------------------------------------------------------------------
// Props
// ---------------------------------------------------------------------------
interface FieldCardProps {
field: CatalogField;
overrides: FieldOverrides;
onChange: (overrides: FieldOverrides) => void;
}
// ---------------------------------------------------------------------------
// Component
// ---------------------------------------------------------------------------
const INPUT_CLS =
"px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-brand-500 text-sm";
export function FieldCard({ field, overrides, onChange }: FieldCardProps) {
const [expanded, setExpanded] = useState(false);
function update(patch: Partial<FieldOverrides>) {
onChange({ ...overrides, ...patch });
}
function handleToggle() {
const next = !overrides.enabled;
update({ enabled: next });
if (!next) {
setExpanded(false);
}
}
const isActive = overrides.enabled;
return (
<div
className={`border rounded-lg transition-all ${
isActive
? "border-brand-300 bg-brand-50/40 shadow-sm"
: "border-gray-200 bg-white"
}`}
>
{/* Header row */}
<div
className="flex items-center gap-3 px-4 py-3 cursor-pointer select-none"
onClick={() => {
if (isActive) setExpanded((v) => !v);
else handleToggle();
}}
>
{/* Type icon */}
<span
className={`w-8 h-8 rounded-md flex items-center justify-center text-sm font-bold shrink-0 ${
isActive
? "bg-brand-100 text-brand-700"
: "bg-gray-100 text-gray-400"
}`}
title={TYPE_LABELS[field.type]}
>
{TYPE_ICONS[field.type]}
</span>
{/* Label + description */}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span
className={`font-medium text-sm truncate ${
isActive ? "text-gray-900" : "text-gray-500"
}`}
>
{field.label}
</span>
<span className="text-xs text-gray-400 font-mono hidden sm:inline">
{field.key}
</span>
</div>
<p className="text-xs text-gray-400 truncate">{field.description}</p>
</div>
{/* Toggle switch */}
<button
type="button"
role="switch"
aria-checked={isActive}
aria-label={`Toggle ${field.label}`}
onClick={(e) => {
e.stopPropagation();
handleToggle();
}}
className={`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2 ${
isActive ? "bg-brand-600" : "bg-gray-300"
}`}
>
<span
className={`inline-block h-5 w-5 rounded-full bg-white shadow-sm transform transition-transform duration-200 ${
isActive ? "translate-x-5" : "translate-x-0"
}`}
/>
</button>
</div>
{/* Expanded settings */}
{isActive && expanded && (
<div className="px-4 pb-4 pt-1 border-t border-brand-200/50 space-y-3">
{/* Default value input */}
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-gray-600">
Default Value
</label>
<DefaultValueInput
type={field.type}
{...(field.options ? { options: field.options } : {})}
value={overrides.defaultValue}
onChange={(val) => update({ defaultValue: val })}
/>
</div>
{/* Toggles row */}
<div className="flex flex-wrap items-center gap-4">
<label className="flex items-center gap-1.5 text-sm text-gray-700 cursor-pointer select-none">
<input
type="checkbox"
checked={overrides.required}
onChange={(e) => update({ required: e.target.checked })}
className="w-4 h-4 rounded border-gray-300 text-brand-600 focus:ring-brand-500"
/>
Required
</label>
<label className="flex items-center gap-1.5 text-sm text-gray-700 cursor-pointer select-none">
<input
type="checkbox"
checked={overrides.showInList}
onChange={(e) => update({ showInList: e.target.checked })}
className="w-4 h-4 rounded border-gray-300 text-brand-600 focus:ring-brand-500"
/>
Show in list
</label>
</div>
{/* Description override */}
<div className="flex flex-col gap-1">
<label className="text-xs font-medium text-gray-600">
Helper Text
</label>
<input
type="text"
value={overrides.description}
onChange={(e) => update({ description: e.target.value })}
placeholder={field.description}
className={INPUT_CLS}
/>
</div>
</div>
)}
</div>
);
}
// ---------------------------------------------------------------------------
// Type-appropriate default value input
// ---------------------------------------------------------------------------
function DefaultValueInput({
type,
options,
value,
onChange,
}: {
type: FieldType;
options?: FieldOption[];
value: unknown;
onChange: (val: unknown) => void;
}) {
switch (type) {
case FieldType.BOOLEAN:
return (
<label className="flex items-center gap-2 text-sm text-gray-700 cursor-pointer select-none">
<input
type="checkbox"
checked={Boolean(value)}
onChange={(e) => onChange(e.target.checked)}
className="w-4 h-4 rounded border-gray-300 text-brand-600 focus:ring-brand-500"
/>
{value ? "True" : "False"}
</label>
);
case FieldType.NUMBER:
return (
<input
type="number"
value={value != null ? String(value) : ""}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : Number(e.target.value))
}
placeholder="No default"
className={INPUT_CLS}
/>
);
case FieldType.DATE:
return (
<input
type="date"
value={typeof value === "string" ? value : ""}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : e.target.value)
}
className={INPUT_CLS}
/>
);
case FieldType.SELECT:
return (
<select
value={typeof value === "string" ? value : ""}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : e.target.value)
}
className={INPUT_CLS}
>
<option value="">No default</option>
{(options ?? []).map((opt) => (
<option key={opt.value} value={opt.value}>
{opt.label}
</option>
))}
</select>
);
case FieldType.MULTI_SELECT:
return (
<MultiSelectDefaultInput
options={options ?? []}
value={Array.isArray(value) ? (value as string[]) : []}
onChange={onChange}
/>
);
case FieldType.URL:
return (
<input
type="url"
value={typeof value === "string" ? value : ""}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : e.target.value)
}
placeholder="https://..."
className={INPUT_CLS}
/>
);
case FieldType.EMAIL:
return (
<input
type="email"
value={typeof value === "string" ? value : ""}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : e.target.value)
}
placeholder="name@example.com"
className={INPUT_CLS}
/>
);
case FieldType.TEXTAREA:
return (
<textarea
value={typeof value === "string" ? value : ""}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : e.target.value)
}
placeholder="No default"
className={`${INPUT_CLS} resize-none`}
rows={2}
/>
);
default:
return (
<input
type="text"
value={typeof value === "string" ? value : ""}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : e.target.value)
}
placeholder="No default"
className={INPUT_CLS}
/>
);
}
}
// ---------------------------------------------------------------------------
// Multi-select checkboxes for default value
// ---------------------------------------------------------------------------
function MultiSelectDefaultInput({
options,
value,
onChange,
}: {
options: FieldOption[];
value: string[];
onChange: (val: string[]) => void;
}) {
function toggleOption(optValue: string) {
const next = value.includes(optValue)
? value.filter((v) => v !== optValue)
: [...value, optValue];
onChange(next.length > 0 ? next : []);
}
if (options.length === 0) {
return <span className="text-xs text-gray-400">No options defined</span>;
}
return (
<div className="flex flex-wrap gap-2">
{options.map((opt) => (
<label
key={opt.value}
className="flex items-center gap-1.5 text-sm text-gray-700 cursor-pointer select-none"
>
<input
type="checkbox"
checked={value.includes(opt.value)}
onChange={() => toggleOption(opt.value)}
className="w-3.5 h-3.5 rounded border-gray-300 text-brand-600 focus:ring-brand-500"
/>
{opt.label}
</label>
))}
</div>
);
}
+517
View File
@@ -0,0 +1,517 @@
import { FieldType, BlueprintTarget } from "@planarchy/shared";
import type { FieldOption } from "@planarchy/shared";
// ---------------------------------------------------------------------------
// Catalog types
// ---------------------------------------------------------------------------
export interface CatalogField {
key: string;
label: string;
type: FieldType;
category: string;
description: string;
options?: FieldOption[];
defaultValue?: unknown;
/** true = maps to a real model column; false = stored in dynamicFields JSONB */
builtIn: boolean;
}
export interface CatalogCategory {
name: string;
description: string;
}
// ---------------------------------------------------------------------------
// PROJECT catalog
// ---------------------------------------------------------------------------
export const PROJECT_CATEGORIES: CatalogCategory[] = [
{ name: "Client & Billing", description: "Client relationship and billing details" },
{ name: "Technical Specs", description: "Render pipeline and delivery format" },
{ name: "Scope & Delivery", description: "Approval rounds, revision budgets, complexity" },
];
export const PROJECT_FIELD_CATALOG: CatalogField[] = [
// -- Client & Billing --
{
key: "clientUnit",
label: "Client Unit",
type: FieldType.TEXT,
category: "Client & Billing",
description: "Business unit or division of the client",
builtIn: false,
},
{
key: "personHoursSold",
label: "Person-Hours Sold",
type: FieldType.NUMBER,
category: "Client & Billing",
description: "Total billable person-hours sold to the client",
builtIn: false,
},
{
key: "billingModel",
label: "Billing Model",
type: FieldType.SELECT,
category: "Client & Billing",
description: "How the project is billed",
options: [
{ value: "fixed", label: "Fixed Price" },
{ value: "tm", label: "Time & Material" },
{ value: "hybrid", label: "Hybrid" },
],
builtIn: false,
},
{
key: "poNumber",
label: "PO Number",
type: FieldType.TEXT,
category: "Client & Billing",
description: "Purchase order reference number",
builtIn: false,
},
{
key: "invoiceCycle",
label: "Invoice Cycle",
type: FieldType.SELECT,
category: "Client & Billing",
description: "How often invoices are sent",
options: [
{ value: "weekly", label: "Weekly" },
{ value: "biweekly", label: "Bi-weekly" },
{ value: "monthly", label: "Monthly" },
{ value: "milestone", label: "Per Milestone" },
{ value: "on_completion", label: "On Completion" },
],
builtIn: false,
},
// -- Technical Specs --
{
key: "renderEngine",
label: "Render Engine",
type: FieldType.SELECT,
category: "Technical Specs",
description: "Primary render engine used",
options: [
{ value: "vray", label: "V-Ray" },
{ value: "arnold", label: "Arnold" },
{ value: "redshift", label: "Redshift" },
{ value: "octane", label: "Octane" },
{ value: "cycles", label: "Cycles" },
{ value: "unreal", label: "Unreal Engine" },
{ value: "unity", label: "Unity" },
{ value: "other", label: "Other" },
],
builtIn: false,
},
{
key: "renderFarm",
label: "Render Farm",
type: FieldType.SELECT,
category: "Technical Specs",
description: "Render farm provider",
options: [
{ value: "internal", label: "Internal" },
{ value: "rebusfarm", label: "RebusFarm" },
{ value: "ranch", label: "Ranch Computing" },
{ value: "garagefarm", label: "GarageFarm" },
{ value: "aws", label: "AWS Deadline" },
{ value: "other", label: "Other" },
],
builtIn: false,
},
{
key: "deliveryFormat",
label: "Delivery Format",
type: FieldType.MULTI_SELECT,
category: "Technical Specs",
description: "Final deliverable formats",
options: [
{ value: "exr", label: "EXR" },
{ value: "png", label: "PNG" },
{ value: "mp4", label: "MP4 (H.264)" },
{ value: "mov_prores", label: "MOV (ProRes)" },
{ value: "tiff", label: "TIFF" },
{ value: "dpx", label: "DPX" },
{ value: "fbx", label: "FBX" },
{ value: "glb", label: "GLB/glTF" },
{ value: "usd", label: "USD" },
],
builtIn: false,
},
{
key: "frameRate",
label: "Frame Rate",
type: FieldType.SELECT,
category: "Technical Specs",
description: "Target frame rate for animation/video",
options: [
{ value: "24", label: "24 fps (Film)" },
{ value: "25", label: "25 fps (PAL)" },
{ value: "30", label: "30 fps (NTSC)" },
{ value: "48", label: "48 fps (HFR)" },
{ value: "60", label: "60 fps" },
],
builtIn: false,
},
{
key: "colorSpace",
label: "Color Space",
type: FieldType.SELECT,
category: "Technical Specs",
description: "Working color space",
options: [
{ value: "srgb", label: "sRGB" },
{ value: "aces", label: "ACES" },
{ value: "rec709", label: "Rec.709" },
{ value: "rec2020", label: "Rec.2020" },
{ value: "display_p3", label: "Display P3" },
{ value: "linear", label: "Linear" },
],
builtIn: false,
},
{
key: "resolution",
label: "Resolution",
type: FieldType.SELECT,
category: "Technical Specs",
description: "Output resolution",
options: [
{ value: "hd", label: "1920x1080 (Full HD)" },
{ value: "2k", label: "2048x1080 (2K)" },
{ value: "qhd", label: "2560x1440 (QHD)" },
{ value: "uhd", label: "3840x2160 (4K UHD)" },
{ value: "4k_dci", label: "4096x2160 (4K DCI)" },
{ value: "8k", label: "7680x4320 (8K)" },
{ value: "custom", label: "Custom" },
],
builtIn: false,
},
// -- Scope & Delivery --
{
key: "clientApprovalRounds",
label: "Client Approval Rounds",
type: FieldType.NUMBER,
category: "Scope & Delivery",
description: "Number of approval rounds included in the scope",
defaultValue: 2,
builtIn: false,
},
{
key: "revisionBudgetHours",
label: "Revision Budget (hours)",
type: FieldType.NUMBER,
category: "Scope & Delivery",
description: "Hours reserved for client-requested revisions",
builtIn: false,
},
{
key: "complexityLevel",
label: "Complexity Level",
type: FieldType.SELECT,
category: "Scope & Delivery",
description: "Overall project complexity assessment",
options: [
{ value: "low", label: "Low" },
{ value: "medium", label: "Medium" },
{ value: "high", label: "High" },
{ value: "very_high", label: "Very High" },
],
builtIn: false,
},
{
key: "shotCount",
label: "Shot Count",
type: FieldType.NUMBER,
category: "Scope & Delivery",
description: "Total number of shots or scenes",
builtIn: false,
},
{
key: "deliveryDate",
label: "Delivery Date",
type: FieldType.DATE,
category: "Scope & Delivery",
description: "Final delivery deadline to the client",
builtIn: false,
},
{
key: "nda",
label: "NDA Required",
type: FieldType.BOOLEAN,
category: "Scope & Delivery",
description: "Whether a non-disclosure agreement is in effect",
defaultValue: false,
builtIn: false,
},
{
key: "projectBrief",
label: "Project Brief URL",
type: FieldType.URL,
category: "Scope & Delivery",
description: "Link to the project brief or scope document",
builtIn: false,
},
];
// ---------------------------------------------------------------------------
// RESOURCE catalog
// ---------------------------------------------------------------------------
export const RESOURCE_CATEGORIES: CatalogCategory[] = [
{ name: "Person Info", description: "Basic employee information" },
{ name: "Organization", description: "Organizational placement and location" },
{ name: "Contract", description: "Contract terms and rates" },
{ name: "Skills & Work", description: "Technical skills and work preferences" },
];
export const RESOURCE_FIELD_CATALOG: CatalogField[] = [
// -- Person Info --
{
key: "nickname",
label: "Nickname",
type: FieldType.TEXT,
category: "Person Info",
description: "Preferred name or nickname",
builtIn: false,
},
{
key: "phone",
label: "Phone Number",
type: FieldType.TEXT,
category: "Person Info",
description: "Business phone number",
builtIn: false,
},
{
key: "personalEmail",
label: "Personal Email",
type: FieldType.EMAIL,
category: "Person Info",
description: "Personal/secondary email address",
builtIn: false,
},
{
key: "linkedInUrl",
label: "LinkedIn Profile",
type: FieldType.URL,
category: "Person Info",
description: "Link to LinkedIn profile",
builtIn: false,
},
{
key: "startDate",
label: "Start Date",
type: FieldType.DATE,
category: "Person Info",
description: "Employment start date",
builtIn: false,
},
// -- Organization --
{
key: "department",
label: "Department",
type: FieldType.TEXT,
category: "Organization",
description: "Department or team name",
builtIn: false,
},
{
key: "costCenter",
label: "Cost Center",
type: FieldType.TEXT,
category: "Organization",
description: "Accounting cost center code",
builtIn: false,
},
{
key: "officeLocation",
label: "Office Location",
type: FieldType.TEXT,
category: "Organization",
description: "Physical office location or site name",
builtIn: false,
},
{
key: "reportingTo",
label: "Reporting To",
type: FieldType.TEXT,
category: "Organization",
description: "Direct manager or supervisor name",
builtIn: false,
},
// -- Contract --
{
key: "contractType",
label: "Contract Type",
type: FieldType.SELECT,
category: "Contract",
description: "Type of employment contract",
options: [
{ value: "permanent", label: "Permanent" },
{ value: "fixed_term", label: "Fixed Term" },
{ value: "freelance", label: "Freelance" },
{ value: "internship", label: "Internship" },
{ value: "working_student", label: "Working Student" },
],
builtIn: false,
},
{
key: "contractEndDate",
label: "Contract End Date",
type: FieldType.DATE,
category: "Contract",
description: "End date for fixed-term contracts",
builtIn: false,
},
{
key: "probationEndDate",
label: "Probation End Date",
type: FieldType.DATE,
category: "Contract",
description: "End of probationary period",
builtIn: false,
},
{
key: "weeklyHours",
label: "Weekly Hours",
type: FieldType.NUMBER,
category: "Contract",
description: "Contracted weekly working hours",
defaultValue: 40,
builtIn: false,
},
// -- Skills & Work --
{
key: "primarySoftware",
label: "Primary Software",
type: FieldType.MULTI_SELECT,
category: "Skills & Work",
description: "Main software tools used",
options: [
{ value: "maya", label: "Maya" },
{ value: "3dsmax", label: "3ds Max" },
{ value: "blender", label: "Blender" },
{ value: "cinema4d", label: "Cinema 4D" },
{ value: "houdini", label: "Houdini" },
{ value: "zbrush", label: "ZBrush" },
{ value: "substance", label: "Substance 3D" },
{ value: "nuke", label: "Nuke" },
{ value: "aftereffects", label: "After Effects" },
{ value: "unreal", label: "Unreal Engine" },
{ value: "unity", label: "Unity" },
{ value: "photoshop", label: "Photoshop" },
],
builtIn: false,
},
{
key: "yearsOfExperience",
label: "Years of Experience",
type: FieldType.NUMBER,
category: "Skills & Work",
description: "Total years of professional experience",
builtIn: false,
},
{
key: "spokenLanguages",
label: "Spoken Languages",
type: FieldType.MULTI_SELECT,
category: "Skills & Work",
description: "Languages the person speaks",
options: [
{ value: "de", label: "German" },
{ value: "en", label: "English" },
{ value: "fr", label: "French" },
{ value: "es", label: "Spanish" },
{ value: "it", label: "Italian" },
{ value: "pt", label: "Portuguese" },
{ value: "zh", label: "Chinese" },
{ value: "ja", label: "Japanese" },
{ value: "ko", label: "Korean" },
{ value: "ru", label: "Russian" },
],
builtIn: false,
},
{
key: "timezone",
label: "Timezone",
type: FieldType.SELECT,
category: "Skills & Work",
description: "Primary working timezone",
options: [
{ value: "Europe/Berlin", label: "CET (Berlin)" },
{ value: "Europe/London", label: "GMT (London)" },
{ value: "America/New_York", label: "EST (New York)" },
{ value: "America/Los_Angeles", label: "PST (Los Angeles)" },
{ value: "Asia/Tokyo", label: "JST (Tokyo)" },
{ value: "Asia/Shanghai", label: "CST (Shanghai)" },
{ value: "Asia/Kolkata", label: "IST (Mumbai)" },
{ value: "Australia/Sydney", label: "AEDT (Sydney)" },
],
builtIn: false,
},
{
key: "remoteEligible",
label: "Remote Eligible",
type: FieldType.BOOLEAN,
category: "Skills & Work",
description: "Whether the person can work remotely",
defaultValue: false,
builtIn: false,
},
{
key: "specialization",
label: "Specialization",
type: FieldType.SELECT,
category: "Skills & Work",
description: "Primary area of specialization",
options: [
{ value: "modeling", label: "3D Modeling" },
{ value: "texturing", label: "Texturing" },
{ value: "rigging", label: "Rigging" },
{ value: "animation", label: "Animation" },
{ value: "lighting", label: "Lighting" },
{ value: "rendering", label: "Rendering" },
{ value: "compositing", label: "Compositing" },
{ value: "fx", label: "FX / Simulation" },
{ value: "concept", label: "Concept Art" },
{ value: "motion_design", label: "Motion Design" },
{ value: "td", label: "Technical Direction" },
{ value: "pipeline", label: "Pipeline / Tools" },
{ value: "generalist", label: "Generalist" },
],
builtIn: false,
},
];
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
/** Return the catalog for a given blueprint target */
export function getCatalogForTarget(target: BlueprintTarget | string): CatalogField[] {
return target === BlueprintTarget.PROJECT
? PROJECT_FIELD_CATALOG
: RESOURCE_FIELD_CATALOG;
}
/** Return the categories for a given blueprint target */
export function getCategoriesForTarget(target: BlueprintTarget | string): CatalogCategory[] {
return target === BlueprintTarget.PROJECT
? PROJECT_CATEGORIES
: RESOURCE_CATEGORIES;
}
/** Look up a catalog field by key */
export function findCatalogField(
target: BlueprintTarget | string,
key: string,
): CatalogField | undefined {
return getCatalogForTarget(target).find((f) => f.key === key);
}