Skip to content

Commit

Permalink
fix: dropped telemetry context provider and custom hook
Browse files Browse the repository at this point in the history
  • Loading branch information
MacQSL committed Dec 16, 2024
1 parent c94841b commit 1ef61b5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 78 deletions.
48 changes: 0 additions & 48 deletions app/src/contexts/telemetryContext.tsx

This file was deleted.

16 changes: 12 additions & 4 deletions app/src/contexts/telemetryTableContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { SIMS_TELEMETRY_HIDDEN_COLUMNS } from 'constants/session-storage';
import { default as dayjs } from 'dayjs';
import { APIError } from 'hooks/api/useAxios';
import { useBiohubApi } from 'hooks/useBioHubApi';
import { useDialogContext, useSurveyContext, useTelemetryContext } from 'hooks/useContext';
import { useDialogContext, useSurveyContext } from 'hooks/useContext';
import useDataLoader from 'hooks/useDataLoader';
import { usePersistentState } from 'hooks/usePersistentState';
import { GetSurveyTelemetryResponse } from 'interfaces/useTelemetryApi.interface';
import { createContext, PropsWithChildren, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { ApiPaginationRequestOptions } from 'types/misc';
import { firstOrNull } from 'utils/Utils';
import { v4 as uuidv4 } from 'uuid';
import { RowValidationError, TableValidationModel } from '../components/data-grid/DataGridValidationAlert';
Expand Down Expand Up @@ -178,9 +180,15 @@ export const TelemetryTableContextProvider = (props: IAllTelemetryTableContextPr
const surveyContext = useSurveyContext();
const dialogContext = useDialogContext();

Check warning on line 181 in app/src/contexts/telemetryTableContext.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/contexts/telemetryTableContext.tsx#L180-L181

Added lines #L180 - L181 were not covered by tests

const {
telemetryDataLoader: { data: telemetryData, isLoading: isLoadingTelemetryData, refresh: refreshTelemetryData }
} = useTelemetryContext();
const telemetryDataLoader = useDataLoader((pagination?: ApiPaginationRequestOptions) =>
biohubApi.telemetry.getTelemetryForSurvey(surveyContext.projectId, surveyContext.surveyId, pagination)

Check warning on line 184 in app/src/contexts/telemetryTableContext.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/contexts/telemetryTableContext.tsx#L183-L184

Added lines #L183 - L184 were not covered by tests
);

useEffect(() => {
telemetryDataLoader.load();

Check warning on line 188 in app/src/contexts/telemetryTableContext.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/contexts/telemetryTableContext.tsx#L187-L188

Added lines #L187 - L188 were not covered by tests
}, [telemetryDataLoader]);

const { data: telemetryData, isLoading: isLoadingTelemetryData, refresh: refreshTelemetryData } = telemetryDataLoader;

Check warning on line 191 in app/src/contexts/telemetryTableContext.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/contexts/telemetryTableContext.tsx#L191

Added line #L191 was not covered by tests

// The data grid rows
const [rows, setRows] = useState<IManualTelemetryTableRow[]>([]);
Expand Down
5 changes: 1 addition & 4 deletions app/src/features/surveys/SurveyRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PROJECT_PERMISSION, SYSTEM_ROLE } from 'constants/roles';
import { AnimalPageContextProvider } from 'contexts/animalPageContext';
import { DialogContextProvider } from 'contexts/dialogContext';
import { ObservationsContextProvider } from 'contexts/observationsContext';
import { TelemetryContextProvider } from 'contexts/telemetryContext';
import { AnimalRouter } from 'features/surveys/animals/AnimalRouter';
import EditSurveyPage from 'features/surveys/edit/EditSurveyPage';
import { SurveyObservationPage } from 'features/surveys/observations/SurveyObservationPage';
Expand Down Expand Up @@ -70,9 +69,7 @@ const SurveyRouter: React.FC = () => {
PROJECT_PERMISSION.OBSERVER
]}
validSystemRoles={[SYSTEM_ROLE.SYSTEM_ADMIN, SYSTEM_ROLE.DATA_ADMINISTRATOR]}>
<TelemetryContextProvider>
<TelemetryRouter />
</TelemetryContextProvider>
<TelemetryRouter />
</ProjectRoleRouteGuard>
</RouteWithTitle>

Expand Down
11 changes: 7 additions & 4 deletions app/src/features/surveys/telemetry/list/SurveyDeploymentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import { LoadingGuard } from 'components/loading/LoadingGuard';
import { SkeletonList } from 'components/loading/SkeletonLoaders';
import { SurveyDeploymentListItem } from 'features/surveys/telemetry/list/SurveyDeploymentListItem';
import { useBiohubApi } from 'hooks/useBioHubApi';
import { useCodesContext, useDialogContext, useSurveyContext, useTelemetryContext } from 'hooks/useContext';
import { useCodesContext, useDialogContext, useSurveyContext } from 'hooks/useContext';
import useDataLoader from 'hooks/useDataLoader';
import { useEffect, useState } from 'react';
import { Link as RouterLink } from 'react-router-dom';
import { ApiPaginationRequestOptions } from 'types/misc';

/**
* Renders a list of all deployments in the survey
Expand All @@ -32,18 +34,19 @@ export const SurveyDeploymentList = () => {
const dialogContext = useDialogContext();
const codesContext = useCodesContext();
const surveyContext = useSurveyContext();
const telemetryContext = useTelemetryContext();

const biohubApi = useBiohubApi();

const deploymentDataLoader = telemetryContext.deploymentDataLoader;

const [bulkDeploymentAnchorEl, setBulkDeploymentAnchorEl] = useState<MenuProps['anchorEl']>(null);
const [deploymentAnchorEl, setDeploymentAnchorEl] = useState<MenuProps['anchorEl']>(null);

const [checkboxSelectedIds, setCheckboxSelectedIds] = useState<number[]>([]);
const [selectedDeploymentId, setSelectedDeploymentId] = useState<number | null>();

const deploymentDataLoader = useDataLoader((pagination?: ApiPaginationRequestOptions) =>
biohubApi.telemetryDeployment.getDeploymentsInSurvey(surveyContext.projectId, surveyContext.surveyId, pagination)

Check warning on line 47 in app/src/features/surveys/telemetry/list/SurveyDeploymentList.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/telemetry/list/SurveyDeploymentList.tsx#L46-L47

Added lines #L46 - L47 were not covered by tests
);

const deployments = deploymentDataLoader.data?.deployments ?? [];
const deploymentsCount = deploymentDataLoader.data?.count ?? 0;

Expand Down
18 changes: 0 additions & 18 deletions app/src/hooks/useContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { IObservationsTableContext, ObservationsTableContext } from 'contexts/ob
import { IProjectContext, ProjectContext } from 'contexts/projectContext';
import { ISurveyContext, SurveyContext } from 'contexts/surveyContext';
import { ITaxonomyContext, TaxonomyContext } from 'contexts/taxonomyContext';
import { ITelemetryContext, TelemetryContext } from 'contexts/telemetryContext';
import { IAllTelemetryTableContext, TelemetryTableContext } from 'contexts/telemetryTableContext';
import { useContext } from 'react';

Expand Down Expand Up @@ -198,20 +197,3 @@ export const useAnimalPageContext = (): IAnimalPageContext => {

return context;
};

/**
* Returns an instance of `ITelemetryContext` from `TelemetryContext`.
*
* @return {*} {ITelemetryContext}
*/
export const useTelemetryContext = (): ITelemetryContext => {
const context = useContext(TelemetryContext);

if (!context) {
throw Error(
'ObservationsContext is undefined, please verify you are calling useObservationsContext() as child of an <ObservationsContextProvider> component.'
);
}

return context;
};

0 comments on commit 1ef61b5

Please sign in to comment.