Skip to content

Commit

Permalink
chore: add upload file limit message (#122)
Browse files Browse the repository at this point in the history
* chore: add upload file limit message

* chore: lint update

* chore: fix due date

* chore: move rubric detail to tooltip
  • Loading branch information
leangseu-edx authored Dec 11, 2023
1 parent 34bf14e commit 0164f71
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
33 changes: 24 additions & 9 deletions src/components/FileUpload/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DataTable, Dropzone } from '@edx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';

import { nullMethod } from 'utils';
import { useActiveStepName, useFileUploadEnabled } from 'hooks/app';
import { useActiveStepName, useFileUploadConfig } from 'hooks/app';
import { useViewStep } from 'hooks/routing';
import FilePreview from 'components/FilePreview';
import { stepNames } from 'constants';
Expand All @@ -20,7 +20,11 @@ import messages from './messages';
import './styles.scss';

export const createFileActionCell = ({ onDeletedFile, isReadOnly }) => (props) => (
<ActionCell {...props} onDeletedFile={onDeletedFile} disabled={isReadOnly} />
<ActionCell
{...props}
onDeletedFile={onDeletedFile}
disabled={isReadOnly}
/>
);

const FileUpload = ({
Expand All @@ -40,8 +44,11 @@ const FileUpload = ({
} = useFileUploadHooks({ onFileUploaded });
const viewStep = useViewStep();
const activeStepName = useActiveStepName();
const {
enabled, fileUploadLimit, allowedExtensions, maxFileSize,
} = useFileUploadConfig() || {};

if (!useFileUploadEnabled() || viewStep === stepNames.studentTraining) {
if (!enabled || viewStep === stepNames.studentTraining) {
return null;
}

Expand Down Expand Up @@ -70,21 +77,29 @@ const FileUpload = ({
return (
<div>
<h3>{formatMessage(messages.fileUploadTitle)}</h3>
{uploadedFiles.length > 0 && isReadOnly && <FilePreview defaultCollapsePreview={defaultCollapsePreview} />}
{uploadedFiles.length > 0 && isReadOnly && (
<FilePreview defaultCollapsePreview={defaultCollapsePreview} />
)}
<b>{formatMessage(messages.uploadedFilesTitle)}</b>
<DataTable
itemCount={uploadedFiles.length}
data={uploadedFiles.map((file) => ({
...file,
size: typeof file.size === 'number' ? filesize(file.size) : 'Unknown',
}))}
tableActions={[
<FileDownload files={uploadedFiles} />,
]}
tableActions={[<FileDownload files={uploadedFiles} />]}
columns={columns}
/>
{!isReadOnly && (
<Dropzone multiple onProcessUpload={onProcessUpload} progressVariant="bar" />
{!isReadOnly && fileUploadLimit > uploadedFiles.length && (
<Dropzone
multiple
onProcessUpload={onProcessUpload}
progressVariant="bar"
accept={{
'*': (allowedExtensions || []).map((ext) => `.${ext}`),
}}
maxSize={maxFileSize}
/>
)}
{!isReadOnly && isModalOpen && (
<UploadConfirmModal
Expand Down
5 changes: 1 addition & 4 deletions src/components/InfoPopover/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import messages from './messages';
export const InfoPopover = ({ onClick, children }) => {
const { formatMessage } = useIntl();
return (
<div className="d-inline-block">
<div className="d-inline-block" title={formatMessage(messages.rubricDetails)}>
<OverlayTrigger
trigger="focus"
placement="bottom"
Expand All @@ -40,9 +40,6 @@ export const InfoPopover = ({ onClick, children }) => {
size="inline"
/>
</OverlayTrigger>
<span className="ml-2.5 micro">
Rubric details
</span>
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/data/services/lms/hooks/selectors/oraConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const usePrompts = () => useORAConfigData()?.prompts;
export const useSubmissionConfig = (): types.SubmissionConfig | undefined => (
useORAConfigData()?.submissionConfig
);
export const useFileUploadEnabled = (): boolean | undefined => (
useSubmissionConfig()?.fileResponseConfig?.enabled
export const useFileUploadConfig = (): types.FileResponseConfig | undefined => (
useSubmissionConfig()?.fileResponseConfig
);

export const useAssessmentStepConfig = (): types.AssessmentStepConfig | undefined => (
Expand Down
1 change: 1 addition & 0 deletions src/data/services/lms/types/blockInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface FileResponseConfig {
enabled: boolean,
optional: boolean,
fileUploadLimit: number,
maxFileSize: number,
allowedExtensions: string[],
blockedExtensions: string[],
fileTypeDescription: string,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const {
useStepState,
useSubmissionConfig,
useTextResponses,
useFileUploadConfig,
useTrainingStepIsCompleted,
} = lmsSelectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const useDueDateMessage = () => {
const { formatMessage } = useIntl();
const { activeStepName, stepState } = useGlobalState();
const stepConfig = useActiveStepConfig();
const dispDate = ({ value }) => {
const dispDate = (value) => {
const date = new Date(moment(value));
return date.toLocaleString();
};
Expand Down

0 comments on commit 0164f71

Please sign in to comment.