Treat a typed main kind as no kind so recommendations still fall back to size.
A custom kind no longer empties a job of eligible cards, and other catalog kinds stay ranking hints instead of becoming the main kind.
This commit is contained in:
1 parent
dad8661268
commit
f795951443
5 files changed
+116
-16
No files matched your search
+23
-10
@@ -9,8 +9,21 @@ import {
|
||||
import type { GroupAnswers, Kind, Scale, Stage, TraitKey } from "./deckTypes";
|
||||
import { KINDS, SCALES, STAGES, TRAIT_KEYS } from "./deckTypes";
|
||||
|
||||
function isKind(value: string): value is Kind {
|
||||
return (KINDS as readonly string[]).includes(value);
|
||||
function isKind(value: string | null | undefined): value is Kind {
|
||||
return value != null && (KINDS as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
/** First id is the main kind only when it is a catalog kind. A typed kind is no kind. */
|
||||
function kindsFromOrderedIds(ids: readonly string[]): {
|
||||
mainKind: Kind | null;
|
||||
otherKinds: Kind[];
|
||||
} {
|
||||
const mainKind = isKind(ids[0]) ? ids[0] : null;
|
||||
const otherKinds = ids
|
||||
.slice(1)
|
||||
.filter(isKind)
|
||||
.filter((kind, index, all) => kind !== mainKind && all.indexOf(kind) === index);
|
||||
return { mainKind, otherKinds };
|
||||
}
|
||||
|
||||
function isScale(value: string): value is Scale {
|
||||
@@ -36,15 +49,15 @@ export function groupAnswersFromRequestedFacets(
|
||||
facets: RequestedFacets,
|
||||
traits?: Partial<Record<TraitKey, boolean>>,
|
||||
): GroupAnswers {
|
||||
const kinds = (facets.orgType ?? []).filter(isKind);
|
||||
const { mainKind, otherKinds } = kindsFromOrderedIds(facets.orgType ?? []);
|
||||
const scales = (facets.scale ?? []).filter(isScale);
|
||||
const maturity = (facets.maturity ?? [])
|
||||
.map((value) => stageForScoring(value))
|
||||
.filter((value): value is Stage => value !== null);
|
||||
return {
|
||||
size: facets.size?.[0] ?? null,
|
||||
mainKind: kinds[0] ?? null,
|
||||
otherKinds: kinds.slice(1),
|
||||
mainKind,
|
||||
otherKinds,
|
||||
scale: scales,
|
||||
stage: maturity[0] ?? null,
|
||||
traits,
|
||||
@@ -66,9 +79,9 @@ export function groupAnswersFromCreateFlowState(
|
||||
state: CreateFlowState,
|
||||
): GroupAnswers {
|
||||
const size = (state.selectedCommunitySizeIds ?? []).map(resolveSizeChipId)[0] ?? null;
|
||||
const kinds = (state.selectedOrganizationTypeIds ?? [])
|
||||
.map((id) => resolveOrgChipId(id))
|
||||
.filter(isKind);
|
||||
const { mainKind, otherKinds } = kindsFromOrderedIds(
|
||||
(state.selectedOrganizationTypeIds ?? []).map((id) => resolveOrgChipId(id)),
|
||||
);
|
||||
const scale = (state.selectedScaleIds ?? [])
|
||||
.map(resolveScaleChipId)
|
||||
.filter(isScale);
|
||||
@@ -78,8 +91,8 @@ export function groupAnswersFromCreateFlowState(
|
||||
const uniqueScale = [...new Set(scale)];
|
||||
return {
|
||||
size,
|
||||
mainKind: kinds[0] ?? null,
|
||||
otherKinds: kinds.slice(1).filter((kind, index, all) => all.indexOf(kind) === index),
|
||||
mainKind,
|
||||
otherKinds,
|
||||
scale: uniqueScale,
|
||||
stage: maturity[0] ?? null,
|
||||
traits: traitRecord(state.setupTraits),
|
||||
|
||||
Reference in new issue
Block a user