-
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.
Support Canvas Pages content via LMSFilePicker (#5717)
Co-authored-by: Alejandro Celaya <[email protected]>
- Loading branch information
Showing
9 changed files
with
416 additions
and
237 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
94 changes: 94 additions & 0 deletions
94
lms/static/scripts/frontend_apps/components/DocumentList.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,94 @@ | ||
import { | ||
DataTable, | ||
FileCodeFilledIcon, | ||
FilePdfFilledIcon, | ||
FolderIcon, | ||
Scroll, | ||
} from '@hypothesis/frontend-shared'; | ||
import type { ComponentChildren } from 'preact'; | ||
|
||
import type { Document } from '../api-types'; | ||
|
||
export type DocumentListProps<DocumentType extends Document> = { | ||
/** List of document objects returned by the API */ | ||
documents: DocumentType[]; | ||
/** Whether to show a loading indicator */ | ||
isLoading?: boolean; | ||
/** The document within `documents` which is currently selected */ | ||
selectedDocument: DocumentType | null; | ||
/** Callback invoked when the user clicks on a document */ | ||
onSelectDocument: (doc: DocumentType | null) => void; | ||
/** | ||
* Callback invoked when the user double-clicks a document to indicate that | ||
* they want to use it | ||
*/ | ||
onUseDocument: (d: DocumentType | null) => void; | ||
/** Optional message to display if there are no documents */ | ||
noDocumentsMessage?: ComponentChildren; | ||
/** Component title for accessibility */ | ||
title: string; | ||
}; | ||
|
||
/** | ||
* List of the documents | ||
*/ | ||
export default function DocumentList<DocumentType extends Document>({ | ||
documents, | ||
isLoading = false, | ||
selectedDocument, | ||
onSelectDocument, | ||
onUseDocument, | ||
noDocumentsMessage, | ||
title, | ||
}: DocumentListProps<DocumentType>) { | ||
const formatDate = (isoString: string) => | ||
new Date(isoString).toLocaleDateString(); | ||
const columns = [ | ||
{ | ||
label: 'Name', | ||
field: 'display_name', | ||
}, | ||
{ | ||
label: 'Last modified', | ||
field: 'updated_at', | ||
classes: 'w-32', | ||
}, | ||
]; | ||
|
||
const renderItem = (document: DocumentType, field: keyof DocumentType) => { | ||
switch (field) { | ||
case 'display_name': | ||
return ( | ||
<div className="flex flex-row items-center gap-x-2"> | ||
{document.type === 'Folder' ? ( | ||
<FolderIcon className="w-5 h-5" /> | ||
) : document.type === 'Page' ? ( | ||
<FileCodeFilledIcon className="w-5 h-5" /> | ||
) : ( | ||
<FilePdfFilledIcon className="w-5 h-5" /> | ||
)} | ||
{document.display_name} | ||
</div> | ||
); | ||
case 'updated_at': | ||
default: | ||
return document.updated_at ? formatDate(document.updated_at) : ''; | ||
} | ||
}; | ||
|
||
return ( | ||
<Scroll> | ||
<DataTable | ||
title={title} | ||
emptyMessage={noDocumentsMessage} | ||
columns={columns} | ||
loading={isLoading} | ||
rows={documents} | ||
selectedRow={selectedDocument} | ||
onSelectRow={onSelectDocument} | ||
onConfirmRow={onUseDocument} | ||
renderItem={renderItem} | ||
/> | ||
</Scroll> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.