Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve column values from state object #441

Merged
merged 9 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 78 additions & 32 deletions src/client/components/pages/Courses/CoursesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,48 @@ import React, {
useState,
useEffect,
useContext,
useMemo,
} from 'react';
import { LoadSpinner } from 'mark-one';
import { Dropdown, LoadSpinner, POSITION } from 'mark-one';
import { MessageContext } from 'client/context';
import CourseInstanceResponseDTO from 'common/dto/courses/CourseInstanceResponse';
import { CourseAPI } from 'client/api';
import { MESSAGE_TYPE, MESSAGE_ACTION, AppMessage } from 'client/classes';
import { OFFERED, COURSE_TABLE_COLUMN } from 'common/constants';
import { ViewResponse } from 'common/dto/view/ViewResponse.dto';
import { VerticalSpace } from 'client/components/layout';
import CourseInstanceTable from './CourseInstanceTable';
import { tableFields } from './tableFields';

/*
* TODO
* Until the functionality for defining a retrieving custom view is implemented
* we can just hard code/comment the columns to display
/**
* These columns are ALWAYS shown regardless of user choice
*/
const currentView = [
const mandatoryColumns = [
COURSE_TABLE_COLUMN.AREA,
COURSE_TABLE_COLUMN.CATALOG_NUMBER,
COURSE_TABLE_COLUMN.TITLE,
COURSE_TABLE_COLUMN.SAME_AS,
COURSE_TABLE_COLUMN.IS_SEAS,
// COURSE_TABLE_COLUMN.IS_UNDERGRADUATE,
COURSE_TABLE_COLUMN.OFFERED,
COURSE_TABLE_COLUMN.INSTRUCTORS,
COURSE_TABLE_COLUMN.MEETINGS,
// COURSE_TABLE_COLUMN.ENROLLMENT,
COURSE_TABLE_COLUMN.NOTES,
COURSE_TABLE_COLUMN.DETAILS,
];

/**
* Default View
*
* This is the hard-coded default view that is showin in the dropdown when a
* user loads the page. Other views can be created, modified and deleted - but
* this default view can never be deleted or updated.
*/
const defaultView: ViewResponse = {
id: 'default',
name: 'Default',
columns: [
...mandatoryColumns,
COURSE_TABLE_COLUMN.MEETINGS,
COURSE_TABLE_COLUMN.IS_SEAS,
COURSE_TABLE_COLUMN.OFFERED,
COURSE_TABLE_COLUMN.INSTRUCTORS,
rmainwork marked this conversation as resolved.
Show resolved Hide resolved
COURSE_TABLE_COLUMN.NOTES,
],
};

/*
* TODO
* Until the functionality for setting "Show Retired Courses" is iomplemented
Expand All @@ -56,6 +68,22 @@ const CoursesPage: FunctionComponent = (): ReactElement => {
setCourses,
] = useState([] as CourseInstanceResponseDTO[]);

const [
currentViewId,
setCurrentViewId,
] = useState(defaultView.id);

const [
views,
] = useState([
defaultView,
]);

const currentView = useMemo(
() => views.find(({ id }) => id === currentViewId),
[views, currentViewId]
);

const dispatchMessage = useContext(MessageContext);

const [fetching, setFetching] = useState(false);
Expand Down Expand Up @@ -108,24 +136,42 @@ const CoursesPage: FunctionComponent = (): ReactElement => {
</div>
)
: (
<CourseInstanceTable
academicYear={acadYear}
courseList={
showRetired
? currentCourses
: currentCourses.filter(
({ spring, fall }): boolean => (
fall.offered !== OFFERED.RETIRED
&& spring.offered !== OFFERED.RETIRED)
<>
<VerticalSpace>
<Dropdown
id="select-view-dropdown"
name="select-view-dropdown"
onChange={(event: React.ChangeEvent<HTMLSelectElement>) => {
setCurrentViewId(event.currentTarget.value);
}}
labelPosition={POSITION.LEFT}
label="View"
value={currentViewId}
options={views.map((view) => ({
label: view.name,
value: view.id,
}))}
/>
</VerticalSpace>
<CourseInstanceTable
academicYear={acadYear}
courseList={
showRetired
? currentCourses
: currentCourses.filter(
({ spring, fall }): boolean => (
fall.offered !== OFFERED.RETIRED
&& spring.offered !== OFFERED.RETIRED)
)
}
courseUpdateHandler={updateLocalCourse}
tableData={tableFields.filter(
({ viewColumn }): boolean => (
currentView.columns.includes(viewColumn)
)
}
courseUpdateHandler={updateLocalCourse}
tableData={tableFields.filter(
({ viewColumn }): boolean => (
currentView.includes(viewColumn)
)
)}
/>
)}
/>
</>
)}
</div>
);
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/client/courseInstance/viewselector.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { render } from 'test-utils';
import CoursesPage from 'client/components/pages/Courses/CoursesPage';

describe('View selection dropdown', function () {
let coursePage: ReturnType<typeof render>;

beforeEach(function () {
coursePage = render(<CoursesPage />);
});
it('defaults to the default view', async function () {
return coursePage.findByDisplayValue(/Default/, { exact: false });
});
});