@nualang/nualang-ui-components 0.1.1418 → 0.1.1419

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import CourseCard from "../../Cards/Course/Course";
5
5
  import useListScroll from "../../hooks/useListScroll";
6
6
  import { SingleLineGridList, SingleLineGridListItem, GridListItem } from "../ListElements";
7
7
  import { getStudentSortOrder, setStudentSortOrder } from "../../utils/studentSort";
8
- import { CLASSROOM_COURSES_SORT_ORDER_KEY, compareCoursesBySortOrder, compareCoursesByLastVisit, getCourseVisits, recordCourseVisit } from "../../utils/courseSort";
8
+ import { CLASSROOM_COURSES_SORT_ORDER_KEY, compareCoursesBySortOrder, compareCoursesByLastVisit, getCourseVisits, normalizeCourseSortOrder, recordCourseVisit } from "../../utils/courseSort";
9
9
 
10
10
  // import { propsAreEqual } from '../../utils';
11
11
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
@@ -165,7 +165,7 @@ function Courses({
165
165
  handleViewCourseTopic,
166
166
  ...otherProps
167
167
  }) {
168
- const [sortOrder, setSortOrder] = useState(() => getStudentSortOrder(CLASSROOM_COURSES_SORT_ORDER_KEY, "oldest"));
168
+ const [sortOrder, setSortOrder] = useState(() => normalizeCourseSortOrder(getStudentSortOrder(CLASSROOM_COURSES_SORT_ORDER_KEY, "default")));
169
169
  // Snapshot taken on mount so opening a course doesn't reshuffle the list
170
170
  // under the user mid-click; the fresh order shows on the way back in.
171
171
  const [visits, setVisits] = useState(getCourseVisits);
@@ -199,7 +199,7 @@ function Courses({
199
199
  // The courses arrive from Dynamo oldest-first, so the default order is
200
200
  // simply the array as given — the courses added to the classroom first
201
201
  // stay at the top.
202
- if (sortOrder === "oldest") return courses;
202
+ if (sortOrder === "default") return courses;
203
203
  if (sortOrder === "newest") return [...courses].reverse();
204
204
  if (sortOrder === "recentlyViewed") {
205
205
  // Sorting the default order means never-opened courses stay in it,
@@ -235,8 +235,8 @@ function Courses({
235
235
  label: t("sort_by"),
236
236
  autoWidth: true,
237
237
  children: [/*#__PURE__*/_jsx(MenuItem, {
238
- value: "oldest",
239
- children: t("oldest")
238
+ value: "default",
239
+ children: t("default")
240
240
  }), /*#__PURE__*/_jsx(MenuItem, {
241
241
  value: "newest",
242
242
  children: t("newest")
@@ -44,7 +44,7 @@ describe("Courses", () => {
44
44
  } = renderCourses();
45
45
  unmount();
46
46
  });
47
- it("defaults to the order the courses arrive in, oldest first", async () => {
47
+ it("defaults to the order the courses arrive in, oldest added first", async () => {
48
48
  // No stored preference — courses added to the classroom first stay at the
49
49
  // top, in the order Dynamo sent them down.
50
50
  const {
@@ -56,6 +56,19 @@ describe("Courses", () => {
56
56
  expect(courseNames).toEqual(props.courses.map(c => c.courseName));
57
57
  unmount();
58
58
  });
59
+ it("falls back to the default order when a stale preference is stored", async () => {
60
+ // The order was named "oldest" in 0.1.1418; a teacher who picked it then
61
+ // still has that in localStorage.
62
+ localStorage.setItem(CLASSROOM_COURSES_SORT_ORDER_KEY, "oldest");
63
+ const {
64
+ unmount
65
+ } = renderCourses({
66
+ showSortControl: true
67
+ });
68
+ const courseNames = await renderedCourseNames();
69
+ expect(courseNames).toEqual(props.courses.map(c => c.courseName));
70
+ unmount();
71
+ });
59
72
  it("reverses the courses when the newest preference is stored", async () => {
60
73
  localStorage.setItem(CLASSROOM_COURSES_SORT_ORDER_KEY, "newest");
61
74
  const {
@@ -44,8 +44,14 @@ export const recordCourseVisit = (courseId, timestamp = Date.now()) => {
44
44
  // stable sort leaves them in whatever order the caller passed them in.
45
45
  export const compareCoursesByLastVisit = (a = {}, b = {}, visits = {}) => (visits[b.courseId] || 0) - (visits[a.courseId] || 0);
46
46
 
47
- // "oldest" and "newest" have no comparator here — there is no timestamp for
48
- // classroom-course membership, only array position. "oldest" is the order the
47
+ // Every order the classroom courses dropdown offers. Anything else — a stale
48
+ // preference from an older release, or a hand-edited value — is treated as
49
+ // "default" rather than leaving the dropdown showing a blank label.
50
+ export const COURSE_SORT_ORDERS = ["default", "newest", "alphabetical", "recentlyChanged", "recentlyViewed"];
51
+ export const normalizeCourseSortOrder = order => COURSE_SORT_ORDERS.includes(order) ? order : "default";
52
+
53
+ // "default" and "newest" have no comparator here — there is no timestamp for
54
+ // classroom-course membership, only array position. "default" is the order the
49
55
  // courses arrive in from Dynamo, so callers leave the array untouched; "newest"
50
56
  // is that same array reversed.
51
57
  // "recentlyViewed" needs the visits map, so it has its own comparator above.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nualang/nualang-ui-components",
3
- "version": "0.1.1418",
3
+ "version": "0.1.1419",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "files": [