Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion examples/app-showcase/src/ui/views/task.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,33 @@ export const TaskViews = defineView({
{ field: 'estimate_hours' },
{ field: 'due_date' },
],
rowColor: { field: 'priority' },
// Row colouring by priority. The `colors` map is what does the work:
// `rowColor: { field }` alone parses and publishes clean and colours
// nothing (author-time diagnostic `view/row-color-without-colors`).
//
// The values are COLOUR NAMES, not hex. objectui `plugin-grid`'s
// `useRowColor` resolves each authored value through its own
// `COLOR_TO_CLASS` vocabulary to a literal Tailwind class
// (`red` -> `bg-red-100`), hands a `bg-*` value through untouched, and
// returns `undefined` for everything else — Tailwind v4 has no runtime,
// so a fabricated class string would name no rule in the compiled
// stylesheet. A hex here would clear the resolver's `!config.colors`
// guard, silence the diagnostic above, and still colour no row.
//
// Each name is the entry of that vocabulary nearest to the colour
// `priority` already declares on the option itself (`task.object.ts`):
// #94A3B8 slate, #3B82F6 blue, #F59E0B amber, #EF4444 red. The renderer
// paints the `-100` tint of the name, so the row background stays light
// enough to read the row's own text on.
rowColor: {
field: 'priority',
colors: {
low: 'slate',
medium: 'blue',
high: 'amber',
urgent: 'red',
},
},
// List-level inline edit — cells become editable in place, with a
// per-row edit affordance and a save-all/cancel-all toolbar (view-level
// master switch; distinct from the master-detail `inlineEdit` on fields).
Expand Down
92 changes: 92 additions & 0 deletions examples/app-showcase/test/inert-wirings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { stripComments } from '../../../scripts/js-comment-mask.mjs';
import stack from '../objectstack.config.js';
import { PLATFORM_CAPABILITY_NAMES } from '@objectstack/spec/security';
import { FILE_REFERENCE_TYPES, valueSchemaFor } from '@objectstack/spec/data';
import { VIEW_ROW_COLOR_WITHOUT_COLORS } from '@objectstack/spec/kernel';
// The SHIPPED ADR-0078 completeness gate, never a re-derivation of it —
// `vitest.config.ts` aliases `@objectstack/lint` to its `src/`, so the verdict
// is about the rule in this checkout rather than about `packages/lint/dist`.
import { validateFunctionalCompleteness } from '@objectstack/lint';
// The job handler's argument type, from the package that BUILDS it
// (`AppPlugin`) — not a local re-description of it. A fake context typed to a
// hand-written approximation is how a double drifts looser than the contract it
Expand Down Expand Up @@ -741,3 +746,90 @@ describe('sharing rules target an object under record-sharing enforcement (#9237
).toEqual([]);
});
});

/**
* #15100 — the task Grid view's `rowColor` named a field and declared no
* `colors` map, so objectui `plugin-grid`'s `useRowColor` returned before it
* read a record and every row kept the default background, while the metadata
* parsed, validated and published clean. The same class as every guard above:
* a declaration the platform accepts at authoring time and then does not
* honour, announced only by an advisory line nobody reads.
*
* Two arms, because the wiring has two independent ways to be inert and only
* the first has a shipped rule:
*
* ① NO MAP — the author-time diagnostic `view/row-color-without-colors`
* names it. WARNING severity, so `os validate` prints it and still exits
* 0; a pin asserting "validate succeeds" would have passed on the broken
* tree, so this asserts on the FINDINGS.
*
* ② A MAP THE RENDERER CANNOT RESOLVE — invisible to ①. `colorToClass`
* hands a value that already starts with `bg-` through untouched,
* otherwise looks it up in its own `COLOR_TO_CLASS` vocabulary of colour
* names, and returns `undefined` for anything else; it never fabricates a
* class string, because Tailwind v4 has no runtime and only complete class
* literals present in scanned source reach the compiled stylesheet. So a
* hex — the spelling the `priority` field uses for its own option colours,
* and the obvious thing to copy — clears the `!config.colors` guard,
* silences ①, and still colours no row.
*/
describe("the task Grid's rowColor is wired all the way to a colour (#15100)", () => {
it('reports no `view/row-color-without-colors` finding anywhere in this stack', () => {
const offenders = validateFunctionalCompleteness(stack)
.filter((f) => f.rule === VIEW_ROW_COLOR_WITHOUT_COLORS)
.map((f) => `${f.where} (${f.path})`);
expect(
offenders,
`\`rowColor\` block(s) with no \`colors\` map — the row-className resolver `
+ `returns before it reads a record: ${offenders.join(', ')}`,
).toEqual([]);
});

it('spells every authored colour as a value the renderer can resolve', () => {
// A colour NAME (`red`) or a complete Tailwind class (`bg-red-200`). The
// vocabulary itself is not transcribed here: a hand-copy of another repo's
// 23-entry map is a second opinion that drifts, and the shape rule is what
// separates a resolvable value from a hex.
const RESOLVABLE = /^(?:[a-z]+|bg-[a-z0-9/[\]().,%#-]+)$/;
const offenders: string[] = [];
for (const { path, block } of rowColorBlocks(stack)) {
for (const [value, colour] of Object.entries(block.colors ?? {})) {
if (typeof colour !== 'string' || !RESOLVABLE.test(colour)) {
offenders.push(`${path}.colors.${value} = ${JSON.stringify(colour)}`);
}
}
}
expect(
offenders,
`authored row colour(s) \`colorToClass\` resolves to \`undefined\` — the block passes `
+ `the completeness rule above and still colours no row: ${offenders.join(', ')}`,
).toEqual([]);
});
});

/** Every `rowColor` block anywhere in this app's stack, with where it sits. */
function rowColorBlocks(
root: unknown,
): Array<{ path: string; block: { colors?: Record<string, unknown> } }> {
const out: Array<{ path: string; block: { colors?: Record<string, unknown> } }> = [];
const seen = new WeakSet<object>();
const walk = (node: unknown, path: string): void => {
if (!node || typeof node !== 'object') return;
if (seen.has(node)) return;
seen.add(node);
if (Array.isArray(node)) {
node.forEach((child, i) => walk(child, `${path}[${i}]`));
return;
}
for (const [key, child] of Object.entries(node as Record<string, unknown>)) {
// The BOOLEAN toolbar toggle `userActions.rowColor` shares this key name
// and is a different thing entirely — only an object is the config.
if (key === 'rowColor' && child && typeof child === 'object' && !Array.isArray(child)) {
out.push({ path: `${path}.rowColor`, block: child as { colors?: Record<string, unknown> } });
}
walk(child, `${path}.${key}`);
}
};
walk(root, '$');
return out;
}
Loading