-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add roster sync indicator * Add message when assignment students do not come from roster (#6905)
- Loading branch information
Showing
7 changed files
with
198 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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 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 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
48 changes: 48 additions & 0 deletions
48
lms/static/scripts/frontend_apps/components/dashboard/LastSyncIndicator.tsx
This file contains 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,48 @@ | ||
import type { IconComponent } from '@hypothesis/frontend-shared'; | ||
import { formatDateTime } from '@hypothesis/frontend-shared'; | ||
import classnames from 'classnames'; | ||
import { useMemo } from 'preact/hooks'; | ||
|
||
import type { ISODateTime } from '../../api-types'; | ||
import RelativeTime from '../RelativeTime'; | ||
|
||
export type LastSyncIndicatorProps = { | ||
icon: IconComponent; | ||
taskName: string; | ||
dateTime: ISODateTime | null; | ||
}; | ||
|
||
/** | ||
* Represents the last time a task that syncs periodically happened | ||
*/ | ||
export default function LastSyncIndicator({ | ||
icon: Icon, | ||
taskName, | ||
dateTime, | ||
}: LastSyncIndicatorProps) { | ||
const absoluteDate = useMemo( | ||
() => | ||
dateTime ? formatDateTime(dateTime, { includeWeekday: true }) : undefined, | ||
[dateTime], | ||
); | ||
|
||
return ( | ||
<div | ||
className={classnames( | ||
'flex gap-x-1 items-center p-1.5', | ||
'bg-grey-2 text-color-text-light cursor-default', | ||
'first:rounded-l last:rounded-r', | ||
)} | ||
title={absoluteDate && `${taskName} last synced on ${absoluteDate}`} | ||
data-testid="container" | ||
> | ||
<Icon /> | ||
<span className="font-bold">{taskName}:</span> | ||
{dateTime ? ( | ||
<RelativeTime dateTime={dateTime} withTitle={false} /> | ||
) : ( | ||
<span data-testid="syncing">syncing…</span> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains 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
39 changes: 39 additions & 0 deletions
39
lms/static/scripts/frontend_apps/components/dashboard/test/LastSyncIndicator-test.js
This file contains 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,39 @@ | ||
import { FileCodeIcon, formatDateTime } from '@hypothesis/frontend-shared'; | ||
import { mount } from 'enzyme'; | ||
|
||
import LastSyncIndicator from '../LastSyncIndicator'; | ||
|
||
describe('LastSyncIndicator', () => { | ||
function createComponent(dateTime) { | ||
return mount( | ||
<LastSyncIndicator | ||
icon={FileCodeIcon} | ||
taskName="task" | ||
dateTime={dateTime} | ||
/>, | ||
).find('[data-testid="container"]'); | ||
} | ||
|
||
[ | ||
{ dateTime: null, expectedTitle: undefined }, | ||
{ | ||
dateTime: '2024-10-02T14:24:15.677924+00:00', | ||
expectedTitle: `task last synced on ${formatDateTime('2024-10-02T14:24:15.677924+00:00', { includeWeekday: true })}`, | ||
}, | ||
].forEach(({ dateTime, expectedTitle }) => { | ||
it('has title when dateTime is not null', () => { | ||
const wrapper = createComponent(dateTime); | ||
assert.equal(wrapper.prop('title'), expectedTitle); | ||
}); | ||
|
||
it('shows syncing message when date time is null', () => { | ||
const wrapper = createComponent(dateTime); | ||
assert.equal(wrapper.exists('[data-testid="syncing"]'), !dateTime); | ||
}); | ||
|
||
it('shows relative time when dateTime is not null', () => { | ||
const wrapper = createComponent(dateTime); | ||
assert.equal(wrapper.exists('RelativeTime'), !!dateTime); | ||
}); | ||
}); | ||
}); |
This file contains 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