Manage one initial assessment question set per CEFR level.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
de9766be7b
commit
8e7226b370
|
|
@ -211,31 +211,49 @@ function unwrapQuestionSets(body: unknown): Array<Record<string, unknown>> {
|
|||
return []
|
||||
}
|
||||
|
||||
function pickStandalonePlacement(sets: Array<Record<string, unknown>>): Record<string, unknown> | null {
|
||||
const publishedStandalone = sets.find((set) => {
|
||||
const CEFR_LEVELS: CefrLevel[] = ["A1", "A2", "B1", "B2", "C1", "C2"]
|
||||
|
||||
function isCefrLevel(value: string): value is CefrLevel {
|
||||
return (CEFR_LEVELS as string[]).includes(value)
|
||||
}
|
||||
|
||||
function setLevel(set: Record<string, unknown>): CefrLevel | null {
|
||||
const level = String(set.description ?? "").trim().toUpperCase()
|
||||
return isCefrLevel(level) ? level : null
|
||||
}
|
||||
|
||||
function pickSetForLevel(
|
||||
sets: Array<Record<string, unknown>>,
|
||||
level: CefrLevel,
|
||||
): Record<string, unknown> | null {
|
||||
const matching = sets.filter((set) => setLevel(set) === level)
|
||||
if (matching.length === 0) return null
|
||||
|
||||
const publishedStandalone = matching.find((set) => {
|
||||
const status = String(set.status ?? "").toUpperCase()
|
||||
const owner = String(set.owner_type ?? "STANDALONE").toUpperCase()
|
||||
return status === "PUBLISHED" && (owner === "STANDALONE" || owner === "")
|
||||
})
|
||||
if (publishedStandalone) return publishedStandalone
|
||||
|
||||
const anyStandalone = sets.find((set) => {
|
||||
const anyStandalone = matching.find((set) => {
|
||||
const owner = String(set.owner_type ?? "STANDALONE").toUpperCase()
|
||||
return owner === "STANDALONE" || owner === ""
|
||||
})
|
||||
if (anyStandalone) return anyStandalone
|
||||
|
||||
return sets[0] ?? null
|
||||
const published = matching.find((set) => String(set.status ?? "").toUpperCase() === "PUBLISHED")
|
||||
return published ?? matching[0] ?? null
|
||||
}
|
||||
|
||||
export async function findPlacementAssessmentSet(): Promise<QuestionSetDetail | null> {
|
||||
export async function findPlacementAssessmentSet(level: CefrLevel): Promise<QuestionSetDetail | null> {
|
||||
const res = await getQuestionSets({
|
||||
set_type: "INITIAL_ASSESSMENT",
|
||||
limit: 50,
|
||||
limit: 100,
|
||||
offset: 0,
|
||||
})
|
||||
const sets = unwrapQuestionSets(res.data)
|
||||
const picked = pickStandalonePlacement(sets)
|
||||
const picked = pickSetForLevel(sets, level)
|
||||
if (!picked) return null
|
||||
const id = Number(picked.id)
|
||||
if (!Number.isFinite(id)) return null
|
||||
|
|
@ -245,11 +263,15 @@ export async function findPlacementAssessmentSet(): Promise<QuestionSetDetail |
|
|||
|
||||
export async function createPlacementAssessmentSet(input?: {
|
||||
title?: string
|
||||
description?: string
|
||||
level: CefrLevel
|
||||
}): Promise<QuestionSetDetail> {
|
||||
const level = input?.level
|
||||
if (!level) {
|
||||
throw new Error("Placement set level is required")
|
||||
}
|
||||
const payload: CreateQuestionSetRequest = {
|
||||
title: input?.title?.trim() || "Initial Placement Assessment",
|
||||
description: input?.description?.trim() || "PLACEMENT",
|
||||
title: input?.title?.trim() || `Initial Placement Assessment — ${level}`,
|
||||
description: level,
|
||||
set_type: "INITIAL_ASSESSMENT",
|
||||
owner_type: "STANDALONE",
|
||||
owner_id: null,
|
||||
|
|
@ -269,10 +291,10 @@ export async function createPlacementAssessmentSet(input?: {
|
|||
return detailRes.data.data
|
||||
}
|
||||
|
||||
export async function ensurePlacementAssessmentSet(): Promise<QuestionSetDetail> {
|
||||
const existing = await findPlacementAssessmentSet()
|
||||
export async function ensurePlacementAssessmentSet(level: CefrLevel): Promise<QuestionSetDetail> {
|
||||
const existing = await findPlacementAssessmentSet(level)
|
||||
if (existing) return existing
|
||||
return createPlacementAssessmentSet()
|
||||
return createPlacementAssessmentSet({ level })
|
||||
}
|
||||
|
||||
export async function savePlacementAssessmentSet(
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import {
|
|||
getPlacementQuestionDetail,
|
||||
listPlacementQuestions,
|
||||
savePlacementAssessmentSet,
|
||||
type CefrLevel,
|
||||
type PlacementQuestionDetail,
|
||||
type PlacementQuestionRow,
|
||||
} from "../../api/initial-assessment.api"
|
||||
|
|
@ -177,13 +178,15 @@ function normalizeTimeLimitValue(raw: number | null | undefined): string {
|
|||
return raw != null && raw > 0 ? String(raw) : ""
|
||||
}
|
||||
|
||||
const CEFR_LEVELS: CefrLevel[] = ["A1", "A2", "B1", "B2", "C1", "C2"]
|
||||
|
||||
export function InitialAssessmentPage() {
|
||||
const [tab, setTab] = useState<TabId>("set")
|
||||
const [selectedLevel, setSelectedLevel] = useState<CefrLevel>("A1")
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [savingSet, setSavingSet] = useState(false)
|
||||
const [setDetail, setSetDetail] = useState<QuestionSetDetail | null>(null)
|
||||
const [title, setTitle] = useState("")
|
||||
const [description, setDescription] = useState("PLACEMENT")
|
||||
const [status, setStatus] = useState("DRAFT")
|
||||
const [shuffle, setShuffle] = useState(false)
|
||||
const [timeLimit, setTimeLimit] = useState<string>("")
|
||||
|
|
@ -206,27 +209,24 @@ export function InitialAssessmentPage() {
|
|||
|
||||
const setFormDirty = useMemo(() => {
|
||||
if (!setDetail) return false
|
||||
const savedTitle = setDetail.title || "Initial Placement Assessment"
|
||||
const savedDescription = setDetail.description || "PLACEMENT"
|
||||
const savedTitle = setDetail.title || `Initial Placement Assessment — ${selectedLevel}`
|
||||
const savedShuffle = Boolean(setDetail.shuffle_questions)
|
||||
const savedTimeLimit = normalizeTimeLimitValue(setDetail.time_limit_minutes)
|
||||
return (
|
||||
title.trim() !== savedTitle.trim() ||
|
||||
(description.trim() || "PLACEMENT") !== savedDescription.trim() ||
|
||||
shuffle !== savedShuffle ||
|
||||
timeLimit.trim() !== savedTimeLimit
|
||||
)
|
||||
}, [setDetail, title, description, shuffle, timeLimit])
|
||||
}, [setDetail, title, shuffle, timeLimit, selectedLevel])
|
||||
|
||||
const questionFormDirty = useMemo(() => !draftsEqual(draft, draftBaseline), [draft, draftBaseline])
|
||||
|
||||
const loadSet = useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const detail = await ensurePlacementAssessmentSet()
|
||||
const detail = await ensurePlacementAssessmentSet(selectedLevel)
|
||||
setSetDetail(detail)
|
||||
setTitle(detail.title || "Initial Placement Assessment")
|
||||
setDescription(detail.description || "PLACEMENT")
|
||||
setTitle(detail.title || `Initial Placement Assessment — ${selectedLevel}`)
|
||||
setStatus(String(detail.status || "DRAFT").toUpperCase())
|
||||
setShuffle(Boolean(detail.shuffle_questions))
|
||||
setTimeLimit(normalizeTimeLimitValue(detail.time_limit_minutes))
|
||||
|
|
@ -237,7 +237,7 @@ export function InitialAssessmentPage() {
|
|||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
}, [selectedLevel])
|
||||
|
||||
const loadQuestions = useCallback(async (setId: number) => {
|
||||
setQuestionsLoading(true)
|
||||
|
|
@ -322,7 +322,7 @@ export function InitialAssessmentPage() {
|
|||
try {
|
||||
const updated = await savePlacementAssessmentSet(setDetail.id, {
|
||||
title: title.trim(),
|
||||
description: description.trim() || "PLACEMENT",
|
||||
description: selectedLevel,
|
||||
status,
|
||||
shuffle_questions: shuffle,
|
||||
time_limit_minutes: timeLimit.trim() ? Number(timeLimit) : null,
|
||||
|
|
@ -359,7 +359,7 @@ export function InitialAssessmentPage() {
|
|||
const nextStatus = nextPublished ? "PUBLISHED" : "DRAFT"
|
||||
const updated = await savePlacementAssessmentSet(setDetail.id, {
|
||||
title: title.trim() || setDetail.title,
|
||||
description: description.trim() || "PLACEMENT",
|
||||
description: selectedLevel,
|
||||
status: nextStatus,
|
||||
shuffle_questions: shuffle,
|
||||
time_limit_minutes: timeLimit.trim() ? Number(timeLimit) : null,
|
||||
|
|
@ -368,7 +368,11 @@ export function InitialAssessmentPage() {
|
|||
})
|
||||
setSetDetail(updated)
|
||||
setStatus(nextStatus)
|
||||
toast.success(nextPublished ? "Placement assessment published" : "Placement assessment unpublished")
|
||||
toast.success(
|
||||
nextPublished
|
||||
? `${selectedLevel} placement set published`
|
||||
: `${selectedLevel} placement set unpublished`,
|
||||
)
|
||||
} catch (e) {
|
||||
notifyApiError(e, "Failed to update publish status")
|
||||
} finally {
|
||||
|
|
@ -577,13 +581,13 @@ export function InitialAssessmentPage() {
|
|||
Initial placement assessment
|
||||
</h1>
|
||||
<p className="mt-1.5 max-w-2xl text-sm text-grayScale-500">
|
||||
Manage the single learner placement test, its questions, and the A1–C2 score thresholds used
|
||||
when grading submissions.
|
||||
Manage one question set per CEFR level (A1–C2). Learners progress upward when they pass
|
||||
each level's pass score; failing stops and assigns the highest level they passed.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Badge variant={published ? "success" : "secondary"}>
|
||||
{published ? "Published" : "Draft"}
|
||||
{selectedLevel} · {published ? "Published" : "Draft"}
|
||||
</Badge>
|
||||
<div className="flex items-center gap-2 rounded-xl border border-grayScale-200 bg-white px-3 py-2">
|
||||
<span className="text-xs font-medium text-grayScale-500">Live for learners</span>
|
||||
|
|
@ -591,7 +595,7 @@ export function InitialAssessmentPage() {
|
|||
checked={published}
|
||||
onCheckedChange={() => void handlePublishToggle(!published)}
|
||||
disabled={savingSet}
|
||||
aria-label="Publish placement assessment"
|
||||
aria-label={`Publish ${selectedLevel} placement assessment`}
|
||||
/>
|
||||
</div>
|
||||
<Button type="button" variant="outline" size="sm" onClick={() => void loadSet()} disabled={loading}>
|
||||
|
|
@ -601,6 +605,33 @@ export function InitialAssessmentPage() {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="mb-6 flex flex-wrap gap-2"
|
||||
role="tablist"
|
||||
aria-label="CEFR placement level"
|
||||
>
|
||||
{CEFR_LEVELS.map((level) => {
|
||||
const selected = selectedLevel === level
|
||||
return (
|
||||
<button
|
||||
key={level}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={selected}
|
||||
onClick={() => setSelectedLevel(level)}
|
||||
className={cn(
|
||||
"rounded-full px-3.5 py-1.5 text-sm font-semibold transition",
|
||||
selected
|
||||
? "bg-brand-500 text-white"
|
||||
: "border border-grayScale-200 bg-white text-grayScale-600 hover:border-grayScale-300",
|
||||
)}
|
||||
>
|
||||
{level}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="mb-6 grid gap-3 sm:grid-cols-2">
|
||||
<Card className="rounded-xl border-grayScale-200/70 shadow-sm">
|
||||
<CardContent className="flex items-center gap-3 p-4">
|
||||
|
|
@ -627,9 +658,9 @@ export function InitialAssessmentPage() {
|
|||
<div className="mb-6 flex gap-1 overflow-x-auto border-b border-grayScale-100">
|
||||
{(
|
||||
[
|
||||
{ id: "set", label: "Placement set" },
|
||||
{ id: "set", label: `${selectedLevel} set` },
|
||||
{ id: "questions", label: "Questions" },
|
||||
{ id: "thresholds", label: "Score thresholds" },
|
||||
{ id: "thresholds", label: "Pass thresholds" },
|
||||
] as const
|
||||
).map((item) => (
|
||||
<button
|
||||
|
|
@ -669,14 +700,12 @@ export function InitialAssessmentPage() {
|
|||
</label>
|
||||
<label className="space-y-1.5 sm:col-span-2">
|
||||
<span className="text-xs font-semibold uppercase tracking-wide text-grayScale-400">
|
||||
Description
|
||||
CEFR level
|
||||
</span>
|
||||
<Input value={selectedLevel} disabled readOnly />
|
||||
<span className="text-xs text-grayScale-400">
|
||||
Each level has its own published set. Switch levels with the chips above.
|
||||
</span>
|
||||
<Textarea
|
||||
rows={3}
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="Short description for admins"
|
||||
/>
|
||||
</label>
|
||||
<label className="space-y-1.5">
|
||||
<span className="text-xs font-semibold uppercase tracking-wide text-grayScale-400">
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ import { SpinnerIcon } from "../../components/ui/spinner-icon"
|
|||
const LEVEL_ORDER = ["A1", "A2", "B1", "B2", "C1", "C2"] as const
|
||||
|
||||
const DEFAULTS: InitialAssessmentLevelThreshold[] = [
|
||||
{ level: "A1", min_percent: 0, display_order: 1 },
|
||||
{ level: "A2", min_percent: 17, display_order: 2 },
|
||||
{ level: "B1", min_percent: 34, display_order: 3 },
|
||||
{ level: "B2", min_percent: 51, display_order: 4 },
|
||||
{ level: "C1", min_percent: 68, display_order: 5 },
|
||||
{ level: "C2", min_percent: 85, display_order: 6 },
|
||||
{ level: "A1", min_percent: 70, display_order: 1 },
|
||||
{ level: "A2", min_percent: 70, display_order: 2 },
|
||||
{ level: "B1", min_percent: 70, display_order: 3 },
|
||||
{ level: "B2", min_percent: 70, display_order: 4 },
|
||||
{ level: "C1", min_percent: 70, display_order: 5 },
|
||||
{ level: "C2", min_percent: 70, display_order: 6 },
|
||||
]
|
||||
|
||||
function ensureAllLevels(rows: InitialAssessmentLevelThreshold[]): InitialAssessmentLevelThreshold[] {
|
||||
|
|
@ -37,14 +37,10 @@ function ensureAllLevels(rows: InitialAssessmentLevelThreshold[]): InitialAssess
|
|||
}
|
||||
|
||||
function validateRows(rows: InitialAssessmentLevelThreshold[]): string | null {
|
||||
if (rows[0]?.min_percent !== 0) return "A1 minimum score must be 0%."
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const value = rows[i].min_percent
|
||||
if (!Number.isFinite(value) || value < 0 || value > 100) {
|
||||
return `${rows[i].level} minimum must be between 0 and 100.`
|
||||
}
|
||||
if (i > 0 && value <= rows[i - 1].min_percent) {
|
||||
return `${rows[i].level} minimum must be greater than ${rows[i - 1].level}.`
|
||||
return `${rows[i].level} pass score must be between 0 and 100.`
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
|
@ -143,8 +139,9 @@ export function InitialAssessmentThresholdsTab() {
|
|||
</CardTitle>
|
||||
</div>
|
||||
<p className="text-sm text-grayScale-500">
|
||||
Map placement score percentage to CEFR levels A1–C2. Learners receive the highest
|
||||
level whose minimum they meet.
|
||||
Pass score (%) required to clear each CEFR level's question set and continue to the
|
||||
next level. Failing a level finalizes the learner at the highest level they already
|
||||
passed (A1 if none).
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
|
|
@ -166,14 +163,13 @@ export function InitialAssessmentThresholdsTab() {
|
|||
className="flex flex-col gap-1.5 rounded-xl border border-grayScale-200 bg-white p-4"
|
||||
>
|
||||
<span className="text-sm font-semibold text-grayScale-800">{row.level}</span>
|
||||
<span className="text-xs text-grayScale-400">Minimum score (%)</span>
|
||||
<span className="text-xs text-grayScale-400">Pass score (%)</span>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step={1}
|
||||
value={row.min_percent}
|
||||
disabled={row.level === "A1"}
|
||||
onChange={(e) => updateMin(row.level, e.target.value)}
|
||||
className="h-9"
|
||||
/>
|
||||
|
|
@ -181,8 +177,8 @@ export function InitialAssessmentThresholdsTab() {
|
|||
))}
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-grayScale-400">
|
||||
Learners get the highest level whose minimum score they meet. A1 starts at 0%. Manage the
|
||||
placement test and its questions under{" "}
|
||||
Learners start at A1 and advance only when they meet that level's pass score. Configure
|
||||
one question set per level under{" "}
|
||||
<Link to="/new-content/initial-assessment" className="font-medium text-brand-600 hover:underline">
|
||||
Content → Initial assessment
|
||||
</Link>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user