Add Gap Offer Handling and UI Enhancements in Progression Graph Components
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m18s

- Implemented `_build_evaluate_empty_slot_gap_specs` function to generate gap offer specifications for unfilled roadmap slots in evaluate-only mode.
- Enhanced `ProgressionFindingsPanel` to display AI offers for empty slots and gaps, improving user interaction and clarity.
- Updated `ProgressionGraphEditor` and `ProgressionSlotCard` components to support new functionalities for managing slots and offers.
- Refactored utility functions in `progressionGraphDraft.js` to streamline slot management and offer handling.
- Incremented application version to reflect these updates.
This commit is contained in:
Lars committed 2026-06-10 15:34:37 +02:00
1 parent 97efe66306
commit c1bf9279ad
7 files changed
+914 -206

No files matched your search

+245 -17
View File
@@ -2,9 +2,191 @@
* Progressionsgraph Slot-Editor — Draft-Hydration und Speichern (Phase B).
*/
const ROADMAP_PHASES = ['einstieg', 'grundlage', 'vertiefung', 'anwendung', 'perfektion']
export const ROADMAP_PHASES = ['einstieg', 'grundlage', 'vertiefung', 'anwendung', 'perfektion']
export const SLOT_MAX = 10
export const PLANNING_ARTIFACT_SCHEMA = 1
const OFFER_SOURCE_LABELS = {
unfilled_gap: 'Lücke',
off_topic: 'Themenfremd',
llm_suggested: 'QS-Empfehlung',
roadmap_unfilled: 'Roadmap-Stufe',
}
export function offerSourceLabel(source) {
return OFFER_SOURCE_LABELS[source] || source || 'Angebot'
}
function createEmptySlot(index) {
const phase = ROADMAP_PHASES[Math.min(index, ROADMAP_PHASES.length - 1)]
return {
majorStepIndex: index,
phase,
learning_goal: '',
consolidates: [],
rationale: '',
load_profile: [],
success_criteria: [],
anti_patterns: [],
exercise_type: '',
primary: emptySlotExercise(),
siblings: [],
}
}
function majorStepFromSlot(slot, index) {
return {
index,
phase: slot.phase || ROADMAP_PHASES[Math.min(index, ROADMAP_PHASES.length - 1)],
learning_goal: slot.learning_goal || '',
consolidates: slot.consolidates || [],
rationale: slot.rationale || '',
load_profile: slot.load_profile || [],
success_criteria: slot.success_criteria || [],
anti_patterns: slot.anti_patterns || [],
exercise_type: slot.exercise_type || '',
}
}
export function reindexSlots(slots) {
return (slots || []).map((slot, i) => ({
...slot,
majorStepIndex: i,
primary: { ...slot.primary },
siblings: [...(slot.siblings || [])],
}))
}
/** progression_roadmap aus aktuellen Slots ableiten (nach Verschieben/Hinzufügen). */
export function syncProgressionRoadmapFromSlots(draft) {
const slots = reindexSlots(draft.slots || [])
const existing = draft.progressionRoadmap || {}
const major_steps = slots.map((s, i) => ({
index: i,
phase: s.phase || 'vertiefung',
learning_goal: (s.learning_goal || '').trim(),
consolidates: s.consolidates || [],
rationale: s.rationale || '',
}))
const stage_specs = slots.map((s, i) => ({
major_step_index: i,
learning_goal: (s.learning_goal || '').trim(),
load_profile: Array.isArray(s.load_profile) ? s.load_profile : [],
exercise_type: (s.exercise_type || '').trim(),
success_criteria: Array.isArray(s.success_criteria) ? s.success_criteria : [],
anti_patterns: Array.isArray(s.anti_patterns) ? s.anti_patterns : [],
}))
return {
...draft,
slots,
majorSteps: slots.map(majorStepFromSlot),
maxSteps: slots.length,
progressionRoadmap: {
...existing,
major_step_count: slots.length,
max_steps: slots.length,
roadmap: { ...(existing.roadmap || {}), major_steps },
stage_specs,
},
}
}
export function moveSlotInDraft(draft, slotIndex, direction) {
const slots = [...(draft.slots || [])]
const j = slotIndex + direction
if (j < 0 || j >= slots.length) return draft
const tmp = slots[slotIndex]
slots[slotIndex] = slots[j]
slots[j] = tmp
return syncProgressionRoadmapFromSlots({ ...draft, slots, dirty: true })
}
export function removeSlotFromDraft(draft, slotIndex) {
const slots = draft.slots || []
if (slots.length <= 2) return draft
const next = slots.filter((_, i) => i !== slotIndex)
return syncProgressionRoadmapFromSlots({ ...draft, slots: next, dirty: true })
}
export function insertSlotInDraft(draft, afterIndex, partial = {}) {
const slots = [...(draft.slots || [])]
if (slots.length >= SLOT_MAX) return draft
const insertAt = afterIndex < 0 ? 0 : Math.min(afterIndex + 1, slots.length)
const newSlot = {
...createEmptySlot(insertAt),
...partial,
primary: partial.primary || emptySlotExercise(),
siblings: partial.siblings || [],
}
slots.splice(insertAt, 0, newSlot)
return syncProgressionRoadmapFromSlots({ ...draft, slots, dirty: true })
}
export function addSlotToDraft(draft) {
const slots = draft.slots || []
if (slots.length >= SLOT_MAX) return draft
return syncProgressionRoadmapFromSlots({
...draft,
slots: [...slots, createEmptySlot(slots.length)],
dirty: true,
})
}
export function patchSlotInDraft(draft, slotIndex, patch) {
const slots = (draft.slots || []).map((s, i) => (i === slotIndex ? { ...s, ...patch } : s))
return syncProgressionRoadmapFromSlots({ ...draft, slots, dirty: true })
}
export function resolveOfferSlotIndex(draft, offer) {
if (offer?.roadmap_major_step_index != null && Number.isFinite(Number(offer.roadmap_major_step_index))) {
return Number(offer.roadmap_major_step_index)
}
if (offer?.replace_step_index != null && Number.isFinite(Number(offer.replace_step_index))) {
return Number(offer.replace_step_index)
}
if (offer?.insert_after_index != null && Number.isFinite(Number(offer.insert_after_index))) {
const after = Number(offer.insert_after_index)
if (offer.source === 'roadmap_unfilled') return after + 1
return Math.min(after + 1, (draft.slots?.length || 1) - 1)
}
return null
}
export function offerNeedsNewSlot(offer) {
return offer?.source === 'unfilled_gap' || offer?.source === 'llm_suggested'
}
export function offerCanExpandSlots(draft, offer) {
if (!offerNeedsNewSlot(offer)) return false
return (draft.slots?.length || 0) < SLOT_MAX
}
export function collectGapOffersFromApiResponse(res) {
const qa = res?.path_qa || {}
const merged = [
...(Array.isArray(res?.gap_fill_offers) ? res.gap_fill_offers : []),
...(Array.isArray(qa?.gap_fill_offers) ? qa.gap_fill_offers : []),
]
const seen = new Set()
return merged.filter((offer) => {
const key = offer?.offer_id || `${offer?.source}-${offer?.title_hint}`
if (!key || seen.has(key)) return false
seen.add(key)
return true
})
}
export function slotsAsPathStepRows(draft) {
return (draft.slots || []).map((slot) => ({
exerciseId: slot.primary?.exerciseId ?? null,
exerciseTitle: slot.primary?.exerciseTitle || '',
roadmapMajorStepIndex: slot.majorStepIndex,
roadmapPhase: slot.phase,
roadmapLearningGoal: slot.learning_goal,
isAiProposal: slot.primary?.kind === 'proposal',
}))
}
export function emptySlotExercise() {
return {
kind: 'empty',
@@ -487,34 +669,74 @@ export function applyMatchStepsToSlots(draft, apiSteps) {
}
}
return { ...draft, slots: nextSlots, dirty: true }
return syncProgressionRoadmapFromSlots({ ...draft, slots: nextSlots, dirty: true })
}
export function applyGapOfferToSlot(draft, slotIndex, offer, aiSuggestion = null) {
const nextSlots = (draft.slots || []).map((s) => ({ ...s, primary: { ...s.primary }, siblings: [...(s.siblings || [])] }))
if (slotIndex < 0 || slotIndex >= nextSlots.length) return draft
const title =
offer?.proposal_title ||
offer?.title_hint ||
offer?.title ||
nextSlots[slotIndex].learning_goal ||
'KI-Vorschlag'
nextSlots[slotIndex].primary = proposalSlotExercise({
title: offer?.title_hint || offer?.title || 'KI-Vorschlag',
proposalKey: offer?.offer_id || offer?.proposal_key,
title,
proposalKey: offer?.proposal_key || offer?.offer_id || null,
aiSuggestion: aiSuggestion || offer?.ai_suggestion || null,
})
return { ...draft, slots: nextSlots, dirty: true }
return syncProgressionRoadmapFromSlots({ ...draft, slots: nextSlots, dirty: true })
}
/**
* Angebot einem Slot zuordnen — optional neuen Slot einfügen (Brücke / QS-Neuanlage).
*/
export function applyGapOfferToDraft(draft, offer, { slotIndex = null, insertNewSlot = false } = {}) {
let next = { ...draft }
if (insertNewSlot && offerNeedsNewSlot(offer)) {
const afterIdx = Number(offer?.insert_after_index)
if (Number.isFinite(afterIdx)) {
if ((next.slots?.length || 0) >= SLOT_MAX) return next
next = insertSlotInDraft(next, afterIdx, {
learning_goal: (offer?.title_hint || offer?.sketch || '').trim().split('\n')[0] || '',
phase: offer?.phase || offer?.gap?.expected_phase || 'vertiefung',
})
slotIndex = afterIdx + 1
}
}
const idx = slotIndex != null ? slotIndex : resolveOfferSlotIndex(next, offer)
if (idx == null || !Number.isFinite(idx) || idx < 0 || idx >= (next.slots?.length || 0)) {
return next
}
return applyGapOfferToSlot(next, idx, offer)
}
export async function saveProgressionGraphDraft(api, graphId, draft) {
const primarySteps = draftPrimaryChainSteps(draft)
const siblingPairs = draftSiblingEdgePairs(draft)
const artifact = buildPlanningArtifactFromDraft(draft)
const edgeIds = [
...(draft.primaryChainEdgeIds || []),
...(draft.siblingEdgeIds || []),
].filter((id) => Number.isFinite(Number(id)))
const synced = syncProgressionRoadmapFromSlots(draft)
const primarySteps = draftPrimaryChainSteps(synced)
const siblingPairs = draftSiblingEdgePairs(synced)
const artifact = buildPlanningArtifactFromDraft(synced)
if (edgeIds.length > 0) {
await api.deleteExerciseProgressionEdgesBatch(Number(graphId), edgeIds)
}
// Kanten frisch laden — hydrate-Arrays können nach Zwischen-Speichern veraltet sein.
const currentEdges = await api.listExerciseProgressionEdges(Number(graphId))
const nextEdgeIds = (currentEdges || [])
.filter((e) => (e.edge_type || 'next_exercise') === 'next_exercise')
.map((e) => e.id)
.filter((id) => Number.isFinite(Number(id)))
const siblingEdgeIds = (currentEdges || [])
.filter((e) => e.edge_type === 'sibling')
.map((e) => e.id)
.filter((id) => Number.isFinite(Number(id)))
let artifactPersisted = false
// Primärkette nur ersetzen, wenn mindestens zwei Bibliotheks-Übungen im Pfad sind.
// Sonst bestehende next_exercise-Kanten erhalten (nur Artefakt/Slots speichern).
if (primarySteps.length >= 2) {
if (nextEdgeIds.length > 0) {
await api.deleteExerciseProgressionEdgesBatch(Number(graphId), nextEdgeIds)
}
await api.createExerciseProgressionSequence(Number(graphId), {
steps: primarySteps.map((s) => ({
exercise_id: s.exerciseId,
@@ -523,10 +745,12 @@ export async function saveProgressionGraphDraft(api, graphId, draft) {
segment_notes: primarySteps.slice(1).map(() => null),
...(artifact ? { planning_roadmap: artifact } : {}),
})
} else if (artifact) {
await api.updateExerciseProgressionGraph(Number(graphId), { planning_roadmap: artifact })
artifactPersisted = Boolean(artifact)
}
if (siblingEdgeIds.length > 0) {
await api.deleteExerciseProgressionEdgesBatch(Number(graphId), siblingEdgeIds)
}
for (const pair of siblingPairs) {
await api.createExerciseProgressionEdge(Number(graphId), {
from_exercise_id: pair.from.exerciseId,
@@ -537,5 +761,9 @@ export async function saveProgressionGraphDraft(api, graphId, draft) {
})
}
if (artifact && !artifactPersisted) {
await api.updateExerciseProgressionGraph(Number(graphId), { planning_roadmap: artifact })
}
return { primaryCount: primarySteps.length, siblingCount: siblingPairs.length }
}