Keep every picked card on the finished Rule, and wait for its words before Continue.
This commit is contained in:
1 parent
a846169960
commit
a2815ae05f
16 files changed
+417
-114
No files matched your search
@@ -5,12 +5,34 @@ import type {
|
||||
DecisionApproachDetailEntry,
|
||||
MembershipMethodDetailEntry,
|
||||
} 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 { usesWizardFieldBlocksModalBody } from "./usesWizardFieldBlocksModalBody";
|
||||
|
||||
const LABEL_NAMES: FinalReviewCategoryNames = {
|
||||
values: "values",
|
||||
communication: "communication",
|
||||
membership: "membership",
|
||||
decisions: "decisions",
|
||||
conflict: "conflict",
|
||||
};
|
||||
|
||||
function missingText(...values: readonly (string | undefined)[]): boolean {
|
||||
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(
|
||||
saved: CommunicationMethodDetailEntry | undefined,
|
||||
): boolean {
|
||||
@@ -55,21 +77,30 @@ function conflictMissingWords(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A review chip shows a warning when its value is missing meaning or signals,
|
||||
* or a card is missing its words.
|
||||
*/
|
||||
export function finalReviewChipHasWarning(
|
||||
function methodUsesCustomFieldBlocks(
|
||||
state: CreateFlowState,
|
||||
groupKey: TemplateFacetGroupKey | null,
|
||||
overrideKey: string | null,
|
||||
overrideKey: string,
|
||||
): 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) {
|
||||
case "coreValues": {
|
||||
const saved = state.coreValueDetailsByChipId?.[overrideKey];
|
||||
return missingText(saved?.meaning, saved?.signals);
|
||||
}
|
||||
case "communication":
|
||||
return communicationMissingWords(
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user