|
| 1 | +import { useQuery } from 'react-query'; |
| 2 | + |
| 3 | +import { queryKeys } from './constants'; |
| 4 | + |
| 5 | +const mockORAConfig = { fake: 'ora config data' }; |
| 6 | +const mockSubmissionData = { fake: 'ora submission data' }; |
| 7 | + |
| 8 | +/** |
| 9 | + * A react-query data object |
| 10 | + * @typedef {Object} ReactQueryData |
| 11 | + * @property {boolean} isLoading |
| 12 | + * @property {boolean} isFetching |
| 13 | + * @property {boolean} isInitialLoading |
| 14 | + * @property {Object} error |
| 15 | + * @property {Object} data |
| 16 | + */ |
| 17 | + |
| 18 | +const loadAssessmentConfig = ({ |
| 19 | + assessmentSteps: { |
| 20 | + peer, |
| 21 | + self, |
| 22 | + training, |
| 23 | + staff, |
| 24 | + }, |
| 25 | +}) => ({ |
| 26 | + peer: peer && { |
| 27 | + startTime: peer.startTime, |
| 28 | + endTime: peer.endTime, |
| 29 | + required: peer.required, |
| 30 | + data: { |
| 31 | + minNumberToGrade: peer.data.minNumberToGrade, |
| 32 | + minNumberToBeGradedBy: peer.data.minNumberToBeGradedBy, |
| 33 | + enableFlexibleGrading: peer.data.enableFlexibleGrading, |
| 34 | + }, |
| 35 | + }, |
| 36 | + self: self && { |
| 37 | + startTime: self.startTime, |
| 38 | + endTime: self.endTime, |
| 39 | + required: self.required, |
| 40 | + }, |
| 41 | + training: training && { |
| 42 | + required: training.required, |
| 43 | + data: { examples: training.data.examples }, |
| 44 | + }, |
| 45 | + staff: staff && { required: staff.required }, |
| 46 | +}); |
| 47 | + |
| 48 | +const loadSubmissionConfig = ({ |
| 49 | + submissionConfig: { |
| 50 | + textResponseConfig: text, |
| 51 | + fileReseponseConfig: file, |
| 52 | + teamsConfig, |
| 53 | + ...config |
| 54 | + }, |
| 55 | +}) => ({ |
| 56 | + startDatetime: config.startDatetime, |
| 57 | + endDatetime: config.endDatetime, |
| 58 | + textResponseConfig: { |
| 59 | + enabled: text.enabled, |
| 60 | + optional: text.optional, |
| 61 | + editorType: text.editorType, |
| 62 | + allowLatexPreview: text.allowLatexPreview, |
| 63 | + }, |
| 64 | + fileResponseConfig: { |
| 65 | + enabled: file.enabled, |
| 66 | + optional: file.optional, |
| 67 | + fileUploadType: file.fileUploadType, |
| 68 | + allowedExtensions: file.allowedExtensions, |
| 69 | + blockedExtensions: file.blockedExtensions, |
| 70 | + fileTypeDescription: file.fileTypeDescription, |
| 71 | + }, |
| 72 | + teamsConfig: { |
| 73 | + enabled: teamsConfig.enabled, |
| 74 | + teamsetName: teamsConfig.teamsetName, |
| 75 | + }, |
| 76 | +}); |
| 77 | + |
| 78 | +const loadRubricConfig = ({ rubric }) => ({ |
| 79 | + showDuringResponse: rubric.showDuringResponse, |
| 80 | + feedbackConfig: { |
| 81 | + description: rubric.feedbackConfig.description, |
| 82 | + defaultText: rubric.feedbackConfig.defaultText, |
| 83 | + }, |
| 84 | + criteria: rubric.criteria.map(criterion => ({ |
| 85 | + name: criterion.name, |
| 86 | + description: criterion.description, |
| 87 | + feedbackEnabled: criterion.feedbackEnabled, |
| 88 | + feedbackRequired: criterion.feedbackRequired, |
| 89 | + options: criterion.map(option => ({ |
| 90 | + name: option.name, |
| 91 | + points: option.points, |
| 92 | + description: option.description, |
| 93 | + })), |
| 94 | + })), |
| 95 | + |
| 96 | +}); |
| 97 | +export const loadORAConfigData = (data) => ({ |
| 98 | + title: data.title, |
| 99 | + prompts: data.prompts, |
| 100 | + baseAssetUrl: data.baseAssetUrl, |
| 101 | + submissionConfig: loadSubmissionConfig(data), |
| 102 | + assessmentSteps: loadAssessmentConfig(data), |
| 103 | + rubric: loadRubricConfig(data), |
| 104 | + leaderboardConfig: { |
| 105 | + enabled: data.leaderboardConfig.enabled, |
| 106 | + numberOfEntries: data.leaderboardConfig.numberOfEntries, |
| 107 | + }, |
| 108 | +}); |
| 109 | +const loadFile = (file) => ({ |
| 110 | + url: file.fileUrl, |
| 111 | + description: file.fileDescription, |
| 112 | + name: file.fileName, |
| 113 | + size: file.fileSize, |
| 114 | + uploadedBy: file.uploadedBy, |
| 115 | +}); |
| 116 | +export const loadSubmissionData = ({ teamInfo, submissionStatus, submission }) => ({ |
| 117 | + teamInfo: { |
| 118 | + teamName: teamInfo.teamName, |
| 119 | + teamUsernames: teamInfo.teamUsernames, |
| 120 | + previousTeamName: teamInfo.previousTeamName, |
| 121 | + hasSubmitted: teamInfo.hasSubmitted, |
| 122 | + uploadedFiles: teamInfo.teamUploadedFiles.map(loadFile), |
| 123 | + }, |
| 124 | + submissionStatus: { |
| 125 | + hasSubmitted: submissionStatus.hasSubmitted, |
| 126 | + hasCancelled: submissionStatus.hasCancelled, |
| 127 | + hasReceivedGrade: submissionStatus.hasReceivedGrade, |
| 128 | + }, |
| 129 | + submission: { |
| 130 | + textResponses: submission.textResponses, |
| 131 | + uploadedFiles: submission.uploadedFiles.map(loadFile), |
| 132 | + }, |
| 133 | +}); |
| 134 | + |
| 135 | +/** |
| 136 | + * @return {ReactQueryData} ORA config data |
| 137 | + */ |
| 138 | +export const useORAConfig = () => { |
| 139 | + const { data, ...status } = useQuery({ |
| 140 | + queryKey: [queryKeys.oraConfig], |
| 141 | + // queryFn: () => getAuthenticatedClient().get(...), |
| 142 | + queryFn: () => Promise.resolve(mockORAConfig), |
| 143 | + }); |
| 144 | + return { ...status, data: loadORAConfigData(data) }; |
| 145 | +}; |
| 146 | + |
| 147 | +/** |
| 148 | + * @return {ReactQueryData} Learner Submission data |
| 149 | + */ |
| 150 | +export const useSubmissionData = () => { |
| 151 | + const { data, ...status } = useQuery({ |
| 152 | + queryKey: [queryKeys.submissionData], |
| 153 | + // queryFn: () => getAuthenticatedClient().get(...), |
| 154 | + queryFn: () => Promise.resolve(mockSubmissionData), |
| 155 | + }); |
| 156 | + return { ...status, data: loadSubmissionData(data) }; |
| 157 | +}; |
0 commit comments