Restyle admin tables and remove retired type and legacy archive views

This commit is contained in:
Yared Yemane 2026-11-03 12:32:21 +03:00
parent 7ae57b93f4
commit fedb7b0fbe
7 changed files with 77 additions and 65 deletions

View File

@ -203,3 +203,14 @@ test("new makeup subscriptions default to the supported backend category", async
const form = await loadModule("src/pages/settings/components/CreateSubscriptionPlanDialog.shared.ts") const form = await loadModule("src/pages/settings/components/CreateSubscriptionPlanDialog.shared.ts")
assert.equal(form.EMPTY_SUBSCRIPTION_PLAN_DRAFT.category, "EDUCATION") assert.equal(form.EMPTY_SUBSCRIPTION_PLAN_DRAFT.category, "EDUCATION")
}) })
test("retired Audio Conversation is excluded while historical reads remain available", async () => {
const retired = {id: 10, key: "audio_conversation_type", display_name: "Audio Conversation", status: "INACTIVE"}
const current = {id: 11, key: "makeup_knowledge_check", display_name: "Makeup knowledge check", status: "ACTIVE"}
const api = await loadModule("src/api/questionTypeDefinitions.api.ts", {get: async (path) => ({data:{data: path.endsWith("/10") ? retired : {definitions:[retired,current],total_count:2}}})})
const result = await api.getQuestionTypeDefinitions()
assert.deepEqual(result.definitions.map(def => def.key), ["makeup_knowledge_check"])
assert.equal(result.total_count,1)
assert.equal((await api.getQuestionTypeDefinitionById(10)).key,"audio_conversation_type")
})

View File

@ -354,7 +354,7 @@ async function fetchQuestionTypeDefinitionsPage(
* Lists question type definitions. When `limit` / `offset` are omitted, fetches every page * Lists question type definitions. When `limit` / `offset` are omitted, fetches every page
* so dropdowns receive the full catalog (the API defaults to a capped page size). * so dropdowns receive the full catalog (the API defaults to a capped page size).
*/ */
export async function getQuestionTypeDefinitions( async function getQuestionTypeDefinitionsIncludingRetired(
params?: QuestionTypeDefinitionsListParams, params?: QuestionTypeDefinitionsListParams,
): Promise<QuestionTypeDefinitionsListResult> { ): Promise<QuestionTypeDefinitionsListResult> {
const hasExplicitPagination = params?.limit !== undefined || params?.offset !== undefined const hasExplicitPagination = params?.limit !== undefined || params?.offset !== undefined
@ -644,3 +644,13 @@ export async function getQuestionTypeDefinitionPractices(
const raw = unwrapApiPayload(res) ?? res.data const raw = unwrapApiPayload(res) ?? res.data
return parsePracticesPage(raw, definitionId, params) return parsePracticesPage(raw, definitionId, params)
} }
/** Retired language-learning types are excluded from new authoring, including older servers. */
export async function getQuestionTypeDefinitions(
params?: QuestionTypeDefinitionsListParams,
): Promise<QuestionTypeDefinitionsListResult> {
const result = await getQuestionTypeDefinitionsIncludingRetired(params)
const definitions = result.definitions.filter((definition) => definition.key !== "audio_conversation_type")
const hidden = result.definitions.length - definitions.length
return { ...result, definitions, total_count: Math.max(0, (result.total_count ?? result.definitions.length) - hidden) }
}

View File

@ -106,7 +106,7 @@ export function DynamicTableBuilder({
</p> </p>
<div className="overflow-x-auto rounded-xl border border-grayScale-200 bg-white"> <div className="overflow-x-auto rounded-xl border border-grayScale-200 bg-white">
<table className="w-full min-w-[320px] border-collapse text-sm"> <table className="admin-data-table w-full min-w-[320px] border-collapse text-sm">
<thead> <thead>
<tr className="bg-grayScale-50/90"> <tr className="bg-grayScale-50/90">
{table.columns.map((col, colIndex) => ( {table.columns.map((col, colIndex) => (
@ -216,7 +216,7 @@ export function DynamicTableBuilder({
Learner preview Learner preview
</p> </p>
<div className="overflow-x-auto rounded-lg border border-grayScale-200 bg-white"> <div className="overflow-x-auto rounded-lg border border-grayScale-200 bg-white">
<table className={cn("w-full min-w-[240px] border-collapse text-sm text-grayScale-800")}> <table className={cn("admin-data-table w-full min-w-[240px] border-collapse text-sm text-grayScale-800")}>
<thead> <thead>
<tr className="bg-brand-50/80"> <tr className="bg-brand-50/80">
{previewColumns.map((col, i) => ( {previewColumns.map((col, i) => (

View File

@ -12,7 +12,7 @@ export const Table = React.forwardRef<HTMLTableElement, TableProps>(
<table ref={ref} className={cn("admin-data-table w-full caption-bottom text-sm", className)} {...props} /> <table ref={ref} className={cn("admin-data-table w-full caption-bottom text-sm", className)} {...props} />
) )
if (noWrapper) return table if (noWrapper) return table
return <div className="relative w-full min-w-0 overflow-auto overscroll-x-contain [-webkit-overflow-scrolling:touch]">{table}</div> return <div className="relative w-full min-w-0 rounded-[3px] border border-grayScale-200 overflow-auto overscroll-x-contain [-webkit-overflow-scrolling:touch]">{table}</div>
}, },
) )
Table.displayName = "Table" Table.displayName = "Table"
@ -53,7 +53,7 @@ export const TableHead = React.forwardRef<HTMLTableCellElement, React.ThHTMLAttr
({ className, ...props }, ref) => ( ({ className, ...props }, ref) => (
<th <th
ref={ref} ref={ref}
className={cn("h-12 px-3 text-left align-middle text-[11px] font-semibold uppercase tracking-[0.07em] text-grayScale-500 sm:px-4 [&:has([role=checkbox])]:pr-0", className)} className={cn("h-10 px-3 text-left align-middle text-[13px] font-medium text-grayScale-700 [&:has([role=checkbox])]:pr-0", className)}
{...props} {...props}
/> />
), ),
@ -62,7 +62,7 @@ TableHead.displayName = "TableHead"
export const TableCell = React.forwardRef<HTMLTableCellElement, React.TdHTMLAttributes<HTMLTableCellElement>>( export const TableCell = React.forwardRef<HTMLTableCellElement, React.TdHTMLAttributes<HTMLTableCellElement>>(
({ className, ...props }, ref) => ( ({ className, ...props }, ref) => (
<td ref={ref} className={cn("p-3 align-middle sm:p-4 [&:has([role=checkbox])]:pr-0", className)} {...props} /> <td ref={ref} className={cn("px-3 py-2.5 align-middle [&:has([role=checkbox])]:pr-0", className)} {...props} />
), ),
) )
TableCell.displayName = "TableCell" TableCell.displayName = "TableCell"

View File

@ -791,79 +791,78 @@
@layer components { @layer components {
.admin-data-table { .admin-data-table {
--table-header: #111111; --table-header: #f8f9fa;
--table-header-text: #ffffff; --table-header-text: #343a40;
--table-row: #ffffff; --table-row: #ffffff;
--table-hover: #f5f5f5; --table-stripe: #fafafa;
--table-selected: #e8e8e8; --table-hover: #fff1b8;
--table-divider: #e5e5e5; --table-selected: #626fc1;
--table-edge: #737373; --table-divider: #d3d6da;
--table-edge: #525fbd;
border-collapse: collapse; border-collapse: collapse;
border: 1px solid var(--table-divider);
background: var(--table-row);
font-variant-numeric: tabular-nums; font-variant-numeric: tabular-nums;
font-size: 13px;
} }
.admin-data-table > thead > tr { background: var(--table-header); border-bottom: 1px solid var(--table-divider); }
.admin-data-table > thead > tr { .admin-data-table > thead > tr > :is(th, td) {
background: var(--table-header); height: 40px;
border-bottom: 3px solid var(--table-edge); padding: 9px 12px;
}
.admin-data-table > thead > tr > th {
height: 54px;
padding-top: 17px;
padding-bottom: 17px;
background: var(--table-header); background: var(--table-header);
color: var(--table-header-text); color: var(--table-header-text);
font-size: 12px; font-size: 13px;
font-weight: 600; font-weight: 500;
line-height: 1.4;
letter-spacing: 0; letter-spacing: 0;
text-transform: none; text-transform: none;
border-right: 1px solid #ffffff14; border: 1px solid var(--table-divider);
vertical-align: middle;
} }
.admin-data-table > thead > tr > th:last-child { border-right: 0; }
.admin-data-table > thead :is(button, svg) { color: inherit; } .admin-data-table > thead :is(button, svg) { color: inherit; }
.admin-data-table > thead input { min-height: 30px; border-radius: 2px; font-size: 12px; box-shadow: none; }
.admin-data-table > tbody > tr { .admin-data-table > tbody > tr {
--table-current-row: var(--table-row); --table-current-row: var(--table-row);
--table-current-edge: transparent;
background: var(--table-current-row); background: var(--table-current-row);
border-bottom: 1px solid var(--table-divider); border-bottom: 1px solid var(--table-divider);
transition: background-color 140ms ease; transition: background-color 120ms ease;
} }
.admin-data-table > tbody > tr:nth-child(even) { --table-current-row: var(--table-stripe); }
.admin-data-table > tbody > tr:hover:not(:has(td[colspan])), .admin-data-table > tbody > tr:hover:not(:has(td[colspan])),
.admin-data-table > tbody > tr:focus-within { .admin-data-table > tbody > tr:focus-within { --table-current-row: var(--table-hover); }
--table-current-row: var(--table-hover); .admin-data-table > tbody > tr > td {
--table-current-edge: var(--table-edge); padding: 10px 12px;
border: 1px solid var(--table-divider);
line-height: 1.45;
vertical-align: middle;
} }
.admin-data-table > tbody > tr[data-state="selected"], .admin-data-table > tbody > tr[data-state="selected"],
.admin-data-table > tbody > tr[aria-selected="true"],
.admin-data-table > tbody > tr:has(input[type="checkbox"]:checked), .admin-data-table > tbody > tr:has(input[type="checkbox"]:checked),
.admin-data-table > tbody > tr:has([role="checkbox"][data-state="checked"]) { .admin-data-table > tbody > tr:has([role="checkbox"][data-state="checked"]) {
--table-current-row: var(--table-selected); --table-current-row: var(--table-selected);
--table-current-edge: var(--table-edge); color: #ffffff;
} }
.admin-data-table > tbody > tr:is([data-state="selected"], [aria-selected="true"]) > td,
.admin-data-table > tbody > tr:last-child { border-bottom: 0; } .admin-data-table > tbody > tr:has(input[type="checkbox"]:checked) > td,
.admin-data-table > tbody > tr > td:not([colspan]) { padding-top: 20px; padding-bottom: 20px; } .admin-data-table > tbody > tr:has([role="checkbox"][data-state="checked"]) > td { color: #ffffff; }
.admin-data-table > tbody > tr > td:first-child:not([colspan]) { box-shadow: inset 3px 0 var(--table-current-edge); } .admin-data-table > tbody > tr:is([data-state="selected"], [aria-selected="true"]) :is(a, button:not([class*="bg-"]), [class*="text-grayScale-"]),
.admin-data-table > tbody > tr:has(input[type="checkbox"]:checked) :is(a, button:not([class*="bg-"]), [class*="text-grayScale-"]) { color: inherit; }
.admin-data-table > tbody > tr > td.sticky { background: var(--table-current-row); } .admin-data-table > tbody > tr > td.sticky { background: var(--table-current-row); }
.admin-data-table input[type="checkbox"] { accent-color: var(--table-edge); } .admin-data-table input[type="checkbox"] { accent-color: var(--table-edge); }
.admin-data-table > tfoot { background: var(--table-hover); border-top: 2px solid var(--table-divider); } .admin-data-table > tfoot { background: var(--table-header); border-top: 1px solid var(--table-divider); }
.admin-data-table > tfoot > tr > td { padding: 10px 12px; border: 1px solid var(--table-divider); }
html.dark .admin-data-table { html.dark .admin-data-table {
--table-header: #111111; --table-header: #25282d;
--table-header-text: #fafafa; --table-header-text: #eeeeee;
--table-row: #262626; --table-row: #191b1f;
--table-hover: #333333; --table-stripe: #202227;
--table-selected: #404040; --table-hover: #453d25;
--table-divider: #404040; --table-selected: #414d96;
--table-edge: #bdbdbd; --table-divider: #41454b;
} --table-edge: #aab4ff;
@media (prefers-reduced-motion: reduce) {
.admin-data-table > tbody > tr { transition: none; }
} }
@media (prefers-reduced-motion: reduce) { .admin-data-table > tbody > tr { transition: none; } }
} }
@layer components { @layer components {

View File

@ -32,7 +32,6 @@ export function LearningHierarchyPage() {
const [failed, setFailed] = useState(false) const [failed, setFailed] = useState(false)
const [busy, setBusy] = useState(false) const [busy, setBusy] = useState(false)
const [search, setSearch] = useState("") const [search, setSearch] = useState("")
const [showLegacy, setShowLegacy] = useState(false)
const [editor, setEditor] = useState<Editor | null>(null) const [editor, setEditor] = useState<Editor | null>(null)
const [deleting, setDeleting] = useState<{ item: Item; kind: Kind } | null>(null) const [deleting, setDeleting] = useState<{ item: Item; kind: Kind } | null>(null)
const [form, setForm] = useState({ name: "", description: "", thumbnail: "", video_url: "", access_tier: "FREE" }) const [form, setForm] = useState({ name: "", description: "", thumbnail: "", video_url: "", access_tier: "FREE" })
@ -112,13 +111,13 @@ export function LearningHierarchyPage() {
finally { setBusy(false) } finally { setBusy(false) }
} }
const title = chapter?.name ?? course?.name ?? "Courses" const title = chapter?.name ?? course?.name ?? "Courses"
const matches = (item: Item) => (kind !== "course" || !!item.is_archived === showLegacy) && (item.name ?? item.title ?? "").toLowerCase().includes(search.toLowerCase()) const matches = (item: Item) => (kind !== "course" || !item.is_archived) && (item.name ?? item.title ?? "").toLowerCase().includes(search.toLowerCase())
function card(item: Item, itemKind: Kind, index?: number) { function card(item: Item, itemKind: Kind, index?: number) {
return <article key={item.id} className="rounded-xl border border-grayScale-200 bg-white p-5 dark:bg-grayScale-50"> return <article key={item.id} className="rounded-xl border border-grayScale-200 bg-white p-5 dark:bg-grayScale-50">
<div className="flex flex-wrap items-start justify-between gap-3"> <div className="flex flex-wrap items-start justify-between gap-3">
<div className="min-w-0"><h3 className="text-lg font-semibold">{item.name ?? item.title}</h3><p className="mt-1 text-sm text-grayScale-500">{item.publish_status === "PUBLISHED" ? "Published" : "Draft"}{item.access_tier ? ` · ${item.access_tier.toLowerCase()}` : ""}</p></div> <div className="min-w-0"><h3 className="text-lg font-semibold">{item.name ?? item.title}</h3><p className="mt-1 text-sm text-grayScale-500">{item.publish_status === "PUBLISHED" ? "Published" : "Draft"}{item.access_tier ? ` · ${item.access_tier.toLowerCase()}` : ""}</p></div>
<div className="flex gap-1"> <div className="flex gap-1">
{index !== undefined && !search && !showLegacy && <><Button size="icon" variant="ghost" disabled={busy || index === movableIndices[0]} onClick={() => void move(index, -1)} aria-label="Move up"><ArrowUp size={16} /></Button><Button size="icon" variant="ghost" disabled={busy || index === movableIndices[movableIndices.length - 1]} onClick={() => void move(index, 1)} aria-label="Move down"><ArrowDown size={16} /></Button></>} {index !== undefined && !search && <><Button size="icon" variant="ghost" disabled={busy || index === movableIndices[0]} onClick={() => void move(index, -1)} aria-label="Move up"><ArrowUp size={16} /></Button><Button size="icon" variant="ghost" disabled={busy || index === movableIndices[movableIndices.length - 1]} onClick={() => void move(index, 1)} aria-label="Move down"><ArrowDown size={16} /></Button></>}
<Button size="icon" variant="ghost" disabled={busy || item.is_archived} onClick={() => openEditor({ kind: itemKind, item })} aria-label="Edit"><Pencil size={16} /></Button> <Button size="icon" variant="ghost" disabled={busy || item.is_archived} onClick={() => openEditor({ kind: itemKind, item })} aria-label="Edit"><Pencil size={16} /></Button>
<Button size="icon" variant="ghost" disabled={busy || item.is_archived} onClick={() => setDeleting({ item, kind: itemKind })} aria-label="Delete"><Trash2 size={16} /></Button> <Button size="icon" variant="ghost" disabled={busy || item.is_archived} onClick={() => setDeleting({ item, kind: itemKind })} aria-label="Delete"><Trash2 size={16} /></Button>
</div> </div>
@ -137,16 +136,9 @@ export function LearningHierarchyPage() {
<nav className="flex flex-wrap items-center gap-2 text-sm text-grayScale-500"><Link to="/new-content/courses">Courses</Link>{courseId && <><span>/</span><Link to={`/new-content/courses/${courseId}`}>{course?.name ?? "Course"}</Link></>}{chapterId && <><span>/</span><span>{chapter?.name ?? "Chapter"}</span></>}</nav> <nav className="flex flex-wrap items-center gap-2 text-sm text-grayScale-500"><Link to="/new-content/courses">Courses</Link>{courseId && <><span>/</span><Link to={`/new-content/courses/${courseId}`}>{course?.name ?? "Course"}</Link></>}{chapterId && <><span>/</span><span>{chapter?.name ?? "Chapter"}</span></>}</nav>
<header className="flex flex-wrap items-center justify-between gap-4"><div><h1 className="flex items-center gap-3 text-2xl font-bold"><BookOpen />{title}</h1><p className="mt-2 text-grayScale-500">{chapterId ? "Manage the lessons and quizzes in this chapter." : courseId ? "Organize this course into chapters." : "Create courses, organize chapters, and add lessons and chapter quizzes."}</p></div><Button disabled={busy || loading || failed} onClick={() => openEditor({ kind })}><Plus size={16} className="mr-2" />Add {kind}</Button></header> <header className="flex flex-wrap items-center justify-between gap-4"><div><h1 className="flex items-center gap-3 text-2xl font-bold"><BookOpen />{title}</h1><p className="mt-2 text-grayScale-500">{chapterId ? "Manage the lessons and quizzes in this chapter." : courseId ? "Organize this course into chapters." : "Create courses, organize chapters, and add lessons and chapter quizzes."}</p></div><Button disabled={busy || loading || failed} onClick={() => openEditor({ kind })}><Plus size={16} className="mr-2" />Add {kind}</Button></header>
{courseId && <Button asChild variant="ghost"><Link to={chapterId ? `/new-content/courses/${courseId}` : "/new-content/courses"}><ArrowLeft size={16} className="mr-2" />Back to {chapterId ? "chapters" : "courses"}</Link></Button>} {courseId && <Button asChild variant="ghost"><Link to={chapterId ? `/new-content/courses/${courseId}` : "/new-content/courses"}><ArrowLeft size={16} className="mr-2" />Back to {chapterId ? "chapters" : "courses"}</Link></Button>}
{kind === "course" && <div className="space-y-3">
<div className="flex flex-wrap gap-2" role="group" aria-label="Course catalog view">
<Button variant={showLegacy ? "outline" : "default"} aria-pressed={!showLegacy} onClick={() => setShowLegacy(false)}>Academy courses</Button>
<Button variant={showLegacy ? "default" : "outline"} aria-pressed={showLegacy} onClick={() => setShowLegacy(true)}>Legacy archive ({items.filter(item => item.is_archived).length})</Button>
</div>
{showLegacy && <p className="text-sm text-grayScale-500">Retired general-learning fixtures are kept here to preserve historical records and learner progress. They are unavailable in the learner catalog.</p>}
</div>}
<Input aria-label="Search content" placeholder="Search by title…" value={search} onChange={event => setSearch(event.target.value)} /> <Input aria-label="Search content" placeholder="Search by title…" value={search} onChange={event => setSearch(event.target.value)} />
{loading ? <p role="status">Loading content…</p> : failed ? <div role="alert"><p>Content could not be loaded.</p><Button onClick={() => void load()}>Try again</Button></div> : <> {loading ? <p role="status">Loading content…</p> : failed ? <div role="alert"><p>Content could not be loaded.</p><Button onClick={() => void load()}>Try again</Button></div> : <>
<section className="space-y-4"><h2 className="text-xl font-semibold capitalize">{collection[kind]}</h2><div className="grid gap-4 md:grid-cols-2">{items.map((item, index) => matches(item) ? card(item, kind, index) : null)}</div>{!items.some(matches) && <p className="rounded-xl border border-dashed p-8 text-center text-grayScale-500">{search ? "No matching content." : showLegacy ? "No archived courses." : `No ${collection[kind]} yet. Add your first ${kind} to get started.`}</p>}</section> <section className="space-y-4"><h2 className="text-xl font-semibold capitalize">{collection[kind]}</h2><div className="grid gap-4 md:grid-cols-2">{items.map((item, index) => matches(item) ? card(item, kind, index) : null)}</div>{!items.some(matches) && <p className="rounded-xl border border-dashed p-8 text-center text-grayScale-500">{search ? "No matching content." : `No ${collection[kind]} yet. Add your first ${kind} to get started.`}</p>}</section>
{chapterId && <section className="space-y-4 border-t pt-6"><div className="flex items-center justify-between"><h2 className="text-xl font-semibold">Chapter quizzes</h2><Button disabled={busy} onClick={() => openEditor({ kind: "quiz" })}><Plus size={16} className="mr-2" />Add quiz</Button></div><div className="grid gap-4 md:grid-cols-2">{quizzes.filter(matches).map(item => card(item, "quiz"))}</div>{!quizzes.some(matches) && <p className="text-grayScale-500">{search ? "No matching quizzes." : "No quizzes yet. Create a quiz, add its questions, then publish it."}</p>}</section>} {chapterId && <section className="space-y-4 border-t pt-6"><div className="flex items-center justify-between"><h2 className="text-xl font-semibold">Chapter quizzes</h2><Button disabled={busy} onClick={() => openEditor({ kind: "quiz" })}><Plus size={16} className="mr-2" />Add quiz</Button></div><div className="grid gap-4 md:grid-cols-2">{quizzes.filter(matches).map(item => card(item, "quiz"))}</div>{!quizzes.some(matches) && <p className="text-grayScale-500">{search ? "No matching quizzes." : "No quizzes yet. Create a quiz, add its questions, then publish it."}</p>}</section>}
</>} </>}
<Dialog open={!!editor} onOpenChange={open => { if (!open && !busy) setEditor(null) }}><DialogContent><DialogHeader><DialogTitle>{editor?.item ? "Edit" : "Add"} {editor?.kind}</DialogTitle></DialogHeader><form onSubmit={save} className="space-y-4"><label className="block space-y-2"><span>Title</span><Input autoFocus required value={form.name} onChange={event => setForm({ ...form, name: event.target.value })} /></label> <Dialog open={!!editor} onOpenChange={open => { if (!open && !busy) setEditor(null) }}><DialogContent><DialogHeader><DialogTitle>{editor?.item ? "Edit" : "Add"} {editor?.kind}</DialogTitle></DialogHeader><form onSubmit={save} className="space-y-4"><label className="block space-y-2"><span>Title</span><Input autoFocus required value={form.name} onChange={event => setForm({ ...form, name: event.target.value })} /></label>

View File

@ -120,7 +120,7 @@ export function AttachPracticeReviewStep({
{isExpanded && ( {isExpanded && (
<div className="animate-in slide-in-from-top-2 duration-300"> <div className="animate-in slide-in-from-top-2 duration-300">
<div className="border-t border-grayScale-100"> <div className="border-t border-grayScale-100">
<table className="w-full text-left border-collapse"> <table className="admin-data-table w-full text-left border-collapse">
<thead> <thead>
<tr className="bg-white"> <tr className="bg-white">
<th className="py-4 pl-10 pr-0 w-[80px]"></th> <th className="py-4 pl-10 pr-0 w-[80px]"></th>