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:
Yared Yemane 2026-08-13 12:03:04 +03:00
parent c886802cd6
commit 4abc20d166
5 changed files with 48 additions and 18 deletions

View File

@ -45,8 +45,9 @@ export function parentsFromPractice(practice: {
parent_kind?: string parent_kind?: string
parent_id?: number parent_id?: number
}): PracticeParent[] { }): PracticeParent[] {
if (practice.parents == null) return [] if (Array.isArray(practice.parents) && practice.parents.length > 0) {
if (practice.parents.length > 0) return dedupeParents(practice.parents) return dedupeParents(practice.parents)
}
const kind = practice.parent_kind?.trim().toUpperCase() ?? "" const kind = practice.parent_kind?.trim().toUpperCase() ?? ""
const parent_id = practice.parent_id const parent_id = practice.parent_id
if (isPracticeParentKind(kind) && parent_id != null && parent_id > 0) { if (isPracticeParentKind(kind) && parent_id != null && parent_id > 0) {

View File

@ -366,7 +366,29 @@ export function EditPracticeFlow() {
if (cancelled) return; if (cancelled) return;
const loadedPersona = const loadedPersona =
mapped.personaId != null ? String(mapped.personaId) : null; 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); setPreservedQuestionSet(mapped.preservedQuestionSet);
initialParentsRef.current = mapped.parents; initialParentsRef.current = mapped.parents;
setLoadedPersonaId(mapped.personaId); setLoadedPersonaId(mapped.personaId);
@ -389,7 +411,20 @@ export function EditPracticeFlow() {
return () => { return () => {
cancelled = true; cancelled = true;
}; };
}, [validPracticeId, practiceId, isExamPrep, typeDefinitions, definitionsLoading]); }, [
validPracticeId,
practiceId,
isExamPrep,
typeDefinitions,
definitionsLoading,
lessonId,
moduleId,
unitId,
courseId,
isModuleContext,
isUnitContext,
isCourseContext,
]);
useEffect(() => { useEffect(() => {
if (loadedPersonaId == null || personasLoading) return; if (loadedPersonaId == null || personasLoading) return;

View File

@ -341,11 +341,11 @@ export function LessonPracticesPage() {
: list.length, : list.length,
); );
} }
} catch { } catch (error) {
setPractices([]); setPractices([]);
setTotalCount(0); setTotalCount(0);
setLoadError("Could not load practices for this lesson."); setLoadError("Could not load practices for this lesson.");
notifyApiError(err, "Failed to load practices"); notifyApiError(error, "Failed to load practices");
} finally { } finally {
setLoading(false); setLoading(false);
} }

View File

@ -85,18 +85,15 @@ export function CatalogCoursePracticesPanel({
setLoading(true) setLoading(true)
setLoadError(null) setLoadError(null)
try { try {
const res = await getExamPrepCatalogCoursePractices(catalogCourseId, { const res = await getExamPrepCatalogCoursePractices(catalogCourseId)
limit: 20,
offset: 0,
})
const { practices: list, totalCount: total } = extractPracticesPage(res) const { practices: list, totalCount: total } = extractPracticesPage(res)
setPractices(list) setPractices(list)
setTotalCount(total) setTotalCount(total)
} catch { } catch (error) {
setPractices([]) setPractices([])
setTotalCount(0) setTotalCount(0)
setLoadError("Could not load practices for this catalog course.") setLoadError("Could not load practices for this catalog course.")
notifyApiError(err, "Failed to load practices") notifyApiError(error, "Failed to load practices")
} finally { } finally {
setLoading(false) setLoading(false)
} }

View File

@ -87,18 +87,15 @@ export function UnitPracticesPanel({
setLoading(true) setLoading(true)
setLoadError(null) setLoadError(null)
try { try {
const res = await getExamPrepUnitPractices(unitId, { const res = await getExamPrepUnitPractices(unitId)
limit: 20,
offset: 0,
})
const { practices: list, totalCount: total } = extractPracticesPage(res) const { practices: list, totalCount: total } = extractPracticesPage(res)
setPractices(list) setPractices(list)
setTotalCount(total) setTotalCount(total)
} catch { } catch (error) {
setPractices([]) setPractices([])
setTotalCount(0) setTotalCount(0)
setLoadError("Could not load practices for this unit.") setLoadError("Could not load practices for this unit.")
notifyApiError(err, "Failed to load practices") notifyApiError(error, "Failed to load practices")
} finally { } finally {
setLoading(false) setLoading(false)
} }