Show the remade card names on template detail, matching final review, and say one size fits all.
This commit is contained in:
1 parent
f634a91bb2
commit
54a4871ad1
4 files changed
+256
-8
No files matched your search
@@ -7,7 +7,7 @@ import type { Category, RuleProps } from "../Rule";
|
|||||||
import { getAssetPath } from "../../../../lib/assetUtils";
|
import { getAssetPath } from "../../../../lib/assetUtils";
|
||||||
import type { RuleTemplateDto } from "../../../../lib/create/fetchTemplates";
|
import type { RuleTemplateDto } from "../../../../lib/create/fetchTemplates";
|
||||||
import {
|
import {
|
||||||
templateBodyToReviewData,
|
templateReviewDataForSlug,
|
||||||
templateSummaryFromBody,
|
templateSummaryFromBody,
|
||||||
} from "../../../../lib/create/templateReviewMapping";
|
} from "../../../../lib/create/templateReviewMapping";
|
||||||
import {
|
import {
|
||||||
@@ -26,9 +26,9 @@ export interface TemplateReviewCardProps {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Expanded Rule for template review: surfaces + icon from Figma catalog (21764-16435);
|
* Expanded Rule for template review: surfaces + icon from Figma catalog (21764-16435);
|
||||||
* tag rows from API `body`. Chip clicks open a read-only detail modal per
|
* tag rows from the remade catalog chips. Chip clicks open a read-only detail
|
||||||
* facet group (values / communication / membership / decision-making / conflict
|
* modal per facet group (values / communication / membership / decision-making /
|
||||||
* management) so reviewers can see what each chip means without editing.
|
* conflict management) so reviewers can see what each chip means without editing.
|
||||||
*/
|
*/
|
||||||
export function TemplateReviewCard({
|
export function TemplateReviewCard({
|
||||||
template,
|
template,
|
||||||
@@ -38,8 +38,8 @@ export function TemplateReviewCard({
|
|||||||
const catalog = getGovernanceTemplateCatalogEntry(template.slug);
|
const catalog = getGovernanceTemplateCatalogEntry(template.slug);
|
||||||
const pres = catalog ?? TEMPLATE_GRID_FALLBACK_PRESENTATION;
|
const pres = catalog ?? TEMPLATE_GRID_FALLBACK_PRESENTATION;
|
||||||
const { categories: rawCategories, chipDetailsByChipId } = useMemo(
|
const { categories: rawCategories, chipDetailsByChipId } = useMemo(
|
||||||
() => templateBodyToReviewData(template.body),
|
() => templateReviewDataForSlug(template.slug, template.body),
|
||||||
[template.body],
|
[template.slug, template.body],
|
||||||
);
|
);
|
||||||
const summary = templateSummaryFromBody(template.description, template.body);
|
const summary = templateSummaryFromBody(template.description, template.body);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import type { Category } from "../../app/components/cards/Rule";
|
import type { Category } from "../../app/components/cards/Rule";
|
||||||
import type { ChipOption } from "../../app/components/controls/MultiSelect/MultiSelect.types";
|
import type { ChipOption } from "../../app/components/controls/MultiSelect/MultiSelect.types";
|
||||||
import type { CommunityRuleSection } from "../../app/components/type/CommunityRule/CommunityRule.types";
|
import type { CommunityRuleSection } from "../../app/components/type/CommunityRule/CommunityRule.types";
|
||||||
|
import coreValuesMessages from "../../messages/en/create/customRule/coreValues.json";
|
||||||
import type { TemplateFacetGroupKey } from "./customRuleFacets";
|
import type { TemplateFacetGroupKey } from "./customRuleFacets";
|
||||||
import { templateCategoryToFacetGroupKey } from "./customRuleFacets";
|
import {
|
||||||
|
readMethodPresetsForFacetGroup,
|
||||||
|
templateCategoryToFacetGroupKey,
|
||||||
|
} from "./customRuleFacets";
|
||||||
import { isDocumentEntry } from "./documentEntryGuards";
|
import { isDocumentEntry } from "./documentEntryGuards";
|
||||||
|
import { templateChipsForSlug, type TemplateChipSet } from "./templatePath";
|
||||||
|
|
||||||
export type { TemplateFacetGroupKey } from "./customRuleFacets";
|
export type { TemplateFacetGroupKey } from "./customRuleFacets";
|
||||||
|
|
||||||
@@ -91,6 +96,134 @@ export function templateBodyToCategories(body: unknown): Category[] {
|
|||||||
return templateBodyToReviewData(body).categories;
|
return templateBodyToReviewData(body).categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ReviewData = ReturnType<typeof templateBodyToReviewData>;
|
||||||
|
|
||||||
|
const CHIP_REVIEW_GROUPS: readonly {
|
||||||
|
groupKey: TemplateFacetGroupKey;
|
||||||
|
categoryName: string;
|
||||||
|
idsOf: (_chips: TemplateChipSet) => readonly string[];
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
groupKey: "coreValues",
|
||||||
|
categoryName: "Values",
|
||||||
|
idsOf: (chips) => chips.coreValues,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
groupKey: "communication",
|
||||||
|
categoryName: "Communication",
|
||||||
|
idsOf: (chips) => chips.communication,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
groupKey: "membership",
|
||||||
|
categoryName: "Membership",
|
||||||
|
idsOf: (chips) => chips.membership,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
groupKey: "decisionApproaches",
|
||||||
|
categoryName: "Decision-making",
|
||||||
|
idsOf: (chips) => chips.decisionApproaches,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
groupKey: "conflictManagement",
|
||||||
|
categoryName: "Conflict management",
|
||||||
|
idsOf: (chips) => chips.conflictManagement,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
function coreValueLabelById(id: string): string | null {
|
||||||
|
const values = (coreValuesMessages as { values?: unknown }).values;
|
||||||
|
if (!Array.isArray(values)) return null;
|
||||||
|
for (const raw of values) {
|
||||||
|
if (!raw || typeof raw !== "object") continue;
|
||||||
|
const row = raw as { id?: unknown; label?: unknown };
|
||||||
|
if (row.id === id && typeof row.label === "string" && row.label.trim()) {
|
||||||
|
return row.label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Same order as `coreValuesChipsSnapshot` / final review: catalog list, then leftovers. */
|
||||||
|
function orderedCoreValueIds(ids: readonly string[]): string[] {
|
||||||
|
const wanted = new Set(ids);
|
||||||
|
const out: string[] = [];
|
||||||
|
const values = (coreValuesMessages as { values?: unknown }).values;
|
||||||
|
if (Array.isArray(values)) {
|
||||||
|
for (const raw of values) {
|
||||||
|
if (!raw || typeof raw !== "object") continue;
|
||||||
|
const id = (raw as { id?: unknown }).id;
|
||||||
|
if (typeof id === "string" && wanted.delete(id)) out.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const id of ids) {
|
||||||
|
if (wanted.has(id)) out.push(id);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function methodLabelById(
|
||||||
|
groupKey: Exclude<TemplateFacetGroupKey, "coreValues">,
|
||||||
|
id: string,
|
||||||
|
): string | null {
|
||||||
|
const row = readMethodPresetsForFacetGroup(groupKey).find(
|
||||||
|
(method) => method.id === id,
|
||||||
|
);
|
||||||
|
return row?.label ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function templateChipsToReviewData(slug: string): ReviewData | null {
|
||||||
|
const chips = templateChipsForSlug(slug);
|
||||||
|
if (!chips) return null;
|
||||||
|
|
||||||
|
const categories: Category[] = [];
|
||||||
|
const chipDetailsByChipId: ReviewData["chipDetailsByChipId"] = {};
|
||||||
|
|
||||||
|
for (const group of CHIP_REVIEW_GROUPS) {
|
||||||
|
const chipOptions: ChipOption[] = [];
|
||||||
|
const ids =
|
||||||
|
group.groupKey === "coreValues"
|
||||||
|
? orderedCoreValueIds(group.idsOf(chips))
|
||||||
|
: group.idsOf(chips);
|
||||||
|
for (const id of ids) {
|
||||||
|
const chipLabel =
|
||||||
|
group.groupKey === "coreValues"
|
||||||
|
? coreValueLabelById(id)
|
||||||
|
: methodLabelById(group.groupKey, id);
|
||||||
|
if (!chipLabel) continue;
|
||||||
|
chipDetailsByChipId[id] = {
|
||||||
|
chipId: id,
|
||||||
|
chipLabel,
|
||||||
|
categoryName: group.categoryName,
|
||||||
|
groupKey: group.groupKey,
|
||||||
|
body: "",
|
||||||
|
};
|
||||||
|
chipOptions.push({
|
||||||
|
id,
|
||||||
|
label: chipLabel,
|
||||||
|
state: "unselected",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (chipOptions.length === 0) continue;
|
||||||
|
categories.push({
|
||||||
|
name: group.categoryName,
|
||||||
|
chipOptions,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { categories, chipDetailsByChipId };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detail-page chips. Prefer the remade catalog ids in templateChips.json so
|
||||||
|
* the list matches final review; fall back to API body titles for unknown slugs.
|
||||||
|
*/
|
||||||
|
export function templateReviewDataForSlug(
|
||||||
|
slug: string,
|
||||||
|
body: unknown,
|
||||||
|
): ReviewData {
|
||||||
|
return templateChipsToReviewData(slug) ?? templateBodyToReviewData(body);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Summary line under tag rows: prefer API description; else first entry bodies (short).
|
* Summary line under tag rows: prefer API description; else first entry bodies (short).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"intro": {
|
"intro": {
|
||||||
"title": "CommunityRule Template",
|
"title": "CommunityRule Template",
|
||||||
"description": "These templates can get you started with a proven approach to governance and decision-making. As useful as these templates are, they are not one size fit all solutions though. We recommend that you use them as a starting place for your community to adapt and customize according to your group's specific needs."
|
"description": "These templates can get you started with a proven approach to governance and decision-making. As useful as these templates are, they are not one size fits all solutions though. We recommend that you use them as a starting place for your community to adapt and customize according to your group's specific needs."
|
||||||
},
|
},
|
||||||
"footer": {
|
"footer": {
|
||||||
"useWithoutChanges": "Use without changes",
|
"useWithoutChanges": "Use without changes",
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { buildAppliedTemplateCreateFlowState } from "../../lib/create/applyTemplatePrefill";
|
||||||
|
import { buildFinalReviewCategoriesFromState } from "../../lib/create/buildFinalReviewCategories";
|
||||||
import {
|
import {
|
||||||
templateBodyToCategories,
|
templateBodyToCategories,
|
||||||
templateBodyToReviewData,
|
templateBodyToReviewData,
|
||||||
templateCategoryToGroupKey,
|
templateCategoryToGroupKey,
|
||||||
|
templateReviewDataForSlug,
|
||||||
templateSummaryFromBody,
|
templateSummaryFromBody,
|
||||||
} from "../../lib/create/templateReviewMapping";
|
} from "../../lib/create/templateReviewMapping";
|
||||||
|
import templateChipsFile from "../../data/templates/templateChips.json";
|
||||||
|
import templateReviewMessages from "../../messages/en/create/templateReview.json";
|
||||||
|
|
||||||
describe("templateReviewMapping", () => {
|
describe("templateReviewMapping", () => {
|
||||||
it("maps body sections to Rule categories", () => {
|
it("maps body sections to Rule categories", () => {
|
||||||
@@ -117,3 +122,113 @@ describe("templateReviewMapping", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const FINAL_REVIEW_NAMES = {
|
||||||
|
values: "Values",
|
||||||
|
communication: "Communication",
|
||||||
|
membership: "Membership",
|
||||||
|
decisions: "Decision-making",
|
||||||
|
conflict: "Conflict management",
|
||||||
|
};
|
||||||
|
|
||||||
|
const STALE_CONSENSUS_BODY = {
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
categoryName: "Values",
|
||||||
|
entries: [{ title: "Community Care", body: "" }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
categoryName: "Communication",
|
||||||
|
entries: [
|
||||||
|
{ title: "In-Person Meetings", body: "" },
|
||||||
|
{ title: "Loomio", body: "" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
categoryName: "Membership",
|
||||||
|
entries: [{ title: "Peer Sponsorship", body: "" }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
categoryName: "Decision-making",
|
||||||
|
entries: [
|
||||||
|
{ title: "Consensus or Vote-Based Approval", body: "" },
|
||||||
|
{ title: "Consensus Decision-Making", body: "" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
categoryName: "Conflict management",
|
||||||
|
entries: [{ title: "Facilitated Negotiation", body: "" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("templateReviewDataForSlug", () => {
|
||||||
|
it("lists remade catalog names for consensus, not API body titles", () => {
|
||||||
|
const { categories } = templateReviewDataForSlug(
|
||||||
|
"consensus",
|
||||||
|
STALE_CONSENSUS_BODY,
|
||||||
|
);
|
||||||
|
const labels = categories.flatMap((row) =>
|
||||||
|
row.chipOptions.map((chip) => chip.label),
|
||||||
|
);
|
||||||
|
expect(labels).toContain("How we run meetings");
|
||||||
|
expect(labels).toContain("In-person meetings");
|
||||||
|
expect(labels).toContain("Conflict ladder");
|
||||||
|
expect(labels).toContain("Community care");
|
||||||
|
expect(labels).toContain("Decision speeds");
|
||||||
|
expect(labels).not.toContain("In-Person Meetings");
|
||||||
|
expect(labels).not.toContain("Community Care");
|
||||||
|
expect(labels).not.toContain("Peer Sponsorship");
|
||||||
|
expect(labels).not.toContain("Facilitated Negotiation");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("matches Use without changes final-review labels", () => {
|
||||||
|
const slugs = Object.keys(
|
||||||
|
(templateChipsFile as { templates: Record<string, unknown> }).templates,
|
||||||
|
);
|
||||||
|
for (const slug of slugs) {
|
||||||
|
const detail = templateReviewDataForSlug(slug, STALE_CONSENSUS_BODY);
|
||||||
|
const seeded = buildAppliedTemplateCreateFlowState({
|
||||||
|
slug,
|
||||||
|
body: STALE_CONSENSUS_BODY,
|
||||||
|
mode: "useWithoutChanges",
|
||||||
|
});
|
||||||
|
const review = buildFinalReviewCategoriesFromState(
|
||||||
|
seeded,
|
||||||
|
FINAL_REVIEW_NAMES,
|
||||||
|
);
|
||||||
|
const detailByName = new Map(
|
||||||
|
detail.categories.map((row) => [
|
||||||
|
row.name,
|
||||||
|
row.chipOptions.map((chip) => chip.label),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
for (const row of review) {
|
||||||
|
if (row.chips.length === 0) continue;
|
||||||
|
expect(detailByName.get(row.name), slug).toEqual(row.chips);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to body titles when the slug is not in the catalog", () => {
|
||||||
|
const cats = templateReviewDataForSlug("unknown-template", {
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
categoryName: "Values",
|
||||||
|
entries: [{ title: "Solidarity", body: "Long body" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}).categories;
|
||||||
|
expect(cats[0].chipOptions.map((chip) => chip.label)).toEqual([
|
||||||
|
"Solidarity",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("template review intro", () => {
|
||||||
|
it("reads one size fits all", () => {
|
||||||
|
expect(templateReviewMessages.intro.description).toContain(
|
||||||
|
"one size fits all",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user