Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura committed Jan 21, 2025
1 parent b7317db commit 4683f3f
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 101 deletions.
118 changes: 59 additions & 59 deletions app/src/features/surveys/observations/create/CreateObservationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,71 +222,71 @@ const CreateObservationPage = () => {

return (

Check warning on line 223 in app/src/features/surveys/observations/create/CreateObservationPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/create/CreateObservationPage.tsx#L223

Added line #L223 was not covered by tests
<>
<TaxonomyContextProvider>
<Prompt when={enableCancelCheck} message={locationChangeInterceptor} />
<PageHeader
title="Create Observation"
breadCrumbJSX={
<Breadcrumbs aria-label="breadcrumb" separator={'>'}>
<Link component={RouterLink} underline="hover" to={`/admin/projects/${projectId}/`}>
{projectName}
</Link>
<Link component={RouterLink} underline="hover" to={`/admin/projects/${projectId}/surveys/${surveyId}`}>
{surveyName}
</Link>
<Link
component={RouterLink}
underline="hover"
to={`/admin/projects/${projectId}/surveys/${surveyId}/observations`}>
Observations
</Link>
<Typography variant="body2" component="span" color="textSecondary" aria-current="page">
Create Observation
</Typography>
</Breadcrumbs>
}
buttonJSX={
<>
<LoadingButton
loading={isSaving}
type="submit"
color="primary"
variant="contained"
onClick={() => formikRef.current?.submitForm()}
data-testid="submit-observation-button">
Save and Exit
</LoadingButton>
<Button disabled={isSaving} color="primary" variant="outlined" onClick={handleCancel}>
Cancel
</Button>
</>
}
/>
<Prompt when={enableCancelCheck} message={locationChangeInterceptor} />
<PageHeader
title="Create Observation"
breadCrumbJSX={
<Breadcrumbs aria-label="breadcrumb" separator={'>'}>
<Link component={RouterLink} underline="hover" to={`/admin/projects/${projectId}/`}>
{projectName}
</Link>
<Link component={RouterLink} underline="hover" to={`/admin/projects/${projectId}/surveys/${surveyId}`}>
{surveyName}
</Link>
<Link
component={RouterLink}
underline="hover"
to={`/admin/projects/${projectId}/surveys/${surveyId}/observations`}>
Observations
</Link>
<Typography variant="body2" component="span" color="textSecondary" aria-current="page">
Create Observation
</Typography>
</Breadcrumbs>
}
buttonJSX={
<>
<LoadingButton
loading={isSaving}
type="submit"
color="primary"
variant="contained"
onClick={() => formikRef.current?.submitForm()}

Check warning on line 254 in app/src/features/surveys/observations/create/CreateObservationPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/create/CreateObservationPage.tsx#L254

Added line #L254 was not covered by tests
data-testid="submit-observation-button">
Save and Exit
</LoadingButton>
<Button disabled={isSaving} color="primary" variant="outlined" onClick={handleCancel}>
Cancel
</Button>
</>
}
/>

<Container maxWidth="xl" sx={{ py: 3 }}>
<Paper sx={{ p: 5 }}>
<Container maxWidth="xl" sx={{ py: 3 }}>
<Paper sx={{ p: 5 }}>
<TaxonomyContextProvider>
<ObservationForm
initialData={initialObservationValues}
handleSubmit={(formikData) => createObservation(formikData)}

Check warning on line 270 in app/src/features/surveys/observations/create/CreateObservationPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/create/CreateObservationPage.tsx#L270

Added line #L270 was not covered by tests
formikRef={formikRef}
/>
<Stack mt={4} flexDirection="row" justifyContent="flex-end" gap={1}>
<LoadingButton
loading={isSaving}
type="submit"
color="primary"
variant="contained"
onClick={() => formikRef.current?.submitForm()}
data-testid="submit-observation-button">
Save and Exit
</LoadingButton>
<Button disabled={isSaving} color="primary" variant="outlined" onClick={handleCancel}>
Cancel
</Button>
</Stack>
</Paper>
</Container>
</TaxonomyContextProvider>
</TaxonomyContextProvider>
<Stack mt={4} flexDirection="row" justifyContent="flex-end" gap={1}>
<LoadingButton
loading={isSaving}
type="submit"
color="primary"
variant="contained"
onClick={() => formikRef.current?.submitForm()}

Check warning on line 280 in app/src/features/surveys/observations/create/CreateObservationPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/create/CreateObservationPage.tsx#L280

Added line #L280 was not covered by tests
data-testid="submit-observation-button">
Save and Exit
</LoadingButton>
<Button disabled={isSaving} color="primary" variant="outlined" onClick={handleCancel}>
Cancel
</Button>
</Stack>
</Paper>
</Container>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import {
export interface IObservationSubcountForm {
_id?: string; // Temporary id for react key
observation_subcount_id: number | null;
observation_subcount_sign_id: number | null;
subcount: number | null;
comment: string | null;
measurements: (SubcountQualitativeMeasurement | SubcountQuantitativeMeasurement)[];
markings?: never[]; // TODO - future enhancement
// TODO - move environments out of subcounts and into standard columns
observation_subcount_sign_id: number | null;
// TODO - move environments out of subcounts and into standard columns
environments: (SubcountQualitativeEnvironment | SubcountQuantitativeEnvironment)[];
}

/**
* Defines the form data structure for the ObservationForm component.
*/
export interface IObservationForm {
standardColumns: Omit<StandardObservationColumns, 'survey_observation_id'> & {
survey_observation_id: number | null;
Expand Down
13 changes: 7 additions & 6 deletions app/src/features/surveys/observations/form/ObservationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const ObservationForm = <TInitialFormikData extends IObservationForm>(

{/* Species Form */}
<HorizontalSplitFormComponent title="Species" summary="Enter the species observed">
<ObservationSpeciesForm formikFieldName="standardColumns" />
<ObservationSpeciesForm formikSectionName="standardColumns" />
</HorizontalSplitFormComponent>

<Divider />
Expand All @@ -135,13 +135,14 @@ const ObservationForm = <TInitialFormikData extends IObservationForm>(

{/* Location */}
<HorizontalSplitFormComponent title="Location" summary="Enter the location of the observation">
<ObservationLocationForm formikFieldName="standardColumns" />
<ObservationLocationForm formikSectionName="standardColumns" />
</HorizontalSplitFormComponent>

<Divider />

{/* Datetime Form */}
<HorizontalSplitFormComponent title="Date & Time" summary="Enter the date and time of the observation">
<ObservationDateTimeForm formikFieldName="standardColumns" />
<ObservationDateTimeForm formikSectionName="standardColumns" />
</HorizontalSplitFormComponent>

<Divider />
Expand All @@ -150,21 +151,21 @@ const ObservationForm = <TInitialFormikData extends IObservationForm>(
<HorizontalSplitFormComponent
title="Environmental Conditions"
summary="Enter information about the environment where the observation was made">
<ObservationEnvironmentForm formikFieldName="standardColumns.environments" />
<ObservationEnvironmentForm formikSectionName="standardColumns.environments" />
</HorizontalSplitFormComponent>

<Divider />

{/* Subcounts Form */}
<HorizontalSplitFormComponent title="Subcounts" summary="Add subcounts to the observation">
<SubcountForm />
<SubcountForm formikSectionName="subcounts" />
</HorizontalSplitFormComponent>

<Divider />

{/* Comments Form */}
<HorizontalSplitFormComponent title="Comments" summary="Add comments about the observation">
<ObservationCommentForm />
<ObservationCommentForm formikSectionName="standardColumns" />
</HorizontalSplitFormComponent>

<Divider />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ import Button from '@mui/material/Button';
import CustomTextField from 'components/fields/CustomTextField';
import { useState } from 'react';

export interface IObservationCommentFormProps {
formikSectionName: string;
}

/**
* Returns form controls for adding comments to the observation
*
* @template FormikValuesType
* @return {*}
*/
export const ObservationCommentForm = () => {
export const ObservationCommentForm = (props: IObservationCommentFormProps) => {
const { formikSectionName } = props;

Check warning on line 18 in app/src/features/surveys/observations/form/comment/ObservationCommentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/comment/ObservationCommentForm.tsx#L17-L18

Added lines #L17 - L18 were not covered by tests

const [showComment, setShowComment] = useState(false);

Check warning on line 20 in app/src/features/surveys/observations/form/comment/ObservationCommentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/comment/ObservationCommentForm.tsx#L20

Added line #L20 was not covered by tests

return (

Check warning on line 22 in app/src/features/surveys/observations/form/comment/ObservationCommentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/comment/ObservationCommentForm.tsx#L22

Added line #L22 was not covered by tests
<>
{showComment ? (
<CustomTextField
name="standardColumns.comment"
name={`${formikSectionName}.comment`}
label="Comment"
maxLength={200}
other={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import SingleDateField from 'components/fields/SingleDateField';
import { TimeField } from 'components/fields/TimeField';

interface IObservationDateTimeFormProps {
formikFieldName: string;
formikSectionName: string;
}

const ObservationDateTimeForm = (props: IObservationDateTimeFormProps) => {
const { formikFieldName } = props;
const { formikSectionName } = props;

Check warning on line 10 in app/src/features/surveys/observations/form/date/ObservationDateTimeForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/date/ObservationDateTimeForm.tsx#L9-L10

Added lines #L9 - L10 were not covered by tests

return (

Check warning on line 12 in app/src/features/surveys/observations/form/date/ObservationDateTimeForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/date/ObservationDateTimeForm.tsx#L12

Added line #L12 was not covered by tests
<Stack spacing={2}>
<SingleDateField label="Date" name={`${formikFieldName}.observation_date`} />
<TimeField label="Time" name={`${formikFieldName}.observation_time`} id="time" required={false} />
<SingleDateField label="Date" name={`${formikSectionName}.observation_date`} />
<TimeField label="Time" name={`${formikSectionName}.observation_time`} id="time" required={false} />
</Stack>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const initialEnvironmentValues = {
};

interface IObservationEnvironmentFormProps {
formikFieldName: string; // Accept formikFieldName as a prop
formikSectionName: string;
}

/**
Expand All @@ -35,7 +35,8 @@ interface IObservationEnvironmentFormProps {
* @return {*}
*/
export const ObservationEnvironmentForm = (props: IObservationEnvironmentFormProps) => {
const { formikFieldName } = props;
const { formikSectionName } = props;

Check warning on line 38 in app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx#L37-L38

Added lines #L37 - L38 were not covered by tests

const { values } = useFormikContext<IObservationForm>();

Check warning on line 40 in app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx#L40

Added line #L40 was not covered by tests

const biohubApi = useBiohubApi();

Check warning on line 42 in app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx#L42

Added line #L42 was not covered by tests
Expand All @@ -49,11 +50,11 @@ export const ObservationEnvironmentForm = (props: IObservationEnvironmentFormPro
const environments: (
| ObservationSubcountQualitativeEnvironmentObject
| ObservationSubcountQuantitativeEnvironmentObject
)[] = get(values, formikFieldName) ?? [];
)[] = get(values, formikSectionName) ?? [];

return (

Check warning on line 55 in app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx#L55

Added line #L55 was not covered by tests
<FieldArray
name={formikFieldName}
name={formikSectionName}
render={(arrayHelpers: FieldArrayRenderProps) => {
return (

Check warning on line 59 in app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx#L59

Added line #L59 was not covered by tests
<>
Expand All @@ -73,7 +74,7 @@ export const ObservationEnvironmentForm = (props: IObservationEnvironmentFormPro
label: item.name
}))
]}
categoryFormikFieldName={`${formikFieldName}[${index}].environment_quantitative_id`}
categoryFormikFieldName={`${formikSectionName}[${index}].environment_quantitative_id`}
getCategoryDataType={(categoryId) => {
const quantitative = (environmentsDataLoader.data?.quantitative_environments ?? []).find(
(item) => item.environment_quantitative_id === categoryId

Check warning on line 80 in app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx#L80

Added line #L80 was not covered by tests
Expand Down Expand Up @@ -111,8 +112,8 @@ export const ObservationEnvironmentForm = (props: IObservationEnvironmentFormPro
(item) => item.environment_quantitative_id === categoryId

Check warning on line 112 in app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx#L112

Added line #L112 was not covered by tests
);
return quantitative
? `${formikFieldName}[${index}].value`
: `${formikFieldName}[${index}].environment_qualitative_option_id`;
? `${formikSectionName}[${index}].value`
: `${formikSectionName}[${index}].environment_qualitative_option_id`;
}}
onDelete={() => arrayHelpers.remove(index)}

Check warning on line 118 in app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/environments/ObservationEnvironmentForm.tsx#L118

Added line #L118 was not covered by tests
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import Stack from '@mui/material/Stack';
import CustomTextField from 'components/fields/CustomTextField';

interface IObservationLocationFormProps {
formikFieldName: string;
formikSectionName: string;
}

const ObservationLocationForm = (props: IObservationLocationFormProps) => {
const { formikFieldName } = props;
const { formikSectionName } = props;

Check warning on line 9 in app/src/features/surveys/observations/form/location/ObservationLocationForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/location/ObservationLocationForm.tsx#L8-L9

Added lines #L8 - L9 were not covered by tests

return (

Check warning on line 11 in app/src/features/surveys/observations/form/location/ObservationLocationForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/location/ObservationLocationForm.tsx#L11

Added line #L11 was not covered by tests
<Stack spacing={2}>
<CustomTextField label="Latitude" name={`${formikFieldName}.latitude`} other={{ type: 'number' }} />
<CustomTextField label="Longitude" name={`${formikFieldName}.longitude`} other={{ type: 'number' }} />
<CustomTextField label="Latitude" name={`${formikSectionName}.latitude`} other={{ type: 'number' }} />
<CustomTextField label="Longitude" name={`${formikSectionName}.longitude`} other={{ type: 'number' }} />
</Stack>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const ObservationSamplingForm = (props: IObservationSamplingFormProps) => {

const samplingInformationCache = useSamplingInformationCache();

Check warning on line 19 in app/src/features/surveys/observations/form/sampling/ObservationSamplingForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/sampling/ObservationSamplingForm.tsx#L19

Added line #L19 was not covered by tests

// Initialize the cached sampling information.
// Optional when creating new records. Necessary when editing existing records.
samplingInformationCache.initCachedSamplingInformationRef({ periods: [] });

Check warning on line 23 in app/src/features/surveys/observations/form/sampling/ObservationSamplingForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/sampling/ObservationSamplingForm.tsx#L23

Added line #L23 was not covered by tests

return (

Check warning on line 25 in app/src/features/surveys/observations/form/sampling/ObservationSamplingForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/sampling/ObservationSamplingForm.tsx#L25

Added line #L25 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ export const MethodTechniqueField = (props: IMethodTechniqueFieldProps) => {
keyword
});

console.log(response);

if (!isMounted()) {
return;

Check warning on line 76 in app/src/features/surveys/observations/form/sampling/components/MethodTechniqueField.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/form/sampling/components/MethodTechniqueField.tsx#L76

Added line #L76 was not covered by tests
}
Expand Down
Loading

0 comments on commit 4683f3f

Please sign in to comment.