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-353/325: Survey form updates #1149

Merged
merged 13 commits into from
Oct 31, 2023
Merged
4 changes: 1 addition & 3 deletions api/src/paths/project/{projectId}/survey/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ POST.apiDoc = {
additional_details: {
type: 'string'
},
field_method_id: {
type: 'number'
},
vantage_code_ids: {
type: 'array',
items: {
Expand Down Expand Up @@ -245,6 +242,7 @@ POST.apiDoc = {
properties: {
strategies: {
type: 'array',
minItems: 1,
items: {
type: 'string'
}
Expand Down
4 changes: 0 additions & 4 deletions api/src/paths/project/{projectId}/survey/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,13 @@ GET.apiDoc = {
description: 'Survey Details',
type: 'object',
required: [
'field_method_id',
'additional_details',
'intended_outcome_id',
'ecological_season_id',
'vantage_code_ids',
'revision_count'
],
properties: {
field_method_id: {
type: 'number'
},
additional_details: {
type: 'string',
nullable: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ PUT.apiDoc = {
required: [
'intended_outcome_id',
'additional_details',
'field_method_id',
'vantage_code_ids',
'ecological_season_id',
'revision_count'
Expand All @@ -225,9 +224,6 @@ PUT.apiDoc = {
additional_details: {
type: 'string'
},
field_method_id: {
type: 'number'
},
vantage_code_ids: {
type: 'array',
items: {
Expand Down Expand Up @@ -280,6 +276,7 @@ PUT.apiDoc = {
properties: {
strategies: {
type: 'array',
minItems: 1,
items: {
type: 'string'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,13 @@ GET.apiDoc = {
description: 'Survey Details',
type: 'object',
required: [
'field_method_id',
'additional_details',
'intended_outcome_id',
'ecological_season_id',
'vantage_code_ids',
'revision_count'
],
properties: {
field_method_id: {
type: 'number'
},
additional_details: {
type: 'string',
nullable: true
Expand Down
4 changes: 0 additions & 4 deletions api/src/paths/project/{projectId}/survey/{surveyId}/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,13 @@ GET.apiDoc = {
description: 'Survey Details',
type: 'object',
required: [
'field_method_id',
'additional_details',
'intended_outcome_id',
'ecological_season_id',
'vantage_code_ids',
'revision_count'
],
properties: {
field_method_id: {
type: 'number'
},
additional_details: {
type: 'string',
nullable: true
Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/xlsx-utils/worksheet-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export function prepareWorksheetCells(worksheet: xlsx.WorkSheet) {
const coord = xlsx.utils.encode_cell({ r, c });
let cell: CellObject = worksheet[coord];

if (!cell || !cell.v) {
if (!cell?.v) {
// Cell is null or has no raw value
continue;
}
Expand Down
5 changes: 0 additions & 5 deletions app/src/features/surveys/CreateSurveyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,6 @@ const CreateSurveyPage = () => {
return { value: item.id, label: item.name, subText: item.description };
}) || []
}
field_methods={
codes?.field_methods.map((item) => {
return { value: item.id, label: item.name, subText: item.description };
}) || []
}
ecological_seasons={
codes?.ecological_seasons.map((item) => {
return { value: item.id, label: item.name, subText: item.description };
Expand Down
15 changes: 2 additions & 13 deletions app/src/features/surveys/components/PurposeAndMethodologyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface IPurposeAndMethodologyForm {
purpose_and_methodology: {
intended_outcome_id: number;
additional_details: string;
field_method_id: number;
field_method_id: number | null;
ecological_season_id: number;
vantage_code_ids: number[];
};
Expand All @@ -23,15 +23,14 @@ export const PurposeAndMethodologyInitialValues: IPurposeAndMethodologyForm = {
purpose_and_methodology: {
intended_outcome_id: '' as unknown as number,
additional_details: '',
field_method_id: '' as unknown as number,
field_method_id: null,
ecological_season_id: '' as unknown as number,
vantage_code_ids: []
}
};

export const PurposeAndMethodologyYupSchema = yup.object().shape({
purpose_and_methodology: yup.object().shape({
field_method_id: yup.number().required('Field Method is Required'),
additional_details: yup.string(),
intended_outcome_id: yup.number().required('Intended Outcome is Required'),
ecological_season_id: yup.number().required('Ecological Season is Required'),
Expand All @@ -41,7 +40,6 @@ export const PurposeAndMethodologyYupSchema = yup.object().shape({

export interface IPurposeAndMethodologyFormProps {
intended_outcomes: ISelectWithSubtextFieldOption[];
field_methods: ISelectWithSubtextFieldOption[];
ecological_seasons: ISelectWithSubtextFieldOption[];
vantage_codes: IMultiAutocompleteFieldOption[];
}
Expand Down Expand Up @@ -82,15 +80,6 @@ const PurposeAndMethodologyForm: React.FC<IPurposeAndMethodologyFormProps> = (pr
Survey Methodology
</Typography>
<Grid container spacing={3}>
<Grid item xs={12}>
<SelectWithSubtextField
id="field_method_id"
name="purpose_and_methodology.field_method_id"
label="Field Method"
options={props.field_methods}
required={true}
/>
</Grid>
<Grid item xs={12}>
<SelectWithSubtextField
id="ecological_season_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const SurveySiteSelectionYupSchema = yup.object().shape({
site_selection: yup.object().shape({
strategies: yup
.array()
.of(yup.string() /* .required('Must select a valid site selection strategy') */)
.required('Must select a valid site selection strategy')
.min(1, 'Must select a valid site selection strategy')
.of(yup.string())
.when('stratums', (stratums: string[], schema: any) => {
return stratums.length > 0
? schema.test(
Expand Down Expand Up @@ -130,8 +132,8 @@ const SurveySiteSelectionForm = (props: ISurveySiteSelectionFormProps) => {
label="Site Selection Strategies"
options={siteStrategies}
selectedOptions={selectedSiteStrategies}
required={false}
onChange={(event, selectedOptions, reason) => {
required={true}
onChange={(_, selectedOptions, reason) => {
// If the user clicks to remove the 'Stratified' option and there are Stratums already defined, then show
// a warning dialogue asking the user if they are sure they want to remove the option and delete the Stratums
if (
Expand Down
5 changes: 0 additions & 5 deletions app/src/features/surveys/edit/EditSurveyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ const EditSurveyForm: React.FC<IEditSurveyForm> = (props) => {
return { value: item.id, label: item.name, subText: item.description };
}) || []
}
field_methods={
props.codes.field_methods.map((item) => {
return { value: item.id, label: item.name, subText: item.description };
}) || []
}
ecological_seasons={
props.codes.ecological_seasons.map((item) => {
return { value: item.id, label: item.name, subText: item.description };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const SurveyGeneralInformation = () => {
return (
<Typography
component="dd"
key={`${focalSpecies}-${index}`}
key={focalSpecies}
sx={{
position: 'relative',
display: 'inline-block',
Expand Down Expand Up @@ -94,7 +94,7 @@ const SurveyGeneralInformation = () => {
return (
<Typography
component="dd"
key={`${ancillarySpecies}-${index}`}
key={ancillarySpecies}
sx={{
position: 'relative',
display: 'inline-block',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('SurveyPurposeAndMethodologyData', () => {
);

expect(getByTestId('survey_intended_outcome').textContent).toEqual('Intended Outcome 1');
expect(getByTestId('survey_field_method').textContent).toEqual('Recruitment');
expect(getByTestId('survey_ecological_season').textContent).toEqual('Season 1');
expect(getAllByTestId('survey_vantage_code').map((item) => item.textContent)).toEqual([
'Vantage Code 1',
Expand Down Expand Up @@ -94,7 +93,6 @@ describe('SurveyPurposeAndMethodologyData', () => {
);

expect(getByTestId('survey_intended_outcome').textContent).toEqual('Intended Outcome 1');
expect(getByTestId('survey_field_method').textContent).toEqual('Recruitment');
expect(getByTestId('survey_ecological_season').textContent).toEqual('Season 1');
expect(getAllByTestId('survey_vantage_code').map((item) => item.textContent)).toEqual([
'Vantage Code 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ const SurveyPurposeAndMethodologyData = () => {
</>
)}

<Box className="row">
<Typography component="dt">Field Method</Typography>
<Typography component="dd" data-testid="survey_field_method">
{Boolean(surveyData.purpose_and_methodology.field_method_id) &&
codes?.field_methods?.find((item: any) => item.id === surveyData.purpose_and_methodology.field_method_id)
?.name}
</Typography>
</Box>

<Box className="row">
<Typography component="dt">Ecological Season</Typography>
<Typography component="dd" data-testid="survey_ecological_season">
Expand Down
19 changes: 19 additions & 0 deletions database/src/migrations/20231030120000_depreciate_field_method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Knex } from 'knex';

/**
*
* @export
* @param {Knex} knex
* @return {*} {Promise<void>}
*/
export async function up(knex: Knex): Promise<void> {
await knex.raw(`--sql
SET search_path = 'biohub';

COMMENT ON COLUMN survey.field_method_id IS '(Depreciated) System generated surrogate primary key identifier.';
`);
}

export async function down(knex: Knex): Promise<void> {
await knex.raw(``);
}
15 changes: 13 additions & 2 deletions database/src/seeds/03_basic_project_survey_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function seed(knex: Knex): Promise<void> {
${insertSurveyVantageData(surveyId)}
${insertSurveyParticipationData(surveyId)}
${insertSurveyLocationData(surveyId)}
${insertSurveySiteStrategy(surveyId)}
`);
}
}
Expand All @@ -82,6 +83,18 @@ const checkAnyProjectExists = () => `
project;
`;

const insertSurveySiteStrategy = (surveyId: number) => `
INSERT into survey_site_strategy
(
survey_id,
site_strategy_id
)
VALUES (
${surveyId},
(select site_strategy_id from site_strategy ss order by random() limit 1)
);
`;

/**
* SQL to insert Project Program data
*
Expand Down Expand Up @@ -303,7 +316,6 @@ const insertSurveyData = (projectId: number) => `
(
project_id,
name,
field_method_id,
additional_details,
start_date,
end_date,
Expand All @@ -315,7 +327,6 @@ const insertSurveyData = (projectId: number) => `
VALUES (
${projectId},
'Seed Survey',
(select field_method_id from field_method order by random() limit 1),
$$${faker.lorem.sentences(2)}$$,
$$${faker.date.between({ from: '2010-01-01T00:00:00-08:00', to: '2015-01-01T00:00:00-08:00' }).toISOString()}$$,
$$${faker.date.between({ from: '2020-01-01T00:00:00-08:00', to: '2025-01-01T00:00:00-08:00' }).toISOString()}$$,
Expand Down
Loading