░▒▓████████████████████████████████▓▒░ ░▒▓█ ▓▒░ ░▒▓█ ~ S W A M P ~ ▓▒░ ░▒▓█ ▓▒░ ░▒▓████████████████████████████████▓▒░
pplmvsvm
LOCATION:
/var/www/canvas/ui/features/enhanced_individual_gradebook/react/hooks
☗ ROOT
↻ REFRESH
✎ CARVE FLESH
EDITING: useExportGradebook.tsx
/* * Copyright (C) 2023 - present Instructure, Inc. * * This file is part of Canvas. * * Canvas is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, version 3 of the License. * * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License along * with this program. If not, see <http://www.gnu.org/licenses/>. */ import doFetchApi from '@canvas/do-fetch-api-effect' import {useScope as useI18nScope} from '@canvas/i18n' import {useState} from 'react' import {ApiCallStatus} from '../../types' import {Attachment} from '../../../../api.d' import {Progress} from '../../../gradebook/react/default_gradebook/gradebook.d' const I18n = useI18nScope('enhanced_individual_gradebook_submit_score') export const useExportGradebook = () => { const [attachmentStatus, setAttachmentStatus] = useState<ApiCallStatus>(ApiCallStatus.NOT_STARTED) const [attachmentError, setAttachmentError] = useState<Error>(new Error('')) const [attachment, setAttachment] = useState<Attachment | null>(null) type AttachmentProgress = { attachment_id: string filename: string progress_id: string } const exportGradebook = async (userId?: string, exportGradebookCsvUrl?: string) => { setAttachmentStatus(ApiCallStatus.PENDING) if (!exportGradebookCsvUrl) { setAttachmentError(new Error('Error exporting gradebook, export URL not found')) setAttachmentStatus(ApiCallStatus.FAILED) return } if (!userId) { setAttachmentError(new Error('Error exporting gradebook, user ID not found')) setAttachmentStatus(ApiCallStatus.FAILED) return } try { const attachmentProgress = // @ts-expect-error (await doFetchApi<AttachmentProgress>({path: exportGradebookCsvUrl, method: 'POST'})).json const pollingProgress: number = window.setInterval(async () => { const progressBody = { path: `/api/v1/progress/${attachmentProgress.progress_id}`, method: 'GET', } // @ts-expect-error const progress = (await doFetchApi<Progress>(progressBody)).json if (progress.workflow_state === 'running' || progress.workflow_state === 'queued') { return } if (progress.workflow_state === 'completed') { const attachmentBody = { path: `/api/v1/users/${userId}/files/${attachmentProgress.attachment_id}`, method: 'GET', } // @ts-expect-error const attachmentResult = (await doFetchApi<Attachment>(attachmentBody)).json setAttachmentStatus(ApiCallStatus.COMPLETED) setAttachment(attachmentResult) } if (progress.workflow_state === 'failed') { clearInterval(pollingProgress) const message = progress.message setAttachmentError( new Error( message ? I18n.t('%{message}', {message}) : I18n.t('There was an error exporting the gradebook') ) ) setAttachmentStatus(ApiCallStatus.FAILED) } clearInterval(pollingProgress) }, 2000) } catch (e) { setAttachmentError(e as Error) setAttachmentStatus(ApiCallStatus.FAILED) } } return { exportGradebook, attachmentStatus, attachmentError, attachment, } }
CANCEL
Name
Type
Size
Modified
Actions
↩ ..
DIR
—
—
📄 useContentDropdownOptions.tsx
TSX
3.8 KB
2023-09-24 03:39
EDIT
📄 useCurrentStudentInfo.tsx
TSX
2.5 KB
2023-09-24 03:39
EDIT
📄 useExportGradebook.tsx
TSX
3.6 KB
2023-09-24 03:39
EDIT
📄 useSubmitScore.tsx
TSX
3.2 KB
2023-09-24 03:39
EDIT