Keep every picked card on the finished Rule, and wait for its words before Continue.

This commit is contained in:
adilallo committed 2026-11-22 17:56:38 -07:00
1 parent a846169960
commit a2815ae05f
16 files changed
+417 -114

No files matched your search

@@ -18,7 +18,10 @@ import {
type FinalReviewCategoryRowDetailed, type FinalReviewCategoryRowDetailed,
} from "../../../../../lib/create/buildFinalReviewCategories"; } from "../../../../../lib/create/buildFinalReviewCategories";
import { communityInitialsFromTitle } from "../../../../../lib/create/communityInitials"; import { communityInitialsFromTitle } from "../../../../../lib/create/communityInitials";
import { finalReviewChipHasWarning } from "../../../../../lib/create/finalReviewChipWarnings"; import {
finalReviewChipHasWarning,
finalReviewMissingWordsLabels,
} from "../../../../../lib/create/finalReviewChipWarnings";
import { applyFinalReviewChipEditPatch } from "../../../../../lib/create/applyFinalReviewChipEditPatch"; import { applyFinalReviewChipEditPatch } from "../../../../../lib/create/applyFinalReviewChipEditPatch";
import type { import type {
TemplateChipDetail, TemplateChipDetail,
@@ -234,6 +237,11 @@ export function FinalReviewScreen({
const descriptionEmptyHint = t("communityContextEditModal.emptyHint"); const descriptionEmptyHint = t("communityContextEditModal.emptyHint");
const missingWordsLabels = useMemo(
() => finalReviewMissingWordsLabels(state),
[state],
);
const templatePath = isTemplateCreatePath(state); const templatePath = isTemplateCreatePath(state);
const avatarUpload = useCommunityAvatarUpload(); const avatarUpload = useCommunityAvatarUpload();
const serverAvatarUrl = useCommunityAvatarDisplayUrl(state.communityAvatarUrl); const serverAvatarUrl = useCommunityAvatarDisplayUrl(state.communityAvatarUrl);
@@ -277,6 +285,19 @@ export function FinalReviewScreen({
: t("description") : t("description")
} }
> >
{missingWordsLabels.length > 0 ? (
<Alert
type="banner"
status="warning"
size="m"
title={t("missingWordsWarning.title")}
description={t("missingWordsWarning.description").replace(
"{labels}",
missingWordsLabels.join(", "),
)}
hasTrailingIcon={false}
/>
) : null}
{bindingArbitrationNeedsSeparateYes(state) ? ( {bindingArbitrationNeedsSeparateYes(state) ? (
<Alert <Alert
type="banner" type="banner"
@@ -3,6 +3,7 @@ import {
buildFinalReviewCategoryRowsDetailed, buildFinalReviewCategoryRowsDetailed,
type FinalReviewCategoryNames, type FinalReviewCategoryNames,
} from "../../../../lib/create/buildFinalReviewCategories"; } from "../../../../lib/create/buildFinalReviewCategories";
import { finalReviewChipBlocksContinue } from "../../../../lib/create/finalReviewChipWarnings";
import type { TemplateFacetGroupKey } from "../../../../lib/create/templateReviewMapping"; import type { TemplateFacetGroupKey } from "../../../../lib/create/templateReviewMapping";
import type { CreateFlowState, CreateFlowStep } from "../types"; import type { CreateFlowState, CreateFlowStep } from "../types";
@@ -75,8 +76,9 @@ const FINAL_REVIEW_REQUIRED_GROUPS: readonly TemplateFacetGroupKey[] = [
] as const; ] as const;
/** /**
* Continue on final review waits for a community name and at least one card * Continue on final review waits for a community name, at least one card on
* on each of the four questions. Skipped values do not block. * each of the four questions, every picked card's words, and every picked
* value's meaning. Skipped values and missing signals do not block.
*/ */
export function isFinalReviewContinueBlocked(state: CreateFlowState): boolean { export function isFinalReviewContinueBlocked(state: CreateFlowState): boolean {
const title = typeof state.title === "string" ? state.title.trim() : ""; const title = typeof state.title === "string" ? state.title.trim() : "";
@@ -85,10 +87,16 @@ export function isFinalReviewContinueBlocked(state: CreateFlowState): boolean {
state, state,
FINAL_REVIEW_BLOCK_NAMES, FINAL_REVIEW_BLOCK_NAMES,
); );
return FINAL_REVIEW_REQUIRED_GROUPS.some((groupKey) => { const missingRequiredCard = FINAL_REVIEW_REQUIRED_GROUPS.some((groupKey) => {
const row = rows.find((candidate) => candidate.groupKey === groupKey); const row = rows.find((candidate) => candidate.groupKey === groupKey);
return !row || row.entries.length === 0; return !row || row.entries.length === 0;
}); });
if (missingRequiredCard) return true;
return rows.some((row) =>
row.entries.some((entry) =>
finalReviewChipBlocksContinue(state, entry.groupKey, entry.overrideKey),
),
);
} }
/** /**
+13 -21
View File
@@ -8,11 +8,10 @@ import type {
import type { CommunityRuleSection } from "../../app/components/type/CommunityRule/CommunityRule.types"; import type { CommunityRuleSection } from "../../app/components/type/CommunityRule/CommunityRule.types";
import { resolveMethodPresetIdFromLabel } from "./buildFinalReviewCategories"; import { resolveMethodPresetIdFromLabel } from "./buildFinalReviewCategories";
import { import {
communicationPresetFor, emptyCommunicationDetails,
conflictManagementPresetFor, emptyConflictManagementDetails,
decisionApproachPresetFor, emptyDecisionApproachDetails,
membershipPresetFor, emptyMembershipDetails,
mergeCoreValueDetailWithPresets,
publishedMethodDisplayLabel, publishedMethodDisplayLabel,
} from "./finalReviewChipPresets"; } from "./finalReviewChipPresets";
import { isDocumentEntry } from "./documentEntryGuards"; import { isDocumentEntry } from "./documentEntryGuards";
@@ -61,12 +60,12 @@ export function buildCoreValuesForDocument(state: CreateFlowState): Array<{
return snap return snap
.filter((r) => selected.has(r.id)) .filter((r) => selected.has(r.id))
.map((r) => { .map((r) => {
const merged = mergeCoreValueDetailWithPresets(r.id, r.label, details[r.id]); const saved = details[r.id];
return { return {
chipId: r.id, chipId: r.id,
label: r.label, label: r.label,
meaning: merged.meaning, meaning: typeof saved?.meaning === "string" ? saved.meaning : "",
signals: merged.signals, signals: typeof saved?.signals === "string" ? saved.signals : "",
}; };
}); });
} }
@@ -278,10 +277,8 @@ function publishedRowSupportText(
/** /**
* Merge `selected*MethodIds` with any saved `{group}MethodDetailsById` * Merge `selected*MethodIds` with any saved `{group}MethodDetailsById`
* overrides authored on the final-review screen. Preset defaults from the * overrides authored on the final-review screen. Blank parts stay blank —
* shipped `messages/en/create/customRule/*.json` seed any sub-fields the * library presets are not filled in for text the pen holder never wrote.
* user didn't edit so consumers of `document.methodSelections` always see
* a complete payload per method.
*/ */
export function buildMethodSelectionsForDocument( export function buildMethodSelectionsForDocument(
state: CreateFlowState, state: CreateFlowState,
@@ -297,7 +294,6 @@ export function buildMethodSelectionsForDocument(
); );
if (commIds.length > 0) { if (commIds.length > 0) {
out.communication = commIds.map((id) => { out.communication = commIds.map((id) => {
const preset = communicationPresetFor(id);
const override = state.communicationMethodDetailsById?.[id]; const override = state.communicationMethodDetailsById?.[id];
const supportText = publishedRowSupportText( const supportText = publishedRowSupportText(
id, id,
@@ -310,7 +306,7 @@ export function buildMethodSelectionsForDocument(
id, id,
state.customMethodCardMetaById, state.customMethodCardMetaById,
), ),
sections: override ? { ...preset, ...override } : preset, sections: override ?? emptyCommunicationDetails(),
...(supportText ? { supportText } : {}), ...(supportText ? { supportText } : {}),
}; };
}); });
@@ -322,7 +318,6 @@ export function buildMethodSelectionsForDocument(
); );
if (memIds.length > 0) { if (memIds.length > 0) {
out.membership = memIds.map((id) => { out.membership = memIds.map((id) => {
const preset = membershipPresetFor(id);
const override = state.membershipMethodDetailsById?.[id]; const override = state.membershipMethodDetailsById?.[id];
const supportText = publishedRowSupportText( const supportText = publishedRowSupportText(
id, id,
@@ -335,7 +330,7 @@ export function buildMethodSelectionsForDocument(
id, id,
state.customMethodCardMetaById, state.customMethodCardMetaById,
), ),
sections: override ? { ...preset, ...override } : preset, sections: override ?? emptyMembershipDetails(),
...(supportText ? { supportText } : {}), ...(supportText ? { supportText } : {}),
}; };
}); });
@@ -347,13 +342,11 @@ export function buildMethodSelectionsForDocument(
); );
if (daIds.length > 0) { if (daIds.length > 0) {
out.decisionApproaches = daIds.map((id) => { out.decisionApproaches = daIds.map((id) => {
const preset = decisionApproachPresetFor(id);
const override = state.decisionApproachDetailsById?.[id]; const override = state.decisionApproachDetailsById?.[id];
const supportText = publishedRowSupportText( const supportText = publishedRowSupportText(
id, id,
state.customMethodCardMetaById, state.customMethodCardMetaById,
); );
const merged = override ? { ...preset, ...override } : preset;
return { return {
id, id,
label: publishedMethodDisplayLabel( label: publishedMethodDisplayLabel(
@@ -362,7 +355,7 @@ export function buildMethodSelectionsForDocument(
state.customMethodCardMetaById, state.customMethodCardMetaById,
), ),
sections: withoutUnpublishedDecisionConsensus( sections: withoutUnpublishedDecisionConsensus(
{ ...merged }, { ...(override ?? emptyDecisionApproachDetails()) },
state.customMethodCardFieldBlocksById?.[id], state.customMethodCardFieldBlocksById?.[id],
) as DecisionApproachDetailEntry, ) as DecisionApproachDetailEntry,
...(supportText ? { supportText } : {}), ...(supportText ? { supportText } : {}),
@@ -376,7 +369,6 @@ export function buildMethodSelectionsForDocument(
); );
if (cmIds.length > 0) { if (cmIds.length > 0) {
out.conflictManagement = cmIds.map((id) => { out.conflictManagement = cmIds.map((id) => {
const preset = conflictManagementPresetFor(id);
const override = state.conflictManagementDetailsById?.[id]; const override = state.conflictManagementDetailsById?.[id];
const supportText = publishedRowSupportText( const supportText = publishedRowSupportText(
id, id,
@@ -389,7 +381,7 @@ export function buildMethodSelectionsForDocument(
id, id,
state.customMethodCardMetaById, state.customMethodCardMetaById,
), ),
sections: override ? { ...preset, ...override } : preset, sections: override ?? emptyConflictManagementDetails(),
...(supportText ? { supportText } : {}), ...(supportText ? { supportText } : {}),
}; };
}); });
+14 -5
View File
@@ -15,9 +15,8 @@ import type {
/** /**
* Catalog copy for method/value sections. Generate draft inserts these into * Catalog copy for method/value sections. Generate draft inserts these into
* empty creation-modal fields. Publish still merges them onto saved overrides * empty creation-modal fields. Publish keeps blank parts blank — it does not
* so every method carries a complete section payload when the author only * fill library text the pen holder never wrote.
* edited a subset of fields.
*/ */
type CustomRuleMethodRow = { type CustomRuleMethodRow = {
id: string; id: string;
@@ -145,6 +144,16 @@ export function emptyDecisionApproachTextFields(
}; };
} }
export function emptyDecisionApproachDetails(): DecisionApproachDetailEntry {
return {
corePrinciple: "",
applicableScope: [],
selectedApplicableScope: [],
stepByStepInstructions: "",
objectionsDeadlocks: "",
};
}
export function conflictManagementPresetFor( export function conflictManagementPresetFor(
id: string, id: string,
): ConflictManagementDetailEntry { ): ConflictManagementDetailEntry {
@@ -233,8 +242,8 @@ export function coreValuePresetForLabel(label: string): CoreValueDetailEntry {
} }
/** /**
* Published / display copy: saved draft wins when non-empty; otherwise preset * Generate draft and legacy placeholder replacement: saved copy wins when
* by chip id (numeric presets), then by label match in `coreValues.json`. * non-empty; otherwise preset by chip id, then by label match.
*/ */
export function mergeCoreValueDetailWithPresets( export function mergeCoreValueDetailWithPresets(
chipId: string, chipId: string,
+124 -12
View File
@@ -5,12 +5,34 @@ import type {
DecisionApproachDetailEntry, DecisionApproachDetailEntry,
MembershipMethodDetailEntry, MembershipMethodDetailEntry,
} from "../../app/(app)/create/types"; } from "../../app/(app)/create/types";
import {
buildFinalReviewCategoryRowsDetailed,
type FinalReviewCategoryNames,
} from "./buildFinalReviewCategories";
import type { CustomMethodCardFieldBlock } from "./customMethodCardFieldBlocks";
import { facetBlockHasContent } from "./methodCardWizardPrefill";
import type { TemplateFacetGroupKey } from "./templateReviewMapping"; import type { TemplateFacetGroupKey } from "./templateReviewMapping";
import { usesWizardFieldBlocksModalBody } from "./usesWizardFieldBlocksModalBody";
const LABEL_NAMES: FinalReviewCategoryNames = {
values: "values",
communication: "communication",
membership: "membership",
decisions: "decisions",
conflict: "conflict",
};
function missingText(...values: readonly (string | undefined)[]): boolean { function missingText(...values: readonly (string | undefined)[]): boolean {
return values.some((value) => (value ?? "").trim().length === 0); return values.some((value) => (value ?? "").trim().length === 0);
} }
function customFieldBlocksHaveWords(
blocks: readonly CustomMethodCardFieldBlock[] | undefined,
): boolean {
if (!blocks || blocks.length === 0) return false;
return blocks.every(facetBlockHasContent);
}
function communicationMissingWords( function communicationMissingWords(
saved: CommunicationMethodDetailEntry | undefined, saved: CommunicationMethodDetailEntry | undefined,
): boolean { ): boolean {
@@ -55,21 +77,30 @@ function conflictMissingWords(
); );
} }
/** function methodUsesCustomFieldBlocks(
* A review chip shows a warning when its value is missing meaning or signals,
* or a card is missing its words.
*/
export function finalReviewChipHasWarning(
state: CreateFlowState, state: CreateFlowState,
groupKey: TemplateFacetGroupKey | null, overrideKey: string,
overrideKey: string | null,
): boolean { ): boolean {
if (!groupKey || !overrideKey) return true; return usesWizardFieldBlocksModalBody({
methodId: overrideKey,
meta: state.customMethodCardMetaById,
fieldBlocksById: state.customMethodCardFieldBlocksById,
modalEditUnlocked: true,
draftFieldBlocks: null,
});
}
function methodCardMissingWords(
state: CreateFlowState,
groupKey: Exclude<TemplateFacetGroupKey, "coreValues">,
overrideKey: string,
): boolean {
if (methodUsesCustomFieldBlocks(state, overrideKey)) {
return !customFieldBlocksHaveWords(
state.customMethodCardFieldBlocksById?.[overrideKey],
);
}
switch (groupKey) { switch (groupKey) {
case "coreValues": {
const saved = state.coreValueDetailsByChipId?.[overrideKey];
return missingText(saved?.meaning, saved?.signals);
}
case "communication": case "communication":
return communicationMissingWords( return communicationMissingWords(
state.communicationMethodDetailsById?.[overrideKey], state.communicationMethodDetailsById?.[overrideKey],
@@ -88,3 +119,84 @@ export function finalReviewChipHasWarning(
); );
} }
} }
function valueHasMeaning(
state: CreateFlowState,
overrideKey: string,
): boolean {
const saved = state.coreValueDetailsByChipId?.[overrideKey];
if ((saved?.meaning ?? "").trim().length > 0) return true;
const blocks = state.customMethodCardFieldBlocksById?.[overrideKey];
if (!blocks || blocks.length === 0) return false;
return blocks.some(
(block) =>
block.kind === "text" &&
block.id !== "facet-signals" &&
facetBlockHasContent(block),
);
}
function valueHasSignals(
state: CreateFlowState,
overrideKey: string,
): boolean {
const saved = state.coreValueDetailsByChipId?.[overrideKey];
if ((saved?.signals ?? "").trim().length > 0) return true;
const blocks = state.customMethodCardFieldBlocksById?.[overrideKey];
if (!blocks || blocks.length === 0) return false;
const signalsBlock = blocks.find(
(block) => block.kind === "text" && block.id === "facet-signals",
);
if (!signalsBlock) return true;
return facetBlockHasContent(signalsBlock);
}
/**
* A review chip shows a warning when its value is missing meaning or signals,
* or a card is missing its words. Custom field text counts as those words.
*/
export function finalReviewChipHasWarning(
state: CreateFlowState,
groupKey: TemplateFacetGroupKey | null,
overrideKey: string | null,
): boolean {
if (!groupKey || !overrideKey) return true;
if (groupKey === "coreValues") {
return !valueHasMeaning(state, overrideKey) || !valueHasSignals(state, overrideKey);
}
return methodCardMissingWords(state, groupKey, overrideKey);
}
/**
* Continue waits for every picked card's words and every picked value's
* meaning. Missing signals stay a warning only.
*/
export function finalReviewChipBlocksContinue(
state: CreateFlowState,
groupKey: TemplateFacetGroupKey | null,
overrideKey: string | null,
): boolean {
if (!groupKey || !overrideKey) return false;
if (groupKey === "coreValues") {
return !valueHasMeaning(state, overrideKey);
}
return methodCardMissingWords(state, groupKey, overrideKey);
}
/** Chip labels that still need words before Continue. */
export function finalReviewMissingWordsLabels(
state: CreateFlowState,
): string[] {
const rows = buildFinalReviewCategoryRowsDetailed(state, LABEL_NAMES);
const labels: string[] = [];
for (const row of rows) {
for (const entry of row.entries) {
if (
finalReviewChipBlocksContinue(state, entry.groupKey, entry.overrideKey)
) {
labels.push(entry.label);
}
}
}
return labels;
}
+1 -1
View File
@@ -233,7 +233,7 @@ export function facetDetailsToWizardFieldBlocks(
return mapFacetPrefillToWizardFieldBlocks(prefill); return mapFacetPrefillToWizardFieldBlocks(prefill);
} }
function facetBlockHasContent(block: CustomMethodCardFieldBlock): boolean { export function facetBlockHasContent(block: CustomMethodCardFieldBlock): boolean {
switch (block.kind) { switch (block.kind) {
case "text": case "text":
return hasTrimmedText(block.placeholderText); return hasTrimmedText(block.placeholderText);
@@ -4,13 +4,6 @@ import type { PublishedMethodSelections } from "./buildPublishPayload";
import { parseDocumentSectionsForDisplay } from "./buildPublishPayload"; import { parseDocumentSectionsForDisplay } from "./buildPublishPayload";
import { resolveMethodPresetIdFromLabel } from "./buildFinalReviewCategories"; import { resolveMethodPresetIdFromLabel } from "./buildFinalReviewCategories";
import { resolveCoreValueChipIdFromLabel } from "./finalReviewChipPresets"; import { resolveCoreValueChipIdFromLabel } from "./finalReviewChipPresets";
import {
communicationPresetFor,
conflictManagementPresetFor,
decisionApproachPresetFor,
membershipPresetFor,
mergeCoreValueDetailWithPresets,
} from "./finalReviewChipPresets";
import { templateCategoryToGroupKey } from "./templateReviewMapping"; import { templateCategoryToGroupKey } from "./templateReviewMapping";
import type { TemplateFacetGroupKey } from "./templateReviewMapping"; import type { TemplateFacetGroupKey } from "./templateReviewMapping";
import { RULE_SECTION_CATEGORY } from "./ruleSectionsFromMethodSelections"; import { RULE_SECTION_CATEGORY } from "./ruleSectionsFromMethodSelections";
@@ -110,26 +103,9 @@ function sectionsRecordFromBlocks(
return out; return out;
} }
function presetForMethod(
groupKey: Exclude<TemplateFacetGroupKey, "coreValues">,
id: string,
): Record<string, unknown> {
switch (groupKey) {
case "communication":
return { ...communicationPresetFor(id) } as Record<string, unknown>;
case "membership":
return { ...membershipPresetFor(id) } as Record<string, unknown>;
case "decisionApproaches":
return { ...decisionApproachPresetFor(id) } as Record<string, unknown>;
case "conflictManagement":
return { ...conflictManagementPresetFor(id) } as Record<string, unknown>;
}
}
function sectionsRecordFromEntry( function sectionsRecordFromEntry(
entry: CommunityRuleSection["entries"][number], entry: CommunityRuleSection["entries"][number],
groupKey: Exclude<TemplateFacetGroupKey, "coreValues">, groupKey: Exclude<TemplateFacetGroupKey, "coreValues">,
presetId: string,
): Record<string, unknown> { ): Record<string, unknown> {
const labelByKey = LABELS_BY_GROUP[groupKey]; const labelByKey = LABELS_BY_GROUP[groupKey];
const consensusKey = const consensusKey =
@@ -140,16 +116,16 @@ function sectionsRecordFromEntry(
consensusLevelKey: consensusKey, consensusLevelKey: consensusKey,
}); });
if (Object.keys(fromBlocks).length > 0) { if (Object.keys(fromBlocks).length > 0) {
return { ...presetForMethod(groupKey, presetId), ...fromBlocks }; return fromBlocks;
} }
} }
const body = (entry.body ?? "").trim(); const body = (entry.body ?? "").trim();
if (body.length === 0) { if (body.length === 0) {
return presetForMethod(groupKey, presetId); return {};
} }
return { ...presetForMethod(groupKey, presetId), corePrinciple: body }; return { corePrinciple: body };
} }
function coreValuesFromValuesSection( function coreValuesFromValuesSection(
@@ -169,18 +145,14 @@ function coreValuesFromValuesSection(
const parts = body.length > 0 ? body.split(/\n\n+/) : []; const parts = body.length > 0 ? body.split(/\n\n+/) : [];
const meaning = (parts[0] ?? "").trim(); const meaning = (parts[0] ?? "").trim();
const signals = parts.slice(1).join("\n\n").trim(); const signals = parts.slice(1).join("\n\n").trim();
const merged = mergeCoreValueDetailWithPresets("", label, {
meaning,
signals,
});
const chipId = const chipId =
resolveCoreValueChipIdFromLabel(label) ?? resolveCoreValueChipIdFromLabel(label) ??
`hydrated-${label.toLowerCase()}`; `hydrated-${label.toLowerCase()}`;
out.push({ out.push({
chipId, chipId,
label, label,
meaning: merged.meaning, meaning,
signals: merged.signals, signals,
}); });
} }
@@ -213,7 +185,7 @@ function methodSelectionsFromDisplaySections(
rows.push({ rows.push({
id, id,
label, label,
sections: sectionsRecordFromEntry(entry, groupKey, id), sections: sectionsRecordFromEntry(entry, groupKey),
}); });
} }
if (rows.length > 0) { if (rows.length > 0) {
@@ -80,7 +80,6 @@ const CM_LABELS: Record<string, string> = {
function needsPlaceholderPresetEnrichment(entry: CommunityRuleEntry): boolean { function needsPlaceholderPresetEnrichment(entry: CommunityRuleEntry): boolean {
if (entry.blocks && entry.blocks.length > 0) return false; if (entry.blocks && entry.blocks.length > 0) return false;
const b = (entry.body ?? "").trim(); const b = (entry.body ?? "").trim();
if (b.length === 0) return true;
return b === TEMPLATE_COMPOSITION_SUGGESTED_BODY; return b === TEMPLATE_COMPOSITION_SUGGESTED_BODY;
} }
@@ -196,15 +195,12 @@ function sectionFromStoredCoreValues(
for (const row of raw) { for (const row of raw) {
if (!row || typeof row !== "object") continue; if (!row || typeof row !== "object") continue;
const o = row as Record<string, unknown>; const o = row as Record<string, unknown>;
const chipId = typeof o.chipId === "string" ? o.chipId : "";
const label = nonEmptyTrimmed(o.label); const label = nonEmptyTrimmed(o.label);
if (!label) continue; if (!label) continue;
const merged = mergeCoreValueDetailWithPresets(chipId, label, { const meaning =
meaning: typeof o.meaning === "string" ? o.meaning : "", typeof o.meaning === "string" ? o.meaning.trim() : "";
signals: typeof o.signals === "string" ? o.signals : "", const signals =
}); typeof o.signals === "string" ? o.signals.trim() : "";
const meaning = (merged.meaning ?? "").trim();
const signals = (merged.signals ?? "").trim();
const bodyParts: string[] = []; const bodyParts: string[] = [];
if (meaning.length > 0) bodyParts.push(meaning); if (meaning.length > 0) bodyParts.push(meaning);
if (signals.length > 0) bodyParts.push(signals); if (signals.length > 0) bodyParts.push(signals);
@@ -221,8 +221,7 @@ export function communityRuleEntryFromMethodChip(
const blocks = [...presetBlocks, ...wizardBlocks]; const blocks = [...presetBlocks, ...wizardBlocks];
const description = nonEmptyTrimmed(options?.supportText); const description = nonEmptyTrimmed(options?.supportText);
if (blocks.length === 0) { if (blocks.length === 0) {
if (!description) return null; return { title, body: description ?? "" };
return { title, body: description };
} }
return { return {
title, title,
@@ -387,8 +386,8 @@ export function sectionFromConflict(
} }
/** /**
* Swap template `sections` method rows for fully-resolved entries built from * Swap template `sections` method rows for entries built from
* `methodSelections` (preset + overrides). * `methodSelections`.
*/ */
export function replaceMethodSectionsWithMethodSelections( export function replaceMethodSectionsWithMethodSelections(
sections: CommunityRuleSection[], sections: CommunityRuleSection[],
@@ -30,6 +30,10 @@
"title": "Binding arbitration needs each member’s own yes", "title": "Binding arbitration needs each member’s own yes",
"description": "Open admission and membership by token do not record that yes. Each member still has to agree separately before binding arbitration applies to them." "description": "Open admission and membership by token do not record that yes. Each member still has to agree separately before binding arbitration applies to them."
}, },
"missingWordsWarning": {
"title": "Add words before you finish",
"description": "These still need words: {labels}."
},
"categories": [ "categories": [
{ {
"name": "Values", "name": "Values",
@@ -241,6 +241,14 @@ describe("FinalReviewScreen — prefilled selections", () => {
expect( expect(
screen.getByRole("button", { name: "Signal, missing words" }), screen.getByRole("button", { name: "Signal, missing words" }),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(
screen.getByText("Add words before you finish"),
).toBeInTheDocument();
expect(
screen.getByText(
/These still need words: Accessibility, Signal, Open admission/,
),
).toBeInTheDocument();
}); });
it("warns when binding arbitration sits next to a join that records no yes", async () => { it("warns when binding arbitration sits next to a join that records no yes", async () => {
+10 -18
View File
@@ -4,7 +4,6 @@ import {
parseDocumentSectionsForDisplay, parseDocumentSectionsForDisplay,
parseSectionsFromCreateFlowState, parseSectionsFromCreateFlowState,
} from "../../lib/create/buildPublishPayload"; } from "../../lib/create/buildPublishPayload";
import { mergeCoreValueDetailWithPresets } from "../../lib/create/finalReviewChipPresets";
import type { CreateFlowState } from "../../app/(app)/create/types"; import type { CreateFlowState } from "../../app/(app)/create/types";
describe("buildPublishPayload", () => { describe("buildPublishPayload", () => {
@@ -144,15 +143,9 @@ describe("buildPublishPayload", () => {
}); });
expect(r.ok).toBe(true); expect(r.ok).toBe(true);
if (!r.ok) return; if (!r.ok) return;
const preset2 = mergeCoreValueDetailWithPresets("2", "Beta", undefined);
expect(r.document.coreValues).toEqual([ expect(r.document.coreValues).toEqual([
{ chipId: "1", label: "Alpha", meaning: "m1", signals: "s1" }, { chipId: "1", label: "Alpha", meaning: "m1", signals: "s1" },
{ { chipId: "2", label: "Beta", meaning: "", signals: "" },
chipId: "2",
label: "Beta",
meaning: preset2.meaning,
signals: preset2.signals,
},
]); ]);
}); });
}); });
@@ -188,11 +181,12 @@ describe("buildPublishPayload — methodSelections", () => {
expect(ms?.communication?.length).toBe(1); expect(ms?.communication?.length).toBe(1);
expect(ms?.communication?.[0]?.id).toBe("slack"); expect(ms?.communication?.[0]?.id).toBe("slack");
const first = ms?.communication?.[0]; const first = ms?.communication?.[0];
expect(first?.sections.corePrinciple.length).toBeGreaterThan(10); expect(first?.sections.corePrinciple).toBe("");
const entries = const entries =
(r.document.sections as Array<{ entries: Array<{ blocks?: unknown[] }> }>)[0] (r.document.sections as Array<{
?.entries; entries: Array<{ title: string; body: string; blocks?: unknown[] }>;
expect(entries?.[0]?.blocks?.length).toBeGreaterThanOrEqual(1); }>)[0]?.entries;
expect(entries?.[0]).toEqual({ title: "Slack", body: "" });
}); });
it("uses customMethodCardMetaById label when preset id is unknown", () => { it("uses customMethodCardMetaById label when preset id is unknown", () => {
@@ -251,7 +245,7 @@ describe("buildPublishPayload — methodSelections", () => {
]); ]);
}); });
it("emits preset-only sections when a method is selected without an override", () => { it("keeps blank card parts blank when a method is selected without an override", () => {
const r = buildPublishPayload({ const r = buildPublishPayload({
title: "T", title: "T",
selectedCommunicationMethodIds: ["signal"], selectedCommunicationMethodIds: ["signal"],
@@ -270,9 +264,7 @@ describe("buildPublishPayload — methodSelections", () => {
}; };
expect(entry.id).toBe("signal"); expect(entry.id).toBe("signal");
expect(entry.label).toBe("Signal"); expect(entry.label).toBe("Signal");
// Preset corePrinciple is non-empty for `signal` in the shipped messages expect(entry.sections.corePrinciple).toBe("");
// file — proves we read presets when no override is present.
expect(entry.sections.corePrinciple.length).toBeGreaterThan(0);
}); });
it("does not seed 75% consensus on a custom decision-making card", () => { it("does not seed 75% consensus on a custom decision-making card", () => {
@@ -311,7 +303,7 @@ describe("buildPublishPayload — methodSelections", () => {
expect(ms.decisionApproaches?.[0]?.sections.consensusLevel).toBeUndefined(); expect(ms.decisionApproaches?.[0]?.sections.consensusLevel).toBeUndefined();
}); });
it("keeps catalog decision consensus in methodSelections", () => { it("does not fill catalog decision consensus when the card has no words", () => {
const r = buildPublishPayload({ const r = buildPublishPayload({
title: "T", title: "T",
selectedDecisionApproachIds: ["lazy-consensus"], selectedDecisionApproachIds: ["lazy-consensus"],
@@ -321,7 +313,7 @@ describe("buildPublishPayload — methodSelections", () => {
const ms = r.document.methodSelections as { const ms = r.document.methodSelections as {
decisionApproaches?: Array<{ sections: { consensusLevel?: number } }>; decisionApproaches?: Array<{ sections: { consensusLevel?: number } }>;
}; };
expect(ms.decisionApproaches?.[0]?.sections.consensusLevel).toBe(100); expect(ms.decisionApproaches?.[0]?.sections.consensusLevel).toBeUndefined();
}); });
it("merges override on top of preset for the selected method", () => { it("merges override on top of preset for the selected method", () => {
+153 -5
View File
@@ -1,7 +1,11 @@
import { describe, it, expect } from "vitest"; import { describe, it, expect } from "vitest";
import { isFinalReviewContinueBlocked } from "../../app/(app)/create/utils/createFlowFooterLabels"; import { isFinalReviewContinueBlocked } from "../../app/(app)/create/utils/createFlowFooterLabels";
import { communityInitialsFromTitle } from "../../lib/create/communityInitials"; import { communityInitialsFromTitle } from "../../lib/create/communityInitials";
import { finalReviewChipHasWarning } from "../../lib/create/finalReviewChipWarnings"; import {
finalReviewChipBlocksContinue,
finalReviewChipHasWarning,
finalReviewMissingWordsLabels,
} from "../../lib/create/finalReviewChipWarnings";
import type { CreateFlowState } from "../../app/(app)/create/types"; import type { CreateFlowState } from "../../app/(app)/create/types";
const completeCards: CreateFlowState = { const completeCards: CreateFlowState = {
@@ -12,11 +16,47 @@ const completeCards: CreateFlowState = {
selectedConflictManagementIds: ["conflict-ladder"], selectedConflictManagementIds: ["conflict-ladder"],
}; };
const completeCardsWithWords: CreateFlowState = {
...completeCards,
communicationMethodDetailsById: {
signal: {
corePrinciple: "We talk in the open.",
logisticsAdmin: "Post in Signal.",
codeOfConduct: "No pile-ons.",
},
},
membershipMethodDetailsById: {
"open-admission": {
eligibility: "Anyone who shares the work.",
joiningProcess: "Show up.",
expectations: "Keep the keys.",
},
},
decisionApproachDetailsById: {
"lazy-consensus": {
corePrinciple: "Silence is assent.",
applicableScope: [],
selectedApplicableScope: [],
stepByStepInstructions: "Post the proposal.",
objectionsDeadlocks: "A named block stops it.",
},
},
conflictManagementDetailsById: {
"conflict-ladder": {
corePrinciple: "Start small.",
applicableScope: [],
selectedApplicableScope: [],
processProtocol: "Talk, then mediate.",
restorationFallbacks: "A panel if that fails.",
},
},
};
describe("isFinalReviewContinueBlocked", () => { describe("isFinalReviewContinueBlocked", () => {
it("blocks when the community name is empty", () => { it("blocks when the community name is empty", () => {
expect( expect(
isFinalReviewContinueBlocked({ isFinalReviewContinueBlocked({
...completeCards, ...completeCardsWithWords,
title: " ", title: " ",
}), }),
).toBe(true); ).toBe(true);
@@ -25,14 +65,45 @@ describe("isFinalReviewContinueBlocked", () => {
it("blocks when any of the four questions has no card", () => { it("blocks when any of the four questions has no card", () => {
expect( expect(
isFinalReviewContinueBlocked({ isFinalReviewContinueBlocked({
...completeCards, ...completeCardsWithWords,
selectedMembershipMethodIds: [], selectedMembershipMethodIds: [],
}), }),
).toBe(true); ).toBe(true);
}); });
it("does not block when values are empty and the four questions have cards", () => { it("blocks when a picked card is missing its words", () => {
expect(isFinalReviewContinueBlocked(completeCards)).toBe(false); expect(isFinalReviewContinueBlocked(completeCards)).toBe(true);
});
it("does not block when values are empty and every card has its words", () => {
expect(isFinalReviewContinueBlocked(completeCardsWithWords)).toBe(false);
});
it("blocks when a picked value is missing its meaning", () => {
expect(
isFinalReviewContinueBlocked({
...completeCardsWithWords,
selectedCoreValueIds: ["1"],
coreValuesChipsSnapshot: [
{ id: "1", label: "Care", state: "selected" },
],
}),
).toBe(true);
});
it("does not block when a value has meaning but no signals", () => {
expect(
isFinalReviewContinueBlocked({
...completeCardsWithWords,
selectedCoreValueIds: ["1"],
coreValuesChipsSnapshot: [
{ id: "1", label: "Care", state: "selected" },
],
coreValueDetailsByChipId: {
"1": { meaning: "We look after each other.", signals: "" },
},
}),
).toBe(false);
}); });
}); });
@@ -70,6 +141,83 @@ describe("finalReviewChipHasWarning", () => {
), ),
).toBe(false); ).toBe(false);
}); });
it("clears the warning when a custom card's fields have text", () => {
const customId = "00000000-0000-4000-8000-000000000190";
expect(
finalReviewChipHasWarning(
{
customMethodCardMetaById: {
[customId]: { label: "S13 comms card", supportText: "" },
},
customMethodCardFieldBlocksById: {
[customId]: [
{
kind: "text",
id: "b1",
blockTitle: "How we talk",
placeholderText: "Post in the hall.",
},
],
},
},
"communication",
customId,
),
).toBe(false);
});
});
describe("finalReviewChipBlocksContinue", () => {
it("does not block a value that has meaning but no signals", () => {
expect(
finalReviewChipBlocksContinue(
{
coreValueDetailsByChipId: {
"1": { meaning: "Care", signals: "" },
},
},
"coreValues",
"1",
),
).toBe(false);
});
it("blocks a custom card until its fields have text", () => {
const customId = "00000000-0000-4000-8000-000000000191";
expect(
finalReviewChipBlocksContinue(
{
customMethodCardMetaById: {
[customId]: { label: "S13 comms card", supportText: "" },
},
customMethodCardFieldBlocksById: {
[customId]: [
{
kind: "text",
id: "b1",
blockTitle: "How we talk",
placeholderText: "",
},
],
},
},
"communication",
customId,
),
).toBe(true);
});
});
describe("finalReviewMissingWordsLabels", () => {
it("names the cards that still need words", () => {
expect(finalReviewMissingWordsLabels(completeCards)).toEqual([
"Signal",
"Open admission",
"Lazy consensus",
"Conflict ladder",
]);
});
}); });
describe("communityInitialsFromTitle", () => { describe("communityInitialsFromTitle", () => {
@@ -81,7 +81,7 @@ describe("parsePublishedDocumentForCommunityRuleDisplay", () => {
expect(out[0].entries[0].body).toBe("x\n\ny"); expect(out[0].entries[0].body).toBe("x\n\ny");
}); });
it("enriches empty core value copy from presets (label match)", () => { it("keeps empty core value copy blank instead of filling library text", () => {
const doc = { const doc = {
sections: [], sections: [],
coreValues: [ coreValues: [
@@ -89,7 +89,8 @@ describe("parsePublishedDocumentForCommunityRuleDisplay", () => {
], ],
}; };
const out = parsePublishedDocumentForCommunityRuleDisplay(doc); const out = parsePublishedDocumentForCommunityRuleDisplay(doc);
expect(out[0].entries[0].body).toMatch(/well-being is bound up/); expect(out[0].entries[0].title).toBe("Interdependence");
expect(out[0].entries[0].body).toBe("");
}); });
it("replaces template placeholder bodies with preset copy, Values first", () => { it("replaces template placeholder bodies with preset copy, Values first", () => {
+31
View File
@@ -61,6 +61,37 @@ describe("inviteRuleCountsLabel", () => {
}), }),
).toBe("3 VALUES AND 2 CARDS"); ).toBe("3 VALUES AND 2 CARDS");
}); });
it("counts titled cards that still have no words", () => {
expect(
inviteRuleCountsLabel({
methodSelections: {
communication: [
{
id: "signal",
label: "Signal",
sections: {
corePrinciple: "",
logisticsAdmin: "",
codeOfConduct: "",
},
},
],
membership: [
{
id: "open-admission",
label: "Open admission",
sections: {
eligibility: "",
joiningProcess: "",
expectations: "",
},
},
],
},
}),
).toBe("0 VALUES AND 2 CARDS");
});
}); });
describe("inviteRuleCountsSpoken", () => { describe("inviteRuleCountsSpoken", () => {
@@ -45,6 +45,16 @@ describe("withoutUnpublishedDecisionConsensus", () => {
}); });
describe("communityRuleEntryFromMethodChip", () => { describe("communityRuleEntryFromMethodChip", () => {
it("keeps a titled card when there are no words yet", () => {
expect(
communityRuleEntryFromMethodChip(
"Signal",
{ corePrinciple: "" },
{ corePrinciple: "Core Principle" },
),
).toEqual({ title: "Signal", body: "" });
});
it("publishes supportText as body when there are no labeled blocks", () => { it("publishes supportText as body when there are no labeled blocks", () => {
expect( expect(
communityRuleEntryFromMethodChip( communityRuleEntryFromMethodChip(