generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 6
Date extensions list #62
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
Draft
diana-villalvazo-wgu
wants to merge
9
commits into
openedx:main
Choose a base branch
from
WGU-Open-edX:56/date-extensions-list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5bc754c
feat: date extensions data table
diana-villalvazo-wgu a0eca62
chore: add provider and api call
diana-villalvazo-wgu 45e562b
style: adding margins
diana-villalvazo-wgu f6348e9
test: add unit tests
diana-villalvazo-wgu cc02466
refactor: small changes
diana-villalvazo-wgu b1805c1
fix: update endpoints
diana-villalvazo-wgu 778a524
feat: implementing pagination
diana-villalvazo-wgu 710c3a6
fix: use camelCase on messages
diana-villalvazo-wgu 8726fc3
chore: improving querykeys
diana-villalvazo-wgu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { IntlProvider } from '@openedx/frontend-base'; | ||
| import { MemoryRouter, Route, Routes } from 'react-router-dom'; | ||
| import DateExtensionsPage from './DateExtensionsPage'; | ||
| import { useDateExtensions } from './data/apiHook'; | ||
|
|
||
| jest.mock('./data/apiHook', () => ({ | ||
| useDateExtensions: jest.fn(), | ||
| })); | ||
|
|
||
| const mockDateExtensions = [ | ||
| { | ||
| id: 1, | ||
| username: 'edByun', | ||
| fullname: 'Ed Byun', | ||
| email: '[email protected]', | ||
| graded_subsection: 'Three body diagrams', | ||
| extended_due_date: '2026-07-15' | ||
| }, | ||
| ]; | ||
|
|
||
| describe('DateExtensionsPage', () => { | ||
| beforeEach(() => { | ||
| (useDateExtensions as jest.Mock).mockReturnValue({ | ||
| data: { count: mockDateExtensions.length, results: mockDateExtensions }, | ||
| isLoading: false, | ||
| }); | ||
| }); | ||
|
|
||
| const RenderWithRouter = () => ( | ||
| <IntlProvider messages={{}}> | ||
| <MemoryRouter initialEntries={['/course-v1:edX+DemoX+Demo_Course']}> | ||
| <Routes> | ||
| <Route path="/:courseId" element={<DateExtensionsPage />} /> | ||
| </Routes> | ||
| </MemoryRouter> | ||
| </IntlProvider> | ||
| ); | ||
|
|
||
| it('renders page title', () => { | ||
| render(<RenderWithRouter />); | ||
| expect(screen.getByRole('heading', { level: 3 })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders add extension button', () => { | ||
| render(<RenderWithRouter />); | ||
| expect(screen.getByRole('button', { name: /add individual extension/i })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders date extensions list', () => { | ||
| render(<RenderWithRouter />); | ||
| expect(screen.getByText('Ed Byun')).toBeInTheDocument(); | ||
| expect(screen.getByText('Three body diagrams')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows loading state on table when fetching data', () => { | ||
| (useDateExtensions as jest.Mock).mockReturnValue({ | ||
| data: { count: 0, results: [] }, | ||
| isLoading: true, | ||
| }); | ||
| render(<RenderWithRouter />); | ||
| expect(screen.getByRole('status')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders reset link for each row', () => { | ||
| render(<RenderWithRouter />); | ||
| const resetLinks = screen.getAllByRole('button', { name: 'Reset Extensions' }); | ||
| expect(resetLinks).toHaveLength(mockDateExtensions.length); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { useIntl } from '@openedx/frontend-base'; | ||
| import messages from './messages'; | ||
| import DateExtensionsList from './components/DateExtensionsList'; | ||
| import { Button, Container } from '@openedx/paragon'; | ||
| import { LearnerDateExtension } from './types'; | ||
|
|
||
| // const successMessage = 'Successfully reset due date for student Phu Nguyen for A subsection with two units (block-v1:SchemaAximWGU+WGU101+1+type@sequential+block@3984030755104708a86592cf23fb1ae4) to 2025-08-21 00:00'; | ||
|
|
||
| const DateExtensionsPage = () => { | ||
| const intl = useIntl(); | ||
|
|
||
| const handleResetExtensions = (user: LearnerDateExtension) => { | ||
| // Implementation for resetting extensions will go here | ||
| console.log(user); | ||
| }; | ||
|
|
||
| return ( | ||
| <Container className="mt-4.5 mb-4 mx-4" fluid="xl"> | ||
| <h3>{intl.formatMessage(messages.dateExtensionsTitle)}</h3> | ||
| <div className="d-flex align-items-center justify-content-between mb-3.5"> | ||
| <p>filters</p> | ||
| <Button>+ {intl.formatMessage(messages.addIndividualExtension)}</Button> | ||
| </div> | ||
| <DateExtensionsList onResetExtensions={handleResetExtensions} /> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default DateExtensionsPage; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import DateExtensionsList, { DateExtensionListProps } from './DateExtensionsList'; | ||
| import { renderWithIntl } from '../../testUtils'; | ||
| import { useDateExtensions } from '../data/apiHook'; | ||
|
|
||
| const mockData = [ | ||
| { | ||
| id: 1, | ||
| username: 'test_user', | ||
| fullname: 'Test User', | ||
| email: '[email protected]', | ||
| graded_subsection: 'Test Section', | ||
| extended_due_date: '2024-01-01' | ||
| } | ||
| ]; | ||
|
|
||
| jest.mock('../data/apiHook', () => ({ | ||
| useDateExtensions: jest.fn(), | ||
| })); | ||
|
|
||
| const mockResetExtensions = jest.fn(); | ||
|
|
||
| describe('DateExtensionsList', () => { | ||
| const renderComponent = (props: DateExtensionListProps) => renderWithIntl( | ||
| <DateExtensionsList {...props} /> | ||
| ); | ||
|
|
||
| it('renders loading state on the table', () => { | ||
| (useDateExtensions as jest.Mock).mockReturnValue({ isLoading: true, data: { count: 0, results: [] } }); | ||
| renderComponent({}); | ||
| expect(screen.getByRole('status')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders table with data', async () => { | ||
| (useDateExtensions as jest.Mock).mockReturnValue({ isLoading: false, data: { count: mockData.length, results: mockData } }); | ||
| renderComponent({ onResetExtensions: mockResetExtensions }); | ||
| const user = userEvent.setup(); | ||
| expect(screen.getByText('test_user')).toBeInTheDocument(); | ||
| expect(screen.getByText('Test User')).toBeInTheDocument(); | ||
| expect(screen.getByText('[email protected]')).toBeInTheDocument(); | ||
| expect(screen.getByText('Test Section')).toBeInTheDocument(); | ||
| expect(screen.getByText('2024-01-01')).toBeInTheDocument(); | ||
| const resetExtensions = screen.getByRole('button', { name: /reset extensions/i }); | ||
| expect(resetExtensions).toBeInTheDocument(); | ||
| await user.click(resetExtensions); | ||
| expect(mockResetExtensions).toHaveBeenCalledWith(mockData[0]); | ||
| }); | ||
|
|
||
| it('renders empty table when no data provided', () => { | ||
| (useDateExtensions as jest.Mock).mockReturnValue({ data: { count: 0, results: [] } }); | ||
| renderComponent({}); | ||
| expect(screen.queryByText('test_user')).not.toBeInTheDocument(); | ||
| expect(screen.getByText('No results found')).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { useIntl } from '@openedx/frontend-base'; | ||
| import { Button, DataTable } from '@openedx/paragon'; | ||
| import messages from '../messages'; | ||
| import { LearnerDateExtension } from '../types'; | ||
| import { useDateExtensions } from '../data/apiHook'; | ||
| import { useParams } from 'react-router-dom'; | ||
| import { useState } from 'react'; | ||
|
|
||
| // For testing purposes, will be deleted once backend is ready | ||
| // const mockDateExtensions = [ | ||
| // { id: 1, username: 'edByun', fullname: 'Ed Byun', email: '[email protected]', graded_subsection: 'Three body diagrams', extended_due_date: '2026-07-15' }, | ||
| // { id: 2, username: 'dianaSalas', fullname: 'Diana Villalvazo', email: '[email protected]', graded_subsection: 'Three body diagrams', extended_due_date: '2026-07-15' }, | ||
| // ]; | ||
|
|
||
| const DATE_EXTENSIONS_PAGE_SIZE = 25; | ||
|
|
||
| export interface DateExtensionListProps { | ||
| onResetExtensions?: (user: LearnerDateExtension) => void, | ||
| } | ||
|
|
||
| interface DataTableFetchDataProps { | ||
| pageIndex: number, | ||
| } | ||
|
|
||
| const DateExtensionsList = ({ | ||
| onResetExtensions = () => {}, | ||
| }: DateExtensionListProps) => { | ||
| const intl = useIntl(); | ||
| const { courseId } = useParams(); | ||
| const [page, setPage] = useState(0); | ||
| const { data = { count: 0, results: [] }, isLoading } = useDateExtensions(courseId ?? '', { | ||
| page, | ||
| pageSize: DATE_EXTENSIONS_PAGE_SIZE | ||
| }); | ||
|
|
||
| const pageCount = Math.ceil(data.count / DATE_EXTENSIONS_PAGE_SIZE); | ||
|
|
||
| const tableColumns = [ | ||
| { accessor: 'username', Header: intl.formatMessage(messages.username) }, | ||
| { accessor: 'fullname', Header: intl.formatMessage(messages.fullname) }, | ||
| { accessor: 'email', Header: intl.formatMessage(messages.email) }, | ||
| { accessor: 'graded_subsection', Header: intl.formatMessage(messages.gradedSubsection) }, | ||
| { accessor: 'extended_due_date', Header: intl.formatMessage(messages.extendedDueDate) }, | ||
| { accessor: 'reset', Header: intl.formatMessage(messages.reset) }, | ||
| ]; | ||
|
|
||
| const tableData = data.results.map(item => ({ | ||
| ...item, | ||
| reset: <Button variant="link" size="inline" onClick={() => onResetExtensions(item)}>Reset Extensions</Button>, | ||
| })); | ||
|
|
||
| const handleFetchData = (data: DataTableFetchDataProps) => { | ||
| setPage(data.pageIndex); | ||
| }; | ||
|
|
||
| return ( | ||
| <DataTable | ||
| columns={tableColumns} | ||
| data={tableData} | ||
| fetchData={handleFetchData} | ||
| initialState={{ | ||
| pageIndex: page, | ||
| pageSize: DATE_EXTENSIONS_PAGE_SIZE, | ||
| }} | ||
| isLoading={isLoading} | ||
| isPaginated | ||
| itemCount={data.count} | ||
| manualFilters | ||
| manualPagination | ||
| pageSize={DATE_EXTENSIONS_PAGE_SIZE} | ||
| pageCount={pageCount} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default DateExtensionsList; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { camelCaseObject, getAuthenticatedHttpClient } from '@openedx/frontend-base'; | ||
| import { getApiBaseUrl } from '../../data/api'; | ||
| import { DateExtensionsResponse } from '../types'; | ||
|
|
||
| export interface PaginationQueryKeys { | ||
| page: number, | ||
| pageSize: number, | ||
| } | ||
|
|
||
| export const getDateExtensions = async ( | ||
| courseId: string, | ||
| pagination: PaginationQueryKeys | ||
| ): Promise<DateExtensionsResponse> => { | ||
| const { data } = await getAuthenticatedHttpClient().get( | ||
| `${getApiBaseUrl()}/api/instructor/v2/courses/${courseId}/unit_extensions/?page=${pagination.page}&page_size=${pagination.pageSize}` | ||
| ); | ||
| return camelCaseObject(data); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { getDateExtensions, PaginationQueryKeys } from './api'; | ||
| import { dateExtensionsQueryKeys } from './queryKeys'; | ||
|
|
||
| export const useDateExtensions = (courseId: string, pagination: PaginationQueryKeys) => ( | ||
| useQuery({ | ||
| queryKey: dateExtensionsQueryKeys.byCoursePaginated(courseId, pagination), | ||
| queryFn: () => getDateExtensions(courseId, pagination), | ||
| }) | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { appId } from '../../constants'; | ||
| import { PaginationQueryKeys } from './api'; | ||
|
|
||
| export const dateExtensionsQueryKeys = { | ||
| all: [appId, 'dateExtensions'] as const, | ||
| byCourse: (courseId: string) => [...dateExtensionsQueryKeys.all, courseId] as const, | ||
| byCoursePaginated: (courseId: string, pagination: PaginationQueryKeys) => [...dateExtensionsQueryKeys.byCourse(courseId), pagination.page] as const, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { defineMessages } from '@openedx/frontend-base'; | ||
|
|
||
| const messages = defineMessages({ | ||
| dateExtensionsTitle: { | ||
| id: 'instruct.dateExtensions.page.title', | ||
| defaultMessage: 'Viewing Granted Extensions', | ||
| description: 'Title for date extensions page', | ||
| }, | ||
| addIndividualExtension: { | ||
| id: 'instruct.dateExtensions.page.addIndividualExtension', | ||
| defaultMessage: 'Add Individual Extension', | ||
| description: 'Button text for adding an individual date extension', | ||
| }, | ||
| username: { | ||
| id: 'instruct.dateExtensions.page.tableHeader.username', | ||
| defaultMessage: 'User Name', | ||
| description: 'Label for the user name column in the date extensions table', | ||
| }, | ||
| fullname: { | ||
| id: 'instruct.dateExtensions.page.tableHeader.fullname', | ||
| defaultMessage: 'Full Name', | ||
| description: 'Label for the full name column in the date extensions table', | ||
| }, | ||
| email: { | ||
| id: 'instruct.dateExtensions.page.tableHeader.email', | ||
| defaultMessage: 'Email', | ||
| description: 'Label for the email column in the date extensions table', | ||
| }, | ||
| gradedSubsection: { | ||
| id: 'instruct.dateExtensions.page.tableHeader.gradedSubsection', | ||
| defaultMessage: 'Graded Subsection', | ||
| description: 'Label for the graded subsection column in the date extensions table', | ||
| }, | ||
| extendedDueDate: { | ||
| id: 'instruct.dateExtensions.page.tableHeader.extendedDueDate', | ||
| defaultMessage: 'Extended Due Date', | ||
| description: 'Label for the extended due date column in the date extensions table', | ||
| }, | ||
| reset: { | ||
| id: 'instruct.dateExtensions.page.tableHeader.reset', | ||
| defaultMessage: 'Reset', | ||
| description: 'Label for the reset column in the date extensions table', | ||
| }, | ||
| }); | ||
|
|
||
| export default messages; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export interface LearnerDateExtension { | ||
| id: number, | ||
| username: string, | ||
| fullname: string, | ||
| email: string, | ||
| graded_subsection: string, | ||
| extended_due_date: string, | ||
| } | ||
|
|
||
| export interface DateExtensionsResponse { | ||
| count: number, | ||
| next: string | null, | ||
| previous: string | null, | ||
| results: LearnerDateExtension[], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.