From 354cc68426c98ccd0aa9c006f4c5eb1e6d866005 Mon Sep 17 00:00:00 2001 From: cgarrettjones Date: Mon, 17 Apr 2023 11:59:01 -0700 Subject: [PATCH 01/54] - expanded project funding to first nations --- .../migrations/20230414000000_SIMS.1.8.0.ts | 40 +++++++++++++ ...0230414000001_tr_project_funding_source.ts | 60 +++++++++++++++++++ .../seeds/03_basic_project_survey_setup.ts | 13 ++++ 3 files changed, 113 insertions(+) create mode 100644 database/src/migrations/20230414000000_SIMS.1.8.0.ts create mode 100644 database/src/migrations/20230414000001_tr_project_funding_source.ts diff --git a/database/src/migrations/20230414000000_SIMS.1.8.0.ts b/database/src/migrations/20230414000000_SIMS.1.8.0.ts new file mode 100644 index 0000000000..e7d3436734 --- /dev/null +++ b/database/src/migrations/20230414000000_SIMS.1.8.0.ts @@ -0,0 +1,40 @@ +import { Knex } from 'knex'; + +/** + * Apply biohub release changes. + * + * @export + * @param {Knex} knex + * @return {*} {Promise} + */ +export async function up(knex: Knex): Promise { + await knex.raw(` + set search_path=biohub_dapi_v1; + + drop view if exists project_funding_source; + + set search_path=biohub; + + ALTER TABLE project_funding_source ALTER COLUMN funding_amount DROP NOT NULL; + ALTER TABLE project_funding_source ALTER COLUMN investment_action_category_id DROP NOT NULL; + alter table project_funding_source add column first_nations_id integer; + + COMMENT ON COLUMN project_funding_source.first_nations_id IS 'System generated surrogate primary key identifier.'; + + drop index project_funding_source_uk1; + CREATE UNIQUE INDEX project_funding_source_uk1 ON project_funding_source(funding_source_project_id, investment_action_category_id, project_id, first_nations_id); + CREATE INDEX "Ref127233" ON project_funding_source(first_nations_id); + + ALTER TABLE project_funding_source ADD CONSTRAINT "Reffirst_nations233" + FOREIGN KEY (first_nations_id) + REFERENCES first_nations(first_nations_id); + + set search_path=biohub_dapi_v1; + + create or replace view project_funding_source as select * from biohub.project_funding_source; + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(``); +} diff --git a/database/src/migrations/20230414000001_tr_project_funding_source.ts b/database/src/migrations/20230414000001_tr_project_funding_source.ts new file mode 100644 index 0000000000..b3abfefcea --- /dev/null +++ b/database/src/migrations/20230414000001_tr_project_funding_source.ts @@ -0,0 +1,60 @@ +import { Knex } from 'knex'; + +/** + * Apply biohub release changes. + * + * @export + * @param {Knex} knex + * @return {*} {Promise} + */ +export async function up(knex: Knex): Promise { + await knex.raw(` + set search_path=biohub; + + create or replace function tr_project_funding_source() returns trigger + language plpgsql + security invoker + as + $$ + -- ******************************************************************* + -- Procedure: tr_project_funding_source + -- Purpose: performs specific data validation + -- + -- MODIFICATION HISTORY + -- Person Date Comments + -- ---------------- ----------- -------------------------------------- + -- charlie.garrettjones@quartech.com + -- 2021-01-03 initial release + -- charlie.garrettjones@quartech.com + -- 2023-04-17 BHBC-2297 adjustment to accommodate first nations + -- ******************************************************************* + declare + _project_id_optional funding_source.project_id_optional%type; + begin + -- ensure funding source is related to an investment action category or first nation + if (((new.investment_action_category_id is null) and (new.first_nations_id is null)) or ((new.investment_action_category_id is not null) and (new.first_nations_id is not null))) then + raise exception 'Funding source must be related to either an investment action category or a first nation.'; + end if; + + -- query funding source to determine optionality of funding source project id when related to investment action category + if ((new.investment_action_category_id is not null) and (new.funding_source_project_id is null)) then + select project_id_optional into _project_id_optional from funding_source + where funding_source_id = (select funding_source_id from investment_action_category where investment_action_category_id = new.investment_action_category_id); + + if not _project_id_optional then + raise exception 'The funding source project id is not optional for the selected funding source.'; + end if; + end if; + + return new; + end; + $$; + + drop trigger if exists project_funding_source_val on biohub.project_funding_source; + create trigger project_funding_source_val before insert or update on biohub.project_funding_source for each row execute procedure tr_project_funding_source(); + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(``); +} diff --git a/database/src/seeds/03_basic_project_survey_setup.ts b/database/src/seeds/03_basic_project_survey_setup.ts index 57f49698e7..511f682b9d 100644 --- a/database/src/seeds/03_basic_project_survey_setup.ts +++ b/database/src/seeds/03_basic_project_survey_setup.ts @@ -33,6 +33,7 @@ export async function seed(knex: Knex): Promise { ${insertSurveyPermitData()} ${insertSurveySpeciesData()} ${insertSurveyFundingData()} + ${insertProjectFundingDataFirstNations()} ${insertSurveyProprietorData()} ${insertSurveyVantageData()} `); @@ -232,6 +233,18 @@ const insertProjectFundingData = () => ` ; `; +/** + * SQL to insert Project Funding data for First Nations + * + */ +const insertProjectFundingDataFirstNations = () => ` + INSERT into project_funding_source + ( first_nations_id, project_id, funding_source_project_id, funding_start_date, funding_end_date ) + VALUES + ( 1, 1, 'AGENCY PROJECT ID', '2023-01-02', '2023-01-30' ) + ; +`; + /** * SQL to insert Project Activity data * From c0c33864c7f684cf3d16d46bede8872b17e91795 Mon Sep 17 00:00:00 2001 From: cgarrettjones Date: Mon, 17 Apr 2023 12:44:23 -0700 Subject: [PATCH 02/54] - adjust project funding source data integrity trigger --- database/src/seeds/03_basic_project_survey_setup.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/src/seeds/03_basic_project_survey_setup.ts b/database/src/seeds/03_basic_project_survey_setup.ts index 511f682b9d..955ee4e540 100644 --- a/database/src/seeds/03_basic_project_survey_setup.ts +++ b/database/src/seeds/03_basic_project_survey_setup.ts @@ -239,9 +239,9 @@ const insertProjectFundingData = () => ` */ const insertProjectFundingDataFirstNations = () => ` INSERT into project_funding_source - ( first_nations_id, project_id, funding_source_project_id, funding_start_date, funding_end_date ) + ( first_nations_id, project_id, funding_start_date, funding_end_date ) VALUES - ( 1, 1, 'AGENCY PROJECT ID', '2023-01-02', '2023-01-30' ) + ( 1, 1, '2023-01-02', '2023-01-30' ) ; `; From 73d51e10e52a2990db10345c9823c292f8e0dae8 Mon Sep 17 00:00:00 2001 From: AlfredRosenthal Date: Thu, 27 Apr 2023 10:09:54 -0700 Subject: [PATCH 03/54] updated funding forms to account for item type --- .../components/ProjectFundingForm.tsx | 12 +++++-- .../components/ProjectFundingItemForm.tsx | 31 ++++++++++++++++--- .../projects/create/CreateProjectForm.tsx | 8 ++++- .../projects/edit/EditProjectForm.tsx | 4 ++- app/src/utils/ProjectStepComponents.tsx | 4 ++- 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/app/src/features/projects/components/ProjectFundingForm.tsx b/app/src/features/projects/components/ProjectFundingForm.tsx index 6c213d4971..cb49b36246 100644 --- a/app/src/features/projects/components/ProjectFundingForm.tsx +++ b/app/src/features/projects/components/ProjectFundingForm.tsx @@ -22,6 +22,7 @@ import React, { useState } from 'react'; import { getFormattedAmount, getFormattedDateRangeString } from 'utils/Utils'; import yup from 'utils/YupSchema'; import ProjectFundingItemForm, { + IMultiAutocompleteFieldOptionWithType, IProjectFundingFormArrayItem, ProjectFundingFormArrayItemInitialValues, ProjectFundingFormArrayItemYupSchema @@ -46,8 +47,9 @@ export interface IInvestmentActionCategoryOption extends IMultiAutocompleteField } export interface IProjectFundingFormProps { - funding_sources: IMultiAutocompleteFieldOption[]; + funding_sources: IMultiAutocompleteFieldOptionWithType[]; investment_action_category: IInvestmentActionCategoryOption[]; + first_nations: IMultiAutocompleteFieldOptionWithType[]; } const useStyles = makeStyles((theme: Theme) => ({ @@ -78,6 +80,10 @@ const useStyles = makeStyles((theme: Theme) => ({ * @return {*} */ const ProjectFundingForm: React.FC = (props) => { + /* + Look into Not applicable table keys + + */ const classes = useStyles(); const formikProps = useFormikContext(); @@ -121,7 +127,7 @@ const ProjectFundingForm: React.FC = (props) => { component={{ element: ( ), @@ -152,7 +158,7 @@ const ProjectFundingForm: React.FC = (props) => { const investment_action_category_value = props.investment_action_category.filter( (item) => item.value === fundingSource.investment_action_category )?.[0]?.label; - + console.log(investment_action_category_value); return ( diff --git a/app/src/features/projects/components/ProjectFundingItemForm.tsx b/app/src/features/projects/components/ProjectFundingItemForm.tsx index 08335b6452..a40c97aef9 100644 --- a/app/src/features/projects/components/ProjectFundingItemForm.tsx +++ b/app/src/features/projects/components/ProjectFundingItemForm.tsx @@ -58,11 +58,35 @@ export const ProjectFundingFormArrayItemYupSchema = yup.object().shape({ end_date: yup.string().isValidDateString().required('Required').isEndDateAfterStartDate('start_date') }); -export interface IProjectFundingItemFormProps { +/* + Ok so what should I be doing here? I think I'll just need to... ummm uhhh + ok so this should just take a single array of items plus the nonsense actions + the items will need the id, label and a type (duh) + + 1. modify the items to add type + 2. Add the first nations names to the list + 3. Add special consideration when selecting a first nations name + 4. modify the save to account for the changes + 5. Modify the fetch to account for any changes in the model + +*/ +export interface IProjectFundingItemFormProps1 { funding_sources: IMultiAutocompleteFieldOption[]; investment_action_category: IInvestmentActionCategoryOption[]; } +export enum FundingSourceType { + FUNDING_SOURCE, + FIRST_NATIONS +} +export interface IMultiAutocompleteFieldOptionWithType extends IMultiAutocompleteFieldOption { + type: FundingSourceType; +} +export interface IProjectFundingItemFormProps { + sources: IMultiAutocompleteFieldOptionWithType[]; + investment_action_category: IInvestmentActionCategoryOption[]; +} + /** * A modal form for a single item of the project funding sources array. * @@ -71,10 +95,9 @@ export interface IProjectFundingItemFormProps { * @param {*} props * @return {*} */ - const ProjectFundingItemForm: React.FC = (props) => { const formikProps = useFormikContext(); - + console.log(props.sources); const { values, touched, errors, handleChange, handleSubmit, setFieldValue } = formikProps; // Only show investment_action_category if certain agency_id values are selected @@ -118,7 +141,7 @@ const ProjectFundingItemForm: React.FC = (props) = error={touched.agency_id && Boolean(errors.agency_id)} displayEmpty inputProps={{ 'aria-label': 'Agency Name', 'data-testid': 'agency-id' }}> - {props.funding_sources.map((item) => ( + {props.sources.map((item) => ( {item.label} diff --git a/app/src/features/projects/create/CreateProjectForm.tsx b/app/src/features/projects/create/CreateProjectForm.tsx index d11a3abacd..d11ffbce92 100644 --- a/app/src/features/projects/create/CreateProjectForm.tsx +++ b/app/src/features/projects/create/CreateProjectForm.tsx @@ -19,6 +19,7 @@ import ProjectFundingForm, { ProjectFundingFormInitialValues, ProjectFundingFormYupSchema } from '../components/ProjectFundingForm'; +import { FundingSourceType } from '../components/ProjectFundingItemForm'; import ProjectIUCNForm, { ProjectIUCNFormInitialValues, ProjectIUCNFormYupSchema } from '../components/ProjectIUCNForm'; import ProjectLocationForm, { ProjectLocationFormInitialValues, @@ -176,7 +177,7 @@ const CreateProjectForm: React.FC = (props) => { { - return { value: item.id, label: item.name }; + return { value: item.id, label: item.name, type: FundingSourceType.FUNDING_SOURCE }; }) || [] } investment_action_category={ @@ -184,6 +185,11 @@ const CreateProjectForm: React.FC = (props) => { return { value: item.id, fs_id: item.fs_id, label: item.name }; }) || [] } + first_nations={ + codes.first_nations?.map((item) => { + return { value: item.id, label: item.name, type: FundingSourceType.FIRST_NATIONS }; + }) || [] + } /> diff --git a/app/src/features/projects/edit/EditProjectForm.tsx b/app/src/features/projects/edit/EditProjectForm.tsx index 66ae754833..ca5292b85c 100644 --- a/app/src/features/projects/edit/EditProjectForm.tsx +++ b/app/src/features/projects/edit/EditProjectForm.tsx @@ -9,6 +9,7 @@ import React from 'react'; import ProjectCoordinatorForm from '../components/ProjectCoordinatorForm'; import ProjectDetailsForm from '../components/ProjectDetailsForm'; import ProjectFundingForm from '../components/ProjectFundingForm'; +import { FundingSourceType } from '../components/ProjectFundingItemForm'; import ProjectIUCNForm from '../components/ProjectIUCNForm'; import ProjectLocationForm from '../components/ProjectLocationForm'; import ProjectObjectivesForm from '../components/ProjectObjectivesForm'; @@ -153,7 +154,7 @@ const EditProjectForm: React.FC = (props) => { { - return { value: item.id, label: item.name }; + return { value: item.id, label: item.name, type: FundingSourceType.FUNDING_SOURCE }; }) || [] } investment_action_category={ @@ -161,6 +162,7 @@ const EditProjectForm: React.FC = (props) => { return { value: item.id, fs_id: item.fs_id, label: item.name }; }) || [] } + first_nations={[]} /> diff --git a/app/src/utils/ProjectStepComponents.tsx b/app/src/utils/ProjectStepComponents.tsx index 65d0b40108..e313b1a872 100644 --- a/app/src/utils/ProjectStepComponents.tsx +++ b/app/src/utils/ProjectStepComponents.tsx @@ -1,6 +1,7 @@ import ProjectCoordinatorForm from 'features/projects/components/ProjectCoordinatorForm'; import ProjectDetailsForm from 'features/projects/components/ProjectDetailsForm'; import ProjectFundingForm from 'features/projects/components/ProjectFundingForm'; +import { FundingSourceType } from 'features/projects/components/ProjectFundingItemForm'; import ProjectIUCNForm from 'features/projects/components/ProjectIUCNForm'; import ProjectLocationForm from 'features/projects/components/ProjectLocationForm'; import ProjectObjectivesForm from 'features/projects/components/ProjectObjectivesForm'; @@ -74,9 +75,10 @@ const ProjectStepComponents: React.FC = (props) => {component === 'ProjectFunding' && ( { - return { value: item.id, label: item.name }; + return { value: item.id, label: item.name, type: FundingSourceType.FUNDING_SOURCE }; }) || [] } investment_action_category={ From a5b8896cc4b136afb594c63c06c607f398af96b2 Mon Sep 17 00:00:00 2001 From: AlfredRosenthal Date: Thu, 27 Apr 2023 10:44:47 -0700 Subject: [PATCH 04/54] added array extension --- app/src/utils/Utils.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/src/utils/Utils.ts b/app/src/utils/Utils.ts index d6434d1628..fe9b90e8db 100644 --- a/app/src/utils/Utils.ts +++ b/app/src/utils/Utils.ts @@ -252,3 +252,30 @@ export const getFormattedIdentitySource = (identitySource: SYSTEM_IDENTITY_SOURC return null; } }; +declare global { + interface Array { + alphabetizeObjects(property: keyof T): T[]; + } +} + +/** + * For a given property, alphabetize an array of objects + * + * @param {string} property This function will alphabetize the array of objects on the given property + * @returns {any[]} Returns an alphabetized array of objects + */ +Array.prototype.alphabetizeObjects = function(property: keyof T): T[] { + return this.sort((a: T, b: T) => { + const nameA = a[property].toUpperCase(); + const nameB = b[property].toUpperCase(); + + if (nameA < nameB) { + return -1; + } else if (nameA > nameB) { + return 1; + } else { + return 0; + } + }); +} + From 0132e29e5b0f8a5e15e25d96792099b8032751db Mon Sep 17 00:00:00 2001 From: AlfredRosenthal Date: Thu, 27 Apr 2023 10:45:04 -0700 Subject: [PATCH 05/54] got first nations information displaying --- .../components/ProjectFundingItemForm.tsx | 8 +-- .../participants/ProjectParticipantsPage.tsx | 70 ++++++++----------- 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/app/src/features/projects/components/ProjectFundingItemForm.tsx b/app/src/features/projects/components/ProjectFundingItemForm.tsx index a40c97aef9..f726d40dfd 100644 --- a/app/src/features/projects/components/ProjectFundingItemForm.tsx +++ b/app/src/features/projects/components/ProjectFundingItemForm.tsx @@ -59,15 +59,13 @@ export const ProjectFundingFormArrayItemYupSchema = yup.object().shape({ }); /* - Ok so what should I be doing here? I think I'll just need to... ummm uhhh - ok so this should just take a single array of items plus the nonsense actions - the items will need the id, label and a type (duh) 1. modify the items to add type 2. Add the first nations names to the list 3. Add special consideration when selecting a first nations name 4. modify the save to account for the changes 5. Modify the fetch to account for any changes in the model + 6. create an enum or type to account for the text on the 'action' items */ export interface IProjectFundingItemFormProps1 { @@ -141,8 +139,8 @@ const ProjectFundingItemForm: React.FC = (props) = error={touched.agency_id && Boolean(errors.agency_id)} displayEmpty inputProps={{ 'aria-label': 'Agency Name', 'data-testid': 'agency-id' }}> - {props.sources.map((item) => ( - + {props.sources.alphabetizeObjects('label').map((item) => ( + {item.label} ))} diff --git a/app/src/features/projects/participants/ProjectParticipantsPage.tsx b/app/src/features/projects/participants/ProjectParticipantsPage.tsx index 6f47799ddd..5fbfae0a48 100644 --- a/app/src/features/projects/participants/ProjectParticipantsPage.tsx +++ b/app/src/features/projects/participants/ProjectParticipantsPage.tsx @@ -128,22 +128,6 @@ const ProjectParticipantsPage: React.FC = () => { } }; - function alphabetizeParticipants( - participantA: IGetProjectParticipantsResponseArrayItem, - participantB: IGetProjectParticipantsResponseArrayItem - ) { - // Message A is sorted before B - if (participantA.user_identifier < participantB.user_identifier) { - return -1; - } - // Message B is sorted before A - if (participantA.user_identifier > participantB.user_identifier) { - return 1; - } - // Items are already in order - return 0; - } - if (!codesContext.codesDataLoader.data || !projectParticipantsDataLoader.hasLoaded) { return ; } @@ -179,32 +163,34 @@ const ProjectParticipantsPage: React.FC = () => { {projectParticipantsDataLoader.data && - projectParticipantsDataLoader.data.participants.sort(alphabetizeParticipants).map((participant) => ( - - {participant.user_identifier} - {participant.user_identity_source_id} - - - - - - - - - handleDialogRemoveParticipantOpen(participant)}> - - - - - - ))} + projectParticipantsDataLoader.data.participants + .alphabetizeObjects('user_identifier') + .map((participant) => ( + + {participant.user_identifier} + {participant.user_identity_source_id} + + + + + + + + + handleDialogRemoveParticipantOpen(participant)}> + + + + + + ))} {!projectParticipantsDataLoader.data && ( From c114b08ea422c9dfb3439abb88bba5a56d91131d Mon Sep 17 00:00:00 2001 From: AlfredRosenthal Date: Thu, 27 Apr 2023 15:25:47 -0700 Subject: [PATCH 06/54] wip --- .../fields/AutocompleteFieldWithType.tsx | 86 +++++++++++++++++++ .../components/ProjectFundingForm.tsx | 11 +-- .../components/ProjectFundingItemForm.tsx | 31 +++++-- 3 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 app/src/components/fields/AutocompleteFieldWithType.tsx diff --git a/app/src/components/fields/AutocompleteFieldWithType.tsx b/app/src/components/fields/AutocompleteFieldWithType.tsx new file mode 100644 index 0000000000..1da9e66ca6 --- /dev/null +++ b/app/src/components/fields/AutocompleteFieldWithType.tsx @@ -0,0 +1,86 @@ +import TextField from '@material-ui/core/TextField'; +import Autocomplete, { createFilterOptions } from '@material-ui/lab/Autocomplete'; +import { FundingSourceType } from 'features/projects/components/ProjectFundingItemForm'; +import { useFormikContext } from 'formik'; +import get from 'lodash-es/get'; +import React, { ChangeEvent } from 'react'; + +export interface IAutocompleteFieldOption { + value: T; + label: string; + type: FundingSourceType; +} + +export interface IAutocompleteField { + id: string; + label: string; + name: string; + options: IAutocompleteFieldOption[]; + required?: boolean; + filterLimit?: number; + onChange?: (event: ChangeEvent>, option: IAutocompleteFieldOption | null) => void; +} + +const AutocompleteFieldWithType: React.FC> = ( + props: IAutocompleteField +) => { + const { touched, errors, setFieldValue, values } = useFormikContext>(); + + const getExistingValue = (existingValue: T): IAutocompleteFieldOption => { + const result = props.options.find((option) => existingValue === option.value); + + if (!result) { + return (null as unknown) as IAutocompleteFieldOption; + } + + return result; + }; + + const handleGetOptionSelected = ( + option: IAutocompleteFieldOption, + value: IAutocompleteFieldOption + ): boolean => { + if (!option?.value || !value?.value) { + return false; + } + + return option.value === value.value; + }; + + return ( + option.label} + getOptionSelected={handleGetOptionSelected} + filterOptions={createFilterOptions({ limit: props.filterLimit })} + onChange={(event, option) => { + if (props.onChange) { + props.onChange(event, option); + return; + } + + setFieldValue(props.name, option); + }} + renderInput={(params) => ( + + )} + /> + ); +}; + +export default AutocompleteFieldWithType; diff --git a/app/src/features/projects/components/ProjectFundingForm.tsx b/app/src/features/projects/components/ProjectFundingForm.tsx index cb49b36246..c390f4c2e7 100644 --- a/app/src/features/projects/components/ProjectFundingForm.tsx +++ b/app/src/features/projects/components/ProjectFundingForm.tsx @@ -22,7 +22,7 @@ import React, { useState } from 'react'; import { getFormattedAmount, getFormattedDateRangeString } from 'utils/Utils'; import yup from 'utils/YupSchema'; import ProjectFundingItemForm, { - IMultiAutocompleteFieldOptionWithType, + IFundingSourceAutocompleteField, IProjectFundingFormArrayItem, ProjectFundingFormArrayItemInitialValues, ProjectFundingFormArrayItemYupSchema @@ -47,9 +47,9 @@ export interface IInvestmentActionCategoryOption extends IMultiAutocompleteField } export interface IProjectFundingFormProps { - funding_sources: IMultiAutocompleteFieldOptionWithType[]; + funding_sources: IFundingSourceAutocompleteField[]; investment_action_category: IInvestmentActionCategoryOption[]; - first_nations: IMultiAutocompleteFieldOptionWithType[]; + first_nations: IFundingSourceAutocompleteField[]; } const useStyles = makeStyles((theme: Theme) => ({ @@ -136,6 +136,7 @@ const ProjectFundingForm: React.FC = (props) => { }} onCancel={() => setIsModalOpen(false)} onSave={(projectFundingItemValues) => { + console.log('projectFundingItemValues', projectFundingItemValues); if (currentProjectFundingFormArrayItem.index < values.funding.fundingSources.length) { // Update an existing item arrayHelpers.replace(currentProjectFundingFormArrayItem.index, projectFundingItemValues); @@ -154,7 +155,7 @@ const ProjectFundingForm: React.FC = (props) => { (fundingSource.agency_id === 1 && 'Investment Action') || (fundingSource.agency_id === 2 && 'Investment Category') || null; - + console.log(`Label: ${investment_action_category_label}`); const investment_action_category_value = props.investment_action_category.filter( (item) => item.value === fundingSource.investment_action_category )?.[0]?.label; @@ -164,7 +165,7 @@ const ProjectFundingForm: React.FC = (props) => { - {getCodeValueNameByID(props.funding_sources, fundingSource.agency_id)} + {getCodeValueNameByID(props.funding_sources, fundingSource?.agency_id)} {investment_action_category_label && ( ({investment_action_category_value}) )} diff --git a/app/src/features/projects/components/ProjectFundingItemForm.tsx b/app/src/features/projects/components/ProjectFundingItemForm.tsx index f726d40dfd..2513a6b17d 100644 --- a/app/src/features/projects/components/ProjectFundingItemForm.tsx +++ b/app/src/features/projects/components/ProjectFundingItemForm.tsx @@ -7,6 +7,7 @@ import InputLabel from '@material-ui/core/InputLabel'; import MenuItem from '@material-ui/core/MenuItem'; import Select from '@material-ui/core/Select'; import Typography from '@material-ui/core/Typography'; +import AutocompleteFieldWithType from 'components/fields/AutocompleteFieldWithType'; import CustomTextField from 'components/fields/CustomTextField'; import DollarAmountField from 'components/fields/DollarAmountField'; import { IMultiAutocompleteFieldOption } from 'components/fields/MultiAutocompleteFieldVariableSize'; @@ -18,14 +19,15 @@ import { IInvestmentActionCategoryOption } from './ProjectFundingForm'; export interface IProjectFundingFormArrayItem { id: number; - agency_id: number; + agency_id?: number; investment_action_category: number; investment_action_category_name: string; agency_project_id: string; - funding_amount: number; + funding_amount?: number; start_date: string; end_date: string; revision_count: number; + first_nations_id?: number; } export const ProjectFundingFormArrayItemInitialValues: IProjectFundingFormArrayItem = { @@ -66,6 +68,10 @@ export const ProjectFundingFormArrayItemYupSchema = yup.object().shape({ 4. modify the save to account for the changes 5. Modify the fetch to account for any changes in the model 6. create an enum or type to account for the text on the 'action' items + + + Q's + 1. Does the agency name still make sense? */ export interface IProjectFundingItemFormProps1 { @@ -77,11 +83,13 @@ export enum FundingSourceType { FUNDING_SOURCE, FIRST_NATIONS } -export interface IMultiAutocompleteFieldOptionWithType extends IMultiAutocompleteFieldOption { +export interface IFundingSourceAutocompleteField { + value: number; + label: string; type: FundingSourceType; } export interface IProjectFundingItemFormProps { - sources: IMultiAutocompleteFieldOptionWithType[]; + sources: IFundingSourceAutocompleteField[]; investment_action_category: IInvestmentActionCategoryOption[]; } @@ -97,6 +105,7 @@ const ProjectFundingItemForm: React.FC = (props) = const formikProps = useFormikContext(); console.log(props.sources); const { values, touched, errors, handleChange, handleSubmit, setFieldValue } = formikProps; + console.log('values', values); // Only show investment_action_category if certain agency_id values are selected // Toggle investment_action_category label and dropdown values based on chosen agency_id @@ -112,7 +121,15 @@ const ProjectFundingItemForm: React.FC = (props) = - Agency Name + + + + {/* Agency Name */} { - // I think this will all need to change here... - console.log(values); - console.log(event); - handleChange(event); - // investment_action_category is dependent on agency_id, so reset it if agency_id changes - setFieldValue( - 'investment_action_category', - ProjectFundingFormArrayItemInitialValues.investment_action_category - ); - - // If an agency_id with a `Not Applicable` investment_action_category is chosen, auto select - // it for the user. - if (event.target.value !== 1 && event.target.value !== 2) { - console.log('LOOK AT THIS THING FIND ALL THIS STUFF MAYBE...'); + onChange={(event, options) => { + // investment_action_category is dependent on agency_id, so reset it if agency_id changes setFieldValue( 'investment_action_category', - props.investment_action_category.find((item) => item.fs_id === event.target.value)?.value || 0 + ProjectFundingFormArrayItemInitialValues.investment_action_category ); - } - }} - error={touched.agency_id && Boolean(errors.agency_id)} - displayEmpty - inputProps={{ 'aria-label': 'Agency Name', 'data-testid': 'agency-id' }}> - {props.sources.alphabetizeObjects('label').map((item) => ( - - {item.label} - - ))} - + console.log( + `Action category: ${ProjectFundingFormArrayItemInitialValues.investment_action_category}` + ); + if (options?.type === FundingSourceType.FIRST_NATIONS) { + setFieldValue('first_nations_id', options?.value); + } else { + setFieldValue('agency_id', options?.value); + // If an agency_id with a `Not Applicable` investment_action_category is chosen, auto select + // it for the user. + //TODO: take a look at this logic, seems backwards + if (event.target.value !== 1 && event.target.value !== 2) { + setFieldValue( + 'investment_action_category', + props.investment_action_category.find((item) => item.fs_id === event.target.value)?.value || 0 + ); + } + } + }} + /> + {errors.agency_id} From 002f41a6b14b2842acd5c443b70bb8d5d6b827db Mon Sep 17 00:00:00 2001 From: AlfredRosenthal Date: Fri, 28 Apr 2023 09:56:34 -0700 Subject: [PATCH 08/54] added more console logs --- app/src/components/dialog/EditDialog.tsx | 7 ++++++- .../projects/components/ProjectFundingItemForm.tsx | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/components/dialog/EditDialog.tsx b/app/src/components/dialog/EditDialog.tsx index b3bd427aca..5e4042b39f 100644 --- a/app/src/components/dialog/EditDialog.tsx +++ b/app/src/components/dialog/EditDialog.tsx @@ -103,7 +103,12 @@ export const EditDialog = (props: PropsWithChildren{props.component.element} + + + + + +

@@ -116,10 +161,10 @@ exports[`ProjectFundingItemForm auto selection of investment action category wor />