From 8cad64c86e2201c5d096b2c5f6c5d89804485a4b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 23 Aug 2024 16:23:07 +0200 Subject: [PATCH] Get MultiSelect back in DashboardActivityFilters (#6583) --- .../dashboard/DashboardActivityFilters.tsx | 109 ++++++++++-------- .../test/DashboardActivityFilters-test.js | 16 +-- 2 files changed, 66 insertions(+), 59 deletions(-) diff --git a/lms/static/scripts/frontend_apps/components/dashboard/DashboardActivityFilters.tsx b/lms/static/scripts/frontend_apps/components/dashboard/DashboardActivityFilters.tsx index 3cff0fc70b..ca0c8b5ea4 100644 --- a/lms/static/scripts/frontend_apps/components/dashboard/DashboardActivityFilters.tsx +++ b/lms/static/scripts/frontend_apps/components/dashboard/DashboardActivityFilters.tsx @@ -1,4 +1,8 @@ -import { CancelIcon, IconButton, Select } from '@hypothesis/frontend-shared'; +import { + CancelIcon, + IconButton, + MultiSelect, +} from '@hypothesis/frontend-shared'; import { useMemo } from 'preact/hooks'; import { useParams } from 'wouter-preact'; @@ -65,22 +69,37 @@ function elementScrollIsAtBottom(element: HTMLElement, offset = 20): boolean { return distanceToTop >= triggerPoint; } -/** Get first item from an array, if any */ -const firstItem = (array: T[]) => array[0] as T | undefined; - /** * Represents a `Select.Option` for a specific assignment */ function AssignmentOption({ assignment }: { assignment: Assignment }) { return ( - +
{assignment.title}
{formatDateTime(assignment.created)}
-
+ + ); +} + +/** + * Placeholder to indicate a loading is in progress in one of the dropdowns + */ +function LoadingOption({ + entity, +}: { + entity: 'courses' | 'assignments' | 'students'; +}) { + return ( +
+ Loading more {entity}... +
); } @@ -182,13 +201,13 @@ export default function DashboardActivityFilters({ return (
- - - + {hasSelection && onClearSelection && ( { } function getSelect(wrapper, id) { - return wrapper.find(`Select[data-testid="${id}"]`); + return wrapper.find(`MultiSelect[data-testid="${id}"]`); } function getSelectContent(wrapper, id) { @@ -215,7 +215,7 @@ describe('DashboardActivityFilters', () => { it('renders corresponding options', () => { const wrapper = createComponent(); const select = getSelect(wrapper, id); - const options = select.find(Select.Option); + const options = select.find(MultiSelect.Option); assert.equal(options.length, expectedOptions.length); options.forEach((option, index) => { @@ -234,17 +234,17 @@ describe('DashboardActivityFilters', () => { [ { id: 'courses-select', - selection: `${courses[0].id}`, + selection: courses.map(c => `${c.id}`), getExpectedCallback: () => onCoursesChange, }, { id: 'assignments-select', - selection: `${assignments[0].id}`, + selection: assignments.map(a => `${a.id}`), getExpectedCallback: () => onAssignmentsChange, }, { id: 'students-select', - selection: studentsWithName[0].h_userid, + selection: studentsWithName.map(s => s.h_userid), getExpectedCallback: () => onStudentsChange, }, ].forEach(({ id, selection, getExpectedCallback }) => { @@ -253,7 +253,7 @@ describe('DashboardActivityFilters', () => { const select = getSelect(wrapper, id); select.props().onChange(selection); - assert.calledWith(getExpectedCallback(), [selection]); + assert.calledWith(getExpectedCallback(), selection); }); }); @@ -523,7 +523,7 @@ describe('DashboardActivityFilters', () => { it('displays only two options in select', () => { const wrapper = createComponentWithProps(props); const select = getSelect(wrapper, selectId); - const options = select.find(Select.Option); + const options = select.find(MultiSelect.Option); assert.equal(options.length, 2); assert.equal(options.at(0).text(), allOption);