feat(plan): render category colors from DB via --cat-color
Replace 14 hardcoded per-category CSS rules with a single --cat-color custom property set inline on each filled cell button, driven by the DB categories list threaded from PlanWork → PlanGrid → PlanRangeChips. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import { useMemo } from "react";
|
||||
import { GridData, ResolvedCell, planCategoryLabel } from "../lib/queries/plan";
|
||||
import type { CSSProperties } from "react";
|
||||
import {
|
||||
GridData,
|
||||
ResolvedCell,
|
||||
planCategoryLabel,
|
||||
categoryMap,
|
||||
PlanCategory,
|
||||
} from "../lib/queries/plan";
|
||||
import type { Project } from "../lib/queries/projects";
|
||||
import PlanRangeChips from "./PlanRangeChips";
|
||||
|
||||
@@ -7,6 +14,7 @@ interface Props {
|
||||
data: GridData | undefined;
|
||||
canEdit: boolean;
|
||||
projects: Project[];
|
||||
categories: PlanCategory[];
|
||||
// The (userId, date) of the most recent successful mutation. The
|
||||
// matching cell gets a one-shot highlight pulse. `nonce` is part of
|
||||
// the value so back-to-back mutations on the same cell re-trigger
|
||||
@@ -92,10 +100,12 @@ export default function PlanGrid({
|
||||
data,
|
||||
canEdit,
|
||||
projects,
|
||||
categories,
|
||||
pulseKey,
|
||||
onCellClick,
|
||||
}: Props) {
|
||||
const today = useMemo(() => todayIso(), []);
|
||||
const catMap = useMemo(() => categoryMap(categories), [categories]);
|
||||
|
||||
if (!data)
|
||||
return (
|
||||
@@ -206,10 +216,17 @@ export default function PlanGrid({
|
||||
<button
|
||||
type="button"
|
||||
className={cls}
|
||||
style={
|
||||
cell
|
||||
? ({
|
||||
"--cat-color": catMap[cell.category]?.color,
|
||||
} as CSSProperties)
|
||||
: undefined
|
||||
}
|
||||
onClick={() => onCellClick(u.id, date, cell)}
|
||||
aria-label={
|
||||
cell
|
||||
? `${u.full_name}, ${date}, ${planCategoryLabel(cell.category)}`
|
||||
? `${u.full_name}, ${date}, ${planCategoryLabel(cell.category, catMap)}`
|
||||
: isLocked
|
||||
? `${u.full_name}, ${date}, ${past ? "uplynulý den" : "prázdné"} — bez záznamu`
|
||||
: `${u.full_name}, ${date}, prázdné — přidat záznam`
|
||||
@@ -225,6 +242,9 @@ export default function PlanGrid({
|
||||
: null
|
||||
}
|
||||
readonly={!canEdit}
|
||||
categoryLabel={
|
||||
cell ? planCategoryLabel(cell.category, catMap) : ""
|
||||
}
|
||||
/>
|
||||
</button>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user