Keep practice parent links on edit and load full exam-prep practice lists.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c886802cd6
commit
4abc20d166
|
|
@ -45,8 +45,9 @@ export function parentsFromPractice(practice: {
|
|||
parent_kind?: string
|
||||
parent_id?: number
|
||||
}): PracticeParent[] {
|
||||
if (practice.parents == null) return []
|
||||
if (practice.parents.length > 0) return dedupeParents(practice.parents)
|
||||
if (Array.isArray(practice.parents) && practice.parents.length > 0) {
|
||||
return dedupeParents(practice.parents)
|
||||
}
|
||||
const kind = practice.parent_kind?.trim().toUpperCase() ?? ""
|
||||
const parent_id = practice.parent_id
|
||||
if (isPracticeParentKind(kind) && parent_id != null && parent_id > 0) {
|
||||
|
|
|
|||
|
|
@ -366,7 +366,29 @@ export function EditPracticeFlow() {
|
|||
if (cancelled) return;
|
||||
const loadedPersona =
|
||||
mapped.personaId != null ? String(mapped.personaId) : null;
|
||||
setFormData(mapped.formData);
|
||||
const lid = lessonId ? Number(lessonId) : NaN;
|
||||
const mid = moduleId ? Number(moduleId) : NaN;
|
||||
const uid = unitId ? Number(unitId) : NaN;
|
||||
const cid = courseId ? Number(courseId) : NaN;
|
||||
const routeParent: PracticeParent | null = Number.isFinite(lid) && lid > 0
|
||||
? { parent_kind: "LESSON", parent_id: lid }
|
||||
: isModuleContext && !isExamPrep && Number.isFinite(mid) && mid > 0
|
||||
? { parent_kind: "MODULE", parent_id: mid }
|
||||
: isUnitContext && isExamPrep && Number.isFinite(uid) && uid > 0
|
||||
? { parent_kind: "UNIT", parent_id: uid }
|
||||
: isCourseContext && Number.isFinite(cid) && cid > 0
|
||||
? {
|
||||
parent_kind: isExamPrep ? "CATALOG_COURSE" : "COURSE",
|
||||
parent_id: cid,
|
||||
}
|
||||
: null;
|
||||
const formParents =
|
||||
mapped.parents.length > 0
|
||||
? mapped.parents
|
||||
: routeParent
|
||||
? [routeParent]
|
||||
: mapped.formData.parents;
|
||||
setFormData({ ...mapped.formData, parents: formParents });
|
||||
setPreservedQuestionSet(mapped.preservedQuestionSet);
|
||||
initialParentsRef.current = mapped.parents;
|
||||
setLoadedPersonaId(mapped.personaId);
|
||||
|
|
@ -389,7 +411,20 @@ export function EditPracticeFlow() {
|
|||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [validPracticeId, practiceId, isExamPrep, typeDefinitions, definitionsLoading]);
|
||||
}, [
|
||||
validPracticeId,
|
||||
practiceId,
|
||||
isExamPrep,
|
||||
typeDefinitions,
|
||||
definitionsLoading,
|
||||
lessonId,
|
||||
moduleId,
|
||||
unitId,
|
||||
courseId,
|
||||
isModuleContext,
|
||||
isUnitContext,
|
||||
isCourseContext,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (loadedPersonaId == null || personasLoading) return;
|
||||
|
|
|
|||
|
|
@ -341,11 +341,11 @@ export function LessonPracticesPage() {
|
|||
: list.length,
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
} catch (error) {
|
||||
setPractices([]);
|
||||
setTotalCount(0);
|
||||
setLoadError("Could not load practices for this lesson.");
|
||||
notifyApiError(err, "Failed to load practices");
|
||||
notifyApiError(error, "Failed to load practices");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,18 +85,15 @@ export function CatalogCoursePracticesPanel({
|
|||
setLoading(true)
|
||||
setLoadError(null)
|
||||
try {
|
||||
const res = await getExamPrepCatalogCoursePractices(catalogCourseId, {
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
})
|
||||
const res = await getExamPrepCatalogCoursePractices(catalogCourseId)
|
||||
const { practices: list, totalCount: total } = extractPracticesPage(res)
|
||||
setPractices(list)
|
||||
setTotalCount(total)
|
||||
} catch {
|
||||
} catch (error) {
|
||||
setPractices([])
|
||||
setTotalCount(0)
|
||||
setLoadError("Could not load practices for this catalog course.")
|
||||
notifyApiError(err, "Failed to load practices")
|
||||
notifyApiError(error, "Failed to load practices")
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,18 +87,15 @@ export function UnitPracticesPanel({
|
|||
setLoading(true)
|
||||
setLoadError(null)
|
||||
try {
|
||||
const res = await getExamPrepUnitPractices(unitId, {
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
})
|
||||
const res = await getExamPrepUnitPractices(unitId)
|
||||
const { practices: list, totalCount: total } = extractPracticesPage(res)
|
||||
setPractices(list)
|
||||
setTotalCount(total)
|
||||
} catch {
|
||||
} catch (error) {
|
||||
setPractices([])
|
||||
setTotalCount(0)
|
||||
setLoadError("Could not load practices for this unit.")
|
||||
notifyApiError(err, "Failed to load practices")
|
||||
notifyApiError(error, "Failed to load practices")
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user