Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMSBIOHUB-627: Fix Manage Telemetry Page #1452

Merged
merged 13 commits into from
Dec 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TelemetryVendorService } from '../../../../../../../../services/telemet
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../../../../../__mocks__/db';
import { bulkDeleteManualTelemetry } from './delete';

describe('telemetry/manual/delete', () => {
describe('delete', () => {
afterEach(() => {
sinon.restore();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as db from '../../../../../../../../database/db';
import { TelemetryVendorService } from '../../../../../../../../services/telemetry-services/telemetry-vendor-service';
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../../../../../__mocks__/db';

describe('telemetry/manual/index', () => {
describe('index', () => {
afterEach(() => {
sinon.restore();
});
Expand Down
2 changes: 1 addition & 1 deletion api/src/paths/telemetry/vendor/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getBctwUser } from '../../../services/bctw-service/bctw-service';
import { BctwTelemetryService } from '../../../services/bctw-service/bctw-telemetry-service';
import { getLogger } from '../../../utils/logger';

const defaultLog = getLogger('paths/telemetry/manual');
const defaultLog = getLogger('paths/telemetry/vendor/deployments');
Copy link
Collaborator

@mauberti-bc mauberti-bc Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this endpoint end with telemetry? like vendor/deployments/telemetry? I would assume that fetching deployments would omit telemetry points and for the telemetry points to be a different request.

EDIT: It looks like this endpoint is making a request to BCTW and is never called in SIMS - can we remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this endpoint is going to be dropped. This change isn't really needed, I was just updating some other instances of 'telemetry/manual' and this got caught in the crossfire.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the related code will need to be updated or removed, etc, as part of the larger work needed to update the Manage Telemetry page.


const vendor_telemetry_responses = {
200: {
Expand Down
7 changes: 4 additions & 3 deletions app/src/components/fields/AnimalAutocompleteField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,21 @@
export const AnimalAutocompleteField = <T extends string | number>(props: IAnimalAutocompleteFieldProps) => {
const { formikFieldName, label, onSelect, defaultAnimal, required, disabled, clearOnSelect, placeholder } = props;

const { touched, errors, setFieldValue, values } = useFormikContext<IAutocompleteFieldOption<T>>();
const { touched, errors, setFieldValue } = useFormikContext<IAutocompleteFieldOption<T>>();

Check warning on line 89 in app/src/components/fields/AnimalAutocompleteField.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/fields/AnimalAutocompleteField.tsx#L89

Added line #L89 was not covered by tests

const surveyContext = useSurveyContext();

// The input field value
const [inputValue, setInputValue] = useState(defaultAnimal?.animal_id ?? '');

useEffect(() => {
if (!defaultAnimal || get(values, formikFieldName)) {
if (!defaultAnimal) {
return;
}

// Set the input value to the default animal's animal_id
setInputValue(String(defaultAnimal.animal_id));
}, [defaultAnimal, formikFieldName, values]);
}, [defaultAnimal]);

// Survey animals to choose from
const options = surveyContext.critterDataLoader.data;
Expand Down
9 changes: 5 additions & 4 deletions app/src/components/fields/DeviceAutocompleteField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
const { formikFieldName, label, options, onSelect, defaultDevice, required, disabled, clearOnSelect, placeholder } =
props;

const { touched, errors, setFieldValue, values } = useFormikContext<IAutocompleteFieldOption<T>>();
const { touched, errors, setFieldValue } = useFormikContext<IAutocompleteFieldOption<T>>();

Check warning on line 94 in app/src/components/fields/DeviceAutocompleteField.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/fields/DeviceAutocompleteField.tsx#L94

Added line #L94 was not covered by tests

const codesContext = useCodesContext();

Expand All @@ -103,12 +103,13 @@
const [inputValue, setInputValue] = useState(String(defaultDevice?.device_id ?? ''));

useEffect(() => {
if (!defaultDevice || get(values, formikFieldName)) {
if (!defaultDevice) {
return;
}

setInputValue(String(defaultDevice.device_id));
}, [defaultDevice, formikFieldName, values]);
// Set the input value to the default device's serial
setInputValue(String(defaultDevice.serial));

Check warning on line 111 in app/src/components/fields/DeviceAutocompleteField.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/fields/DeviceAutocompleteField.tsx#L111

Added line #L111 was not covered by tests
}, [defaultDevice]);

return (
<Autocomplete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Paper from '@mui/material/Paper';
import Stack from '@mui/material/Stack';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import AlertBar from 'components/alert/AlertBar';
import { LoadingGuard } from 'components/loading/LoadingGuard';
import { SkeletonList } from 'components/loading/SkeletonLoaders';
import { SurveyDeploymentListItem } from 'features/surveys/telemetry/list/SurveyDeploymentListItem';
Expand Down Expand Up @@ -260,7 +259,7 @@ export const SurveyDeploymentList = (props: ISurveyDeploymentListProps) => {
}}>
<MenuItem
component={RouterLink}
to={`/admin/projects/${surveyContext.projectId}/surveys/${surveyContext.surveyId}/telemetry/deployment/${selectedDeploymentId}/edit`}
to={`/admin/projects/${surveyContext.projectId}/surveys/${surveyContext.surveyId}/telemetry/manage/deployment/${selectedDeploymentId}/edit`}
onClick={() => setDeploymentAnchorEl(null)}>
<ListItemIcon>
<Icon path={mdiPencilOutline} size={1} />
Expand Down Expand Up @@ -392,12 +391,6 @@ export const SurveyDeploymentList = (props: ISurveyDeploymentListProps) => {
sx={{
background: grey[100]
}}>
<AlertBar
severity="error"
text="We're fixing a bug preventing deployments from loading. Please check back later."
title="There's a Bug!"
variant="standard"
/>
{deployments.map((deployment) => {
const animal = surveyContext.critterDataLoader.data?.find(
(animal) => animal.critterbase_critter_id === deployment.critterbase_critter_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const DeploymentForm = (props: IDeploymentFormProps) => {
summary={
<>
Enter information about the device and animal.
<Typography color="textSecondary">
<Typography color="textSecondary" component="span" display="block">
You must&nbsp;
<Typography
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const DeploymentsContainer = () => {
isLoading={deploymentsDataLoader.isLoading}
isLoadingFallback={<SkeletonTable numberOfLines={5} />}
isLoadingFallbackDelay={100}>
<Box p={2}>
<Box>
<LoadingGuard
isLoading={deploymentsDataLoader.isLoading || !deploymentsDataLoader.isReady}
isLoadingFallback={<SkeletonTable />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@
field: 'deployment2_id',
headerName: 'Deployment ID',
description: 'The unique key for the deployment',
width: 100,
minWidth: 100,
width: 85,
minWidth: 85,
renderHeader: (params) => (
<Tooltip title={params.colDef.description}>
<Typography color={grey[500]} variant="body2" fontWeight={700}>
Expand Down Expand Up @@ -198,7 +198,7 @@
return (
<Typography variant="body2">
{serial}
<Typography fontSize="inherit" color="textSecondary">
<Typography fontSize="inherit" color="textSecondary" component="span" display="block">
{vendor}
</Typography>
</Typography>
Expand All @@ -213,7 +213,7 @@
renderCell: (params) => (
<Typography>
{params.row.frequency}&nbsp;
<Typography component="span" color="textSecondary">
<Typography color="textSecondary" component="span">
{codesContext.codesDataLoader.data?.frequency_units.find(
(frequencyUnit) => frequencyUnit.id === params.row.frequency_unit_id
)?.name ?? null}
Expand Down Expand Up @@ -241,15 +241,19 @@
headerName: 'End',
description: 'The end date of the deployment',
flex: 1,
renderCell: (params) => (
<>
{params.row.attachment_end_time
? dayjs(`${params.row.attachment_end_date} ${params.row.attachment_end_time}`).format(
DATE_FORMAT.MediumDateTimeFormat
)
: dayjs(params.row.attachment_end_date).format(DATE_FORMAT.MediumDateFormat)}
</>
)
renderCell: (params) => {
if (!params.row.attachment_end_date) {
return null;

Check warning on line 246 in app/src/features/surveys/telemetry/manage/deployments/table/DeploymentsTable.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/telemetry/manage/deployments/table/DeploymentsTable.tsx#L246

Added line #L246 was not covered by tests
}

if (params.row.attachment_end_time) {
return dayjs(`${params.row.attachment_end_date} ${params.row.attachment_end_time}`).format(

Check warning on line 250 in app/src/features/surveys/telemetry/manage/deployments/table/DeploymentsTable.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/telemetry/manage/deployments/table/DeploymentsTable.tsx#L250

Added line #L250 was not covered by tests
DATE_FORMAT.MediumDateTimeFormat
);
}

return dayjs(params.row.attachment_end_date).format(DATE_FORMAT.MediumDateFormat);

Check warning on line 255 in app/src/features/surveys/telemetry/manage/deployments/table/DeploymentsTable.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/telemetry/manage/deployments/table/DeploymentsTable.tsx#L255

Added line #L255 was not covered by tests
}
},
{
field: 'status',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export const DevicesTable = (props: IDevicesTableProps) => {
field: 'device_id',
headerName: 'Device ID',
description: 'The unique key for the device',
width: 100,
minWidth: 100,
width: 85,
minWidth: 85,
renderHeader: (params) => (
<Tooltip title={params.colDef.description}>
<Typography color={grey[500]} variant="body2" fontWeight={700}>
Expand Down
Loading