Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | 41x 41x 41x 41x 41x 447x 277x 41x 213x 41x 211x 41x 13x 8x 41x 784x 342x 342x 448x 1x 448x 1x 447x 41x 41x 41x 41x 41x 41x 41x 41x 494x 41x 177x 2x 175x 41x 25x 25x 21x 21x 41x 22x 41x 41x 52x 52x 48x 48x 41x 4x 4x 3x 41x 200x 200x 172x 200x 170x 23x 147x 41x 4x 4x 4x 4x 4x 4x 4x 4x 2x 41x 73x 73x 5x 5x 4x 41x 789x 789x 41x 41x 3x 3x 3x 41x 8x 8x 8x 8x 5x 3x 3x 8x 8x 1x 2x 41x 106x 106x 106x 106x 41x 2x 2x 1x 1x 41x 4x 4x 2x 2x 41x 41x 41x 41x 41x 248x 41x 250x 250x 250x 8x 242x 41x 565x 41x 345x 329x 323x 41x 26x 26x 26x 3x 3x 3x 3x 41x 286x 286x 3x 283x 286x 41x 638x 638x 286x 279x 41x 236x 236x 236x 236x 5639x 5639x 1409x 1409x 2x 234x 236x 236x 472x 472x 472x 230x 230x 4x 41x 242x 242x 7x 7x 236x 242x 41x 622x 243x 1x 242x 622x 622x 238x 458x 41x 41x 315x 41x 159x 102x 57x 159x 57x 57x 57x 41x 41x 5801x 5789x 5789x 5699x 41x 280x 269x 11x 11x 280x 280x 9x 2x 41x 491x 279x 212x 212x 2x 485x 41x 176x 6x 170x 176x 176x 176x 14x 11x 3x 3x 156x 1x 155x 131x 24x 176x 1x 23x 23x 41x 174x 174x 174x 174x 174x | import { alpha } from "@mui/material/styles";
/** Soft-chip semantic colors per subscription tier (low → high). */
export const PLAN_CHIP_COLORS = {
free: "default",
basic: "info",
intermediate: "accent",
premium: "warning",
};
/** MUI palette key used for each plan tier's soft chip (sidebar, profile, etc.). */
export const PLAN_PALETTE_KEYS = {
free: null,
basic: "info",
intermediate: "secondary",
premium: "warning",
};
const PLAN_LABELS = {
free: "Free",
basic: "Basic",
intermediate: "Intermediate",
premium: "Premium",
};
const PLAN_STYLES = {
free: {
textColor: "#637381",
borderColor: "transparent",
background: "#F4F6F8",
},
basic: {
textColor: "#006C9C",
borderColor: "transparent",
background: "#CAFDF5",
},
intermediate: {
textColor: "#5119B7",
borderColor: "transparent",
background: "#EDE7F6",
},
premium: {
textColor: "#B76E00",
borderColor: "transparent",
background: "#FFF5CC",
},
};
export const normalizeFeatureList = (features) => {
if (!Array.isArray(features)) return [];
return features.filter((feature) => typeof feature?.feature_key === "string");
};
export const isFeatureEnabled = (features, key) =>
normalizeFeatureList(features).find((feature) => feature.feature_key === key)?.enabled ?? false;
export const getFeatureMeta = (features, key) =>
normalizeFeatureList(features).find((feature) => feature.feature_key === key) ?? null;
export const getPlanLabel = (plan) => {
if (!plan || typeof plan !== "string") return "an upgraded plan";
return PLAN_LABELS[plan.toLowerCase()] || plan;
};
/** Resolve plan slug from `current_plan` and/or display `plan_name`. */
export const resolvePlanKey = (plan, planName = null) => {
if (plan && typeof plan === "string") {
const key = plan.toLowerCase().trim();
if (PLAN_CHIP_COLORS[key]) return key;
}
const candidates = [planName]
.filter(Boolean)
.map((name) =>
String(name)
.toLowerCase()
.replace(/\s*plan\s*/gi, " ")
.trim()
);
for (const normalized of candidates) {
Eif (PLAN_CHIP_COLORS[normalized]) return normalized;
const byLabel = Object.entries(PLAN_LABELS).find(([, label]) => label.toLowerCase() === normalized);
if (byLabel) return byLabel[0];
for (const key of Object.keys(PLAN_CHIP_COLORS)) {
if (normalized.includes(key)) return key;
}
}
return null;
};
/** Subscription tiers from lowest to highest. */
export const PLAN_TIER_ORDER = ["free", "basic", "intermediate", "premium"];
/** Default minimum plan when API feature metadata omits `min_plan`. */
export const TEACHER_ITEM_ANALYSIS_FEATURE_KEY = "teacher.item_analysis";
export const TEACHER_CREATE_OWN_QUESTIONS_KEY = "teacher.create_own_questions";
/**
* Access to Erudition Library globals (non-exam-catalog staff-created tests).
* Plan tier and lock state come from the API (`min_plan` / `locked` on assignment
* rows and `min_plan` on the effective-features entry) — not client defaults.
*/
export const TEACHER_ERUDITION_TESTS_LIBRARY_KEY = "teacher.erudition_tests_library";
/** @deprecated Backend alias — resolved to {@link TEACHER_ERUDITION_TESTS_LIBRARY_KEY}. */
export const TEACHER_GLOBAL_STAFF_TESTS_KEY = "teacher.global_staff_tests";
/** User-facing label for non-catalog Erudition-created global tests. */
export const ERUDITION_LIBRARY_LABEL = "Erudition Library";
const ERUDITION_LIBRARY_FEATURE_KEYS = new Set([
TEACHER_ERUDITION_TESTS_LIBRARY_KEY,
TEACHER_GLOBAL_STAFF_TESTS_KEY,
]);
/** True for Erudition Library feature keys (canonical or legacy alias). */
export const isEruditionLibraryFeatureKey = (featureKey) =>
ERUDITION_LIBRARY_FEATURE_KEYS.has(featureKey);
/** Normalize legacy GrowthBook keys to the canonical registry key. */
export const resolveCanonicalFeatureKey = (featureKey) => {
if (featureKey === TEACHER_GLOBAL_STAFF_TESTS_KEY) {
return TEACHER_ERUDITION_TESTS_LIBRARY_KEY;
}
return featureKey;
};
/** Parse `Feature '…' is not enabled` from a 403 response body. */
export const parseFeatureKeyFrom403 = (error) => {
const detail = error?.response?.data?.detail;
if (typeof detail !== "string") return null;
const match = detail.match(/Feature '([^']+)'/);
return match?.[1] ?? null;
};
export const isFeatureNotEnabled403 = (error) =>
error?.response?.status === 403 && Boolean(parseFeatureKeyFrom403(error));
export const FEATURE_MIN_PLAN_DEFAULTS = {
"teacher.dashboard": "intermediate",
[TEACHER_ITEM_ANALYSIS_FEATURE_KEY]: "intermediate",
[TEACHER_CREATE_OWN_QUESTIONS_KEY]: "intermediate",
"teacher.teacher_made_tests.limit_10": "intermediate",
"teacher.teacher_made_tests.unlimited": "premium",
};
export const getPlanTierIndex = (planKey) => {
const key = resolvePlanKey(planKey);
if (!key) return -1;
const idx = PLAN_TIER_ORDER.indexOf(key);
return idx >= 0 ? idx : -1;
};
export const getNextPlanTier = (planKey) => {
const idx = getPlanTierIndex(planKey);
if (idx < 0 || idx >= PLAN_TIER_ORDER.length - 1) return null;
return PLAN_TIER_ORDER[idx + 1];
};
/** Minimum plan tier that includes the feature (from override, API meta, or defaults). */
export const resolveRequiredPlanForFeature = (featureKey, featureMeta = null, minPlanOverride = null) => {
const fromOverride = resolvePlanKey(minPlanOverride);
if (fromOverride) return fromOverride;
const fromMeta = resolvePlanKey(featureMeta?.min_plan);
if (fromMeta) return fromMeta;
if (featureKey && FEATURE_MIN_PLAN_DEFAULTS[featureKey]) {
return FEATURE_MIN_PLAN_DEFAULTS[featureKey];
}
return null;
};
/**
* Plan tier to show as the upgrade target — never the user's current tier when they already meet the minimum.
*/
export const resolveRecommendedUpgradePlan = ({
featureKey = null,
featureMeta = null,
minPlan = null,
currentPlan = null,
planName = null,
} = {}) => {
const current = resolvePlanKey(currentPlan, planName);
const required = resolveRequiredPlanForFeature(featureKey, featureMeta, minPlan);
Iif (!required) return null;
Iif (!current) return required;
const currentIdx = getPlanTierIndex(current);
const requiredIdx = getPlanTierIndex(required);
Iif (currentIdx < 0 || requiredIdx < 0) return required;
if (currentIdx < requiredIdx) return required;
return getNextPlanTier(current);
};
/** Soft-chip color for a subscription plan. */
export const getPlanChipColor = (plan, planName = null) => {
const key = resolvePlanKey(plan, planName);
if (!key) return "default";
const mapped = PLAN_CHIP_COLORS[key];
// Intermediate uses secondary in explicit sx — keep semantic fallback distinct from role chip.
if (key === "intermediate") return "default";
return mapped;
};
/** Shared soft typography for sidebar/profile badge chips. */
export const getSoftBadgeTypographySx = (theme, size = "sm") => {
const isMedium = size === "md";
return {
fontFamily: theme.typography.fontFamily,
fontWeight: theme.typography.fontWeightMedium ?? 500,
fontSize: isMedium ? "0.8125rem" : "0.75rem",
letterSpacing: "0.02em",
lineHeight: 1.5,
height: isMedium ? 28 : 24,
borderRadius: `${(theme.shape.borderRadius || 8) * 1.25}px`,
"& .MuiChip-label": {
px: isMedium ? 1 : 0.75,
py: 0,
},
"& .MuiChip-icon": {
color: "inherit !important",
opacity: 0.9,
fontSize: isMedium ? 16 : 14,
marginLeft: isMedium ? "8px !important" : "7px !important",
marginRight: "-2px !important",
},
};
};
/** @deprecated Use getSoftBadgeTypographySx */
export const getPlanChipTypographySx = getSoftBadgeTypographySx;
/** Soft primary styling for role badges (Teacher, Student, etc.). */
export const getRoleChipSx = (theme, size = "sm") => {
const lightMode = theme.palette.mode === "light";
const primary = theme.palette.primary;
return {
...getSoftBadgeTypographySx(theme, size),
bgcolor: alpha(primary.main, lightMode ? 0.14 : 0.22),
color: primary[lightMode ? "dark" : "light"],
};
};
/** Theme-aware soft chip sx — distinct color per subscription tier. */
export const getPlanChipSx = (theme, plan, planName = null, size = "sm") => {
const key = resolvePlanKey(plan, planName) || "free";
const lightMode = theme.palette.mode === "light";
const typographySx = getSoftBadgeTypographySx(theme, size);
if (key === "free") {
return {
...typographySx,
bgcolor: alpha(theme.palette.grey[500], 0.14),
color: theme.palette.text.secondary,
};
}
const paletteKey = PLAN_PALETTE_KEYS[key];
const paletteColor =
paletteKey && theme.palette[paletteKey]?.main ? theme.palette[paletteKey] : theme.palette.primary;
const staticStyle = PLAN_STYLES[key];
if (key === "intermediate" && staticStyle) {
return {
...typographySx,
bgcolor: staticStyle.background,
color: staticStyle.textColor,
};
}
return {
...typographySx,
bgcolor: alpha(paletteColor.main, lightMode ? 0.14 : 0.22),
color: paletteColor[lightMode ? "dark" : "light"] || staticStyle?.textColor,
};
};
/** Frosted plan badge styles for primary-colored headers/toolbars. */
export const getPlanOnPrimaryChipSx = (theme, plan, planName = null, size = "sm") => {
const key = resolvePlanKey(plan, planName) || "free";
const typographySx = getSoftBadgeTypographySx(theme, size);
const presets = {
free: {
bgcolor: alpha(theme.palette.common.white, 0.18),
color: alpha(theme.palette.common.white, 0.95),
},
basic: {
bgcolor: alpha(theme.palette.info.light, 0.38),
color: theme.palette.common.white,
},
intermediate: {
bgcolor: alpha(theme.palette.secondary?.main || theme.palette.primary.light, 0.36),
color: theme.palette.common.white,
boxShadow: `inset 0 0 0 1px ${alpha(theme.palette.common.white, 0.22)}`,
},
premium: {
bgcolor: alpha(theme.palette.warning.light, 0.62),
color: theme.palette.grey[900],
},
};
return {
...typographySx,
...presets[key],
};
};
export const getPlanStyle = (plan, planName = null) => {
const key = resolvePlanKey(plan, planName);
if (!key) {
return {
textColor: "#263238",
borderColor: "#CFD8DC",
background: "linear-gradient(135deg, #F5F5F5 0%, #ECEFF1 100%)",
};
}
return PLAN_STYLES[key] || PLAN_STYLES.free;
};
export const formatUpgradeMessage = (featureMeta, minPlanOverride = null) => {
const requiredPlan = minPlanOverride || featureMeta?.min_plan;
if (!requiredPlan) {
return "Contact your district administrator to upgrade your plan.";
}
return `Available on the ${getPlanLabel(requiredPlan)} plan. Contact your district administrator to upgrade your plan.`;
};
const EXAM_CATALOG_TYPES = ["staar", "tsi", "sat", "act"];
/** 24-slot tiered exam catalog (`teacher.exam.*`) — short titles like `TSI 1`, `ACT 2`. */
export const EXAM_CATALOG_FEATURE_LABELS = {
"teacher.exam.staar.1": "STAAR 1",
"teacher.exam.staar.2": "STAAR 2",
"teacher.exam.staar.3": "STAAR 3",
"teacher.exam.staar.4": "STAAR 4",
"teacher.exam.staar.5": "STAAR 5",
"teacher.exam.staar.6": "STAAR 6",
"teacher.exam.tsi.1": "TSI 1",
"teacher.exam.tsi.2": "TSI 2",
"teacher.exam.tsi.3": "TSI 3",
"teacher.exam.tsi.4": "TSI 4",
"teacher.exam.tsi.5": "TSI 5",
"teacher.exam.tsi.6": "TSI 6",
"teacher.exam.sat.1": "SAT 1",
"teacher.exam.sat.2": "SAT 2",
"teacher.exam.sat.3": "SAT 3",
"teacher.exam.sat.4": "SAT 4",
"teacher.exam.sat.5": "SAT 5",
"teacher.exam.sat.6": "SAT 6",
"teacher.exam.act.1": "ACT 1",
"teacher.exam.act.2": "ACT 2",
"teacher.exam.act.3": "ACT 3",
"teacher.exam.act.4": "ACT 4",
"teacher.exam.act.5": "ACT 5",
"teacher.exam.act.6": "ACT 6",
};
export const EXAM_CATALOG_FEATURE_KEYS = Object.keys(EXAM_CATALOG_FEATURE_LABELS);
const EXAM_CATALOG_FEATURE_KEY_SET = new Set(EXAM_CATALOG_FEATURE_KEYS);
export const isExamCatalogFeatureKey = (featureKey) =>
typeof featureKey === "string" && EXAM_CATALOG_FEATURE_KEY_SET.has(featureKey);
export const buildExamCatalogFeatureKey = (examType, slot) => {
const type = String(examType || "")
.trim()
.toLowerCase();
const slotNum = Number(slot);
if (!EXAM_CATALOG_TYPES.includes(type) || !Number.isInteger(slotNum) || slotNum < 1 || slotNum > 6) {
return null;
}
return `teacher.exam.${type}.${slotNum}`;
};
const getAssignmentFormat = (assignment) =>
String(assignment?.format ?? assignment?.test_format ?? assignment?.testFormat ?? "")
.trim()
.toLowerCase();
/** Coerce API boolean fields that may arrive as bool, 0/1, or string. */
export const normalizeApiBoolean = (value) => {
if (value === true || value === 1 || value === "1" || value === "true") return true;
if (value === false || value === 0 || value === "0" || value === "false") return false;
return null;
};
/** True when the district's current plan meets or exceeds a required tier (both from API). */
export const planMeetsMinimum = (currentPlan, planName, minPlan) => {
const required = resolvePlanKey(minPlan);
const current = resolvePlanKey(currentPlan, planName);
if (!required || !current) return null;
const currentIdx = getPlanTierIndex(current);
const requiredIdx = getPlanTierIndex(required);
Iif (currentIdx < 0 || requiredIdx < 0) return null;
return currentIdx >= requiredIdx;
};
const isTeacherMadeGlobalAssignment = (assignment) => {
const format = getAssignmentFormat(assignment);
if (format === "teacher-test" || format === "teacher_test" || format === "teacher-made") {
return true;
}
const source = String(assignment?.source ?? assignment?.assignment_source ?? assignment?.origin ?? "")
.trim()
.toLowerCase();
return (
source.includes("teacher-test") ||
source.includes("teacher_test") ||
assignment?.is_teacher_made === true ||
assignment?.teacher_made === true
);
};
/** Staff tiered practice globals only (format=practice), aligned with backend `is_tiered_practice_global`. */
export const isExamCatalogAssignmentCandidate = (assignment) => {
const type = String(assignment?.type || "")
.trim()
.toLowerCase();
if (!EXAM_CATALOG_TYPES.includes(type)) return false;
if (isTeacherMadeGlobalAssignment(assignment)) return false;
return getAssignmentFormat(assignment) === "practice";
};
const inferExamSlotFromTitle = (title, examType) => {
const normalizedTitle = String(title || "").trim();
Iif (!normalizedTitle) return null;
const typeUpper = String(examType || "")
.trim()
.toUpperCase();
for (const [featureKey, label] of Object.entries(EXAM_CATALOG_FEATURE_LABELS)) {
const parsed = parseExamFeatureKey(featureKey);
if (!parsed || parsed.type !== typeUpper) continue;
const labelPattern = new RegExp(`\\b${label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "i");
if (labelPattern.test(normalizedTitle)) {
return parsed.slot;
}
}
const typeLower = String(examType || "")
.trim()
.toLowerCase();
const typedPatterns = [
new RegExp(`\\b${typeLower}\\s+exam\\s*#?\\s*([1-6])\\b`, "i"),
new RegExp(`\\b${typeLower}\\s*(?:math\\s*)?(?:practice\\s*)?(?:test\\s*)?#?\\s*([1-6])\\b`, "i"),
/\b(?:test|practice)\s*#?\s*([1-6])\b/i,
];
for (const pattern of typedPatterns) {
const match = normalizedTitle.match(pattern);
const slotGroup = match?.[1];
if (slotGroup) {
const slot = Number(slotGroup);
Eif (slot >= 1 && slot <= 6) return slot;
}
}
return null;
};
const inferExamSlotFromAssignment = (assignment) => {
const slotFromField = assignment?.slot ?? assignment?.exam_slot ?? assignment?.examSlot;
if (slotFromField != null && slotFromField !== "") {
const slot = Number(slotFromField);
if (slot >= 1 && slot <= 6) return slot;
}
const type = String(assignment?.type || "")
.trim()
.toLowerCase();
return inferExamSlotFromTitle(assignment?.title, type);
};
/**
* Resolve the canonical `teacher.exam.{type}.{slot}` key for a staff global practice test.
* Returns null for teacher-made globals and non-practice formats.
*/
export const resolveExamCatalogFeatureKey = (assignment) => {
if (!isExamCatalogAssignmentCandidate(assignment)) return null;
if (isExamCatalogFeatureKey(assignment?.feature_key)) {
return assignment.feature_key;
}
const type = String(assignment?.type || "")
.trim()
.toLowerCase();
const slot = inferExamSlotFromAssignment(assignment);
if (slot == null) return null;
return buildExamCatalogFeatureKey(type, slot);
};
export const isExamCatalogAssignment = (assignment) => Boolean(resolveExamCatalogFeatureKey(assignment));
/** Assignment types stored on Erudition Library globals (non plan-catalog). */
export const ERUDITION_LIBRARY_ASSIGNMENT_TYPES = new Set(["custom-test", "teacher-test"]);
/** True for Erudition Library globals on the Tests page (any non-catalog global assignment). */
export const isEruditionLibraryAssignment = (assignment) =>
Boolean(assignment) && !isExamCatalogAssignment(assignment);
/** Type badge label for a global assignment list row or detail view. */
export const formatGlobalAssignmentTypeLabel = (assignment) => {
if (isEruditionLibraryAssignment(assignment)) {
return ERUDITION_LIBRARY_LABEL;
}
const type = String(assignment?.type || "").trim();
Iif (!type) return "—";
const normalized = type.toLowerCase();
Eif (EXAM_CATALOG_TYPES.includes(normalized)) {
return normalized.toUpperCase();
}
return type;
};
/** @deprecated Use resolveExamCatalogFeatureKey — kept for existing imports. */
export const inferExamFeatureKey = (assignment) => resolveExamCatalogFeatureKey(assignment);
/** Parse `teacher.exam.staar.3` → { type: "STAAR", slot: 3 } */
export const parseExamFeatureKey = (featureKey) => {
if (!featureKey || typeof featureKey !== "string") return null;
const match = featureKey.match(/^teacher\.exam\.(staar|tsi|sat|act)\.(\d+)$/i);
if (!match) return null;
return {
type: match[1].toUpperCase(),
slot: Number(match[2]),
};
};
/** Short display title for a catalog slot (`TSI 1`, `ACT 2`). */
export const formatExamCatalogTitle = (featureKey, examType = null, slot = null) => {
if (featureKey && EXAM_CATALOG_FEATURE_LABELS[featureKey]) {
return EXAM_CATALOG_FEATURE_LABELS[featureKey];
}
const parsed = parseExamFeatureKey(featureKey);
const type = (parsed?.type || String(examType || "").trim().toUpperCase()).trim();
const slotNum = parsed?.slot ?? Number(slot);
if (!type || !Number.isInteger(slotNum) || slotNum < 1 || slotNum > 6) {
return null;
}
return `${type} ${slotNum}`;
};
export const formatExamFeatureLabel = (featureKey) => {
if (isEruditionLibraryFeatureKey(featureKey)) {
return ERUDITION_LIBRARY_LABEL;
}
const catalogTitle = formatExamCatalogTitle(featureKey);
if (catalogTitle) return catalogTitle;
return featureKey;
};
/** Human-readable label for any plan feature key (exam catalog or global staff tests). */
export const formatFeatureKeyLabel = (featureKey) => formatExamFeatureLabel(featureKey);
/**
* Resolve whether a global-assignment row is locked.
*
* Outcomes (first match wins):
* 1. `apiAccessGranted` — detail fetch returned 200 (backend already enforced access).
* 2. Assignment row carries `locked` / `enabled` from `global_assignment_access_meta` (list API).
* 3. `featuresLoading` — effective features still loading; don't lock on a missing key.
* 4. Effective-features list — `isFeatureEnabledFn(featureKey)` (fallback when row has no hints).
*/
export const resolveAssignmentAccessLocked = (
assignment,
featureKey,
isFeatureEnabledFn,
{ featuresLoading = false, apiAccessGranted = false, currentPlan = null, planName = null } = {}
) => {
if (apiAccessGranted) {
return false;
}
const lockedHint = normalizeApiBoolean(assignment?.locked);
const enabledHint = normalizeApiBoolean(assignment?.enabled);
const hasBackendAccessHint = lockedHint != null || enabledHint != null;
if (hasBackendAccessHint) {
if (lockedHint === true || enabledHint === false) {
return true;
}
Eif (enabledHint === true || lockedHint === false) {
return false;
}
}
if (featuresLoading) {
return false;
}
if (isFeatureEnabledFn(featureKey)) {
return false;
}
// District plan + row min_plan both come from the API (effective features / list enrichment).
const planUnlock = planMeetsMinimum(currentPlan, planName, assignment?.min_plan);
if (planUnlock === true) {
return false;
}
Iif (planUnlock === false) {
return true;
}
return true;
};
export const getAssignmentAccessState = (
assignment,
features,
isFeatureEnabledFn,
options = {}
) => {
const backendFeatureKey =
typeof assignment?.feature_key === "string" && assignment.feature_key.trim()
? assignment.feature_key.trim().toLowerCase()
: null;
const featureKey = resolveCanonicalFeatureKey(
backendFeatureKey || resolveExamCatalogFeatureKey(assignment) || TEACHER_ERUDITION_TESTS_LIBRARY_KEY
);
const featureMeta = getFeatureMeta(features, featureKey);
const locked = resolveAssignmentAccessLocked(assignment, featureKey, isFeatureEnabledFn, options);
return {
featureKey,
locked,
featureMeta,
minPlan: resolveRequiredPlanForFeature(featureKey, featureMeta, assignment?.min_plan),
};
};
|