From dc4f0a11c942f03edf3eb7f5b4a64ec3c3474cdb Mon Sep 17 00:00:00 2001 From: Aaron Shafovaloff Date: Wed, 20 Dec 2023 14:46:38 -0500 Subject: [PATCH] move apiRequest to reduce circular dependencies Change-Id: I60446bd1e2141160b8fcbc0e13973b89bfe31d07 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/335751 Tested-by: Service Cloud Jenkins Reviewed-by: Michael Hulse QA-Review: Aaron Shafovaloff Product-Review: Aaron Shafovaloff --- .../GlobalSettings/AllowFinalGradeOverrideCheckbox.tsx | 2 +- .../components/GlobalSettings/ShowNotesColumnCheckbox.tsx | 2 +- .../GradingResults/__tests__/GradingResults.test.tsx | 4 ++-- .../components/__tests__/EnhancedIndividualGradebook.test.tsx | 4 ++-- .../enhanced_individual_gradebook/react/hooks/useComments.tsx | 2 +- .../react/hooks/useCustomColumns.tsx | 2 +- .../react/hooks/useDefaultGrade.tsx | 2 +- .../react/hooks/useGradebookNotes.tsx | 2 +- .../react/hooks/useSubmitScore.tsx | 2 +- .../default_gradebook/components/TotalGradeOverrideTray.tsx | 2 +- .../components/__tests__/TotalGradeOverrideTray.test.tsx | 2 +- .../hooks/useFinalGradeOverrideCustomStatus.tsx | 2 +- ui/shared/{util => do-fetch-api-effect}/apiRequest.ts | 3 ++- 13 files changed, 16 insertions(+), 15 deletions(-) rename ui/shared/{util => do-fetch-api-effect}/apiRequest.ts (96%) diff --git a/ui/features/enhanced_individual_gradebook/react/components/GlobalSettings/AllowFinalGradeOverrideCheckbox.tsx b/ui/features/enhanced_individual_gradebook/react/components/GlobalSettings/AllowFinalGradeOverrideCheckbox.tsx index f545af037cb..e2420e737fd 100644 --- a/ui/features/enhanced_individual_gradebook/react/components/GlobalSettings/AllowFinalGradeOverrideCheckbox.tsx +++ b/ui/features/enhanced_individual_gradebook/react/components/GlobalSettings/AllowFinalGradeOverrideCheckbox.tsx @@ -18,7 +18,7 @@ import React from 'react' import {useScope as useI18nScope} from '@canvas/i18n' -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' import type {HandleCheckboxChange} from '../../../types' import CheckboxTemplate from './CheckboxTemplate' diff --git a/ui/features/enhanced_individual_gradebook/react/components/GlobalSettings/ShowNotesColumnCheckbox.tsx b/ui/features/enhanced_individual_gradebook/react/components/GlobalSettings/ShowNotesColumnCheckbox.tsx index 0d0329a4e26..060dadeec21 100644 --- a/ui/features/enhanced_individual_gradebook/react/components/GlobalSettings/ShowNotesColumnCheckbox.tsx +++ b/ui/features/enhanced_individual_gradebook/react/components/GlobalSettings/ShowNotesColumnCheckbox.tsx @@ -19,7 +19,7 @@ import React from 'react' import {useScope as useI18nScope} from '@canvas/i18n' import type {CustomColumn, HandleCheckboxChange, TeacherNotes} from '../../../types' -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' import CheckboxTemplate from './CheckboxTemplate' const I18n = useI18nScope('enhanced_individual_gradebook') diff --git a/ui/features/enhanced_individual_gradebook/react/components/GradingResults/__tests__/GradingResults.test.tsx b/ui/features/enhanced_individual_gradebook/react/components/GradingResults/__tests__/GradingResults.test.tsx index 011c8527461..e03db2e7a3a 100644 --- a/ui/features/enhanced_individual_gradebook/react/components/GradingResults/__tests__/GradingResults.test.tsx +++ b/ui/features/enhanced_individual_gradebook/react/components/GradingResults/__tests__/GradingResults.test.tsx @@ -30,13 +30,13 @@ import { } from './fixtures' import {GRADEBOOK_SUBMISSION_COMMENTS} from '../../../../queries/Queries' import {MockedProvider} from '@apollo/react-testing' -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' import type { AssignmentConnection, GradebookUserSubmissionDetails, } from 'features/enhanced_individual_gradebook/types' -jest.mock('@canvas/util/apiRequest', () => ({ +jest.mock('@canvas/do-fetch-api-effect/apiRequest', () => ({ executeApiRequest: jest.fn(), })) diff --git a/ui/features/enhanced_individual_gradebook/react/components/__tests__/EnhancedIndividualGradebook.test.tsx b/ui/features/enhanced_individual_gradebook/react/components/__tests__/EnhancedIndividualGradebook.test.tsx index e31256e95f0..8da7fffc539 100644 --- a/ui/features/enhanced_individual_gradebook/react/components/__tests__/EnhancedIndividualGradebook.test.tsx +++ b/ui/features/enhanced_individual_gradebook/react/components/__tests__/EnhancedIndividualGradebook.test.tsx @@ -28,11 +28,11 @@ import userSettings from '@canvas/user-settings' import {GradebookSortOrder} from '../../../types/gradebook.d' import * as ReactRouterDom from 'react-router-dom' import doFetchApi from '@canvas/do-fetch-api-effect' -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' jest.mock('axios') // mock axios for final grade override helper API call jest.mock('@canvas/do-fetch-api-effect', () => jest.fn()) // mock doFetchApi for final grade override helper API call -jest.mock('@canvas/util/apiRequest', () => ({ +jest.mock('@canvas/do-fetch-api-effect/apiRequest', () => ({ executeApiRequest: jest.fn(), })) const mockedAxios = axios as jest.Mocked diff --git a/ui/features/enhanced_individual_gradebook/react/hooks/useComments.tsx b/ui/features/enhanced_individual_gradebook/react/hooks/useComments.tsx index 7e2ac542fbc..a27005dc853 100644 --- a/ui/features/enhanced_individual_gradebook/react/hooks/useComments.tsx +++ b/ui/features/enhanced_individual_gradebook/react/hooks/useComments.tsx @@ -19,7 +19,7 @@ import {useCallback, useEffect, useState} from 'react' import {useQuery} from 'react-apollo' import {useScope as useI18nScope} from '@canvas/i18n' -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' import {GRADEBOOK_SUBMISSION_COMMENTS} from '../../queries/Queries' import { diff --git a/ui/features/enhanced_individual_gradebook/react/hooks/useCustomColumns.tsx b/ui/features/enhanced_individual_gradebook/react/hooks/useCustomColumns.tsx index a10f7f3bade..1b2af91d7df 100644 --- a/ui/features/enhanced_individual_gradebook/react/hooks/useCustomColumns.tsx +++ b/ui/features/enhanced_individual_gradebook/react/hooks/useCustomColumns.tsx @@ -18,7 +18,7 @@ import {useEffect, useState} from 'react' import type {CustomColumn} from '../../types' -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' export const useCustomColumns = (getCustomColumnsUrl?: string | null) => { const [customColumns, setCustomColumns] = useState(null) diff --git a/ui/features/enhanced_individual_gradebook/react/hooks/useDefaultGrade.tsx b/ui/features/enhanced_individual_gradebook/react/hooks/useDefaultGrade.tsx index 8efd37a93af..621bacb8cf4 100644 --- a/ui/features/enhanced_individual_gradebook/react/hooks/useDefaultGrade.tsx +++ b/ui/features/enhanced_individual_gradebook/react/hooks/useDefaultGrade.tsx @@ -17,7 +17,7 @@ */ import {useCallback, useState} from 'react' -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' import {ApiCallStatus, type SubmissionGradeChange} from '../../types' import {mapToSubmissionGradeChange} from '../../utils/gradebookUtils' diff --git a/ui/features/enhanced_individual_gradebook/react/hooks/useGradebookNotes.tsx b/ui/features/enhanced_individual_gradebook/react/hooks/useGradebookNotes.tsx index f135cb52a61..331c3237281 100644 --- a/ui/features/enhanced_individual_gradebook/react/hooks/useGradebookNotes.tsx +++ b/ui/features/enhanced_individual_gradebook/react/hooks/useGradebookNotes.tsx @@ -19,7 +19,7 @@ import {useScope as useI18nScope} from '@canvas/i18n' import {useEffect, useState} from 'react' import {ApiCallStatus, type CustomColumnDatum} from '../../types' -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' const I18n = useI18nScope('enhanced_individual_gradebook_submit_score') diff --git a/ui/features/enhanced_individual_gradebook/react/hooks/useSubmitScore.tsx b/ui/features/enhanced_individual_gradebook/react/hooks/useSubmitScore.tsx index 1d7d73b8a61..292609fadb0 100644 --- a/ui/features/enhanced_individual_gradebook/react/hooks/useSubmitScore.tsx +++ b/ui/features/enhanced_individual_gradebook/react/hooks/useSubmitScore.tsx @@ -16,7 +16,7 @@ * with this program. If not, see . */ -import {executeApiRequest} from '@canvas/util/apiRequest' +import {executeApiRequest} from '@canvas/do-fetch-api-effect/apiRequest' import GradeFormatHelper from '@canvas/grading/GradeFormatHelper' import {useScope as useI18nScope} from '@canvas/i18n' import numberHelper from '@canvas/i18n/numberHelper' diff --git a/ui/features/gradebook/react/default_gradebook/components/TotalGradeOverrideTray.tsx b/ui/features/gradebook/react/default_gradebook/components/TotalGradeOverrideTray.tsx index c6fbbcd0f16..a83b3f998e8 100644 --- a/ui/features/gradebook/react/default_gradebook/components/TotalGradeOverrideTray.tsx +++ b/ui/features/gradebook/react/default_gradebook/components/TotalGradeOverrideTray.tsx @@ -37,7 +37,7 @@ import useStore from '../stores' import {gradeOverrideCustomStatus} from '../FinalGradeOverrides/FinalGradeOverride.utils' import {useFinalGradeOverrideCustomStatus} from '../hooks/useFinalGradeOverrideCustomStatus' import {showFlashError} from '@canvas/alerts/react/FlashAlert' -import {ApiCallStatus} from '@canvas/util/apiRequest' +import {ApiCallStatus} from '@canvas/do-fetch-api-effect/apiRequest' const I18n = useI18nScope('gradebook') diff --git a/ui/features/gradebook/react/default_gradebook/components/__tests__/TotalGradeOverrideTray.test.tsx b/ui/features/gradebook/react/default_gradebook/components/__tests__/TotalGradeOverrideTray.test.tsx index f2bf7eca55d..4417a40480f 100644 --- a/ui/features/gradebook/react/default_gradebook/components/__tests__/TotalGradeOverrideTray.test.tsx +++ b/ui/features/gradebook/react/default_gradebook/components/__tests__/TotalGradeOverrideTray.test.tsx @@ -20,7 +20,7 @@ import React from 'react' import {render, fireEvent} from '@testing-library/react' import GradeOverrideEntry from '@canvas/grading/GradeEntry/GradeOverrideEntry' -import {ApiCallStatus} from '@canvas/util/apiRequest' +import {ApiCallStatus} from '@canvas/do-fetch-api-effect/apiRequest' import {TotalGradeOverrideTray, type TotalGradeOverrideTrayProps} from '../TotalGradeOverrideTray' import useStore from '../../stores' import * as FinalGradeOverrideHooks from '../../hooks/useFinalGradeOverrideCustomStatus' diff --git a/ui/features/gradebook/react/default_gradebook/hooks/useFinalGradeOverrideCustomStatus.tsx b/ui/features/gradebook/react/default_gradebook/hooks/useFinalGradeOverrideCustomStatus.tsx index 4af5d4bf104..52b40eeb338 100644 --- a/ui/features/gradebook/react/default_gradebook/hooks/useFinalGradeOverrideCustomStatus.tsx +++ b/ui/features/gradebook/react/default_gradebook/hooks/useFinalGradeOverrideCustomStatus.tsx @@ -19,7 +19,7 @@ import {useState} from 'react' import {useMutation} from 'react-apollo' import gql from 'graphql-tag' -import {ApiCallStatus} from '@canvas/util/apiRequest' +import {ApiCallStatus} from '@canvas/do-fetch-api-effect/apiRequest' const SET_OVERRIDE_STATUS_MUTATION = gql` mutation SetOverrideStatusMutation( diff --git a/ui/shared/util/apiRequest.ts b/ui/shared/do-fetch-api-effect/apiRequest.ts similarity index 96% rename from ui/shared/util/apiRequest.ts rename to ui/shared/do-fetch-api-effect/apiRequest.ts index 8839c8393e4..bc3f97739b0 100644 --- a/ui/shared/util/apiRequest.ts +++ b/ui/shared/do-fetch-api-effect/apiRequest.ts @@ -16,7 +16,7 @@ * with this program. If not, see . */ -import doFetchApi from '@canvas/do-fetch-api-effect' +import doFetchApi from './index' export type ApiResponse = { data: T @@ -36,6 +36,7 @@ export type ApiRequest = { } export async function executeApiRequest(request: ApiRequest): Promise> { + // @ts-expect-error const {json, response, link} = await doFetchApi(request) return {