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

wired up agreements #850

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion frontend/src/api/getAgreements.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ export const getAllAgreements = async () => {

export const getAgreementsByResearchProjectFilter = async (id) => {
const api_version = ApplicationContext.get().helpers().backEndConfig.apiVersion;
const endpoint = `/api/${api_version}/agreements/?project_id=${id}`;
const endpoint = `/api/${api_version}/agreements/?research_project_id=${id}`;
const responseData = await ApplicationContext.get().helpers().callBackend(endpoint, "get");
return responseData;
};

export const getAllAgreementTypes = async () => {
const api_version = ApplicationContext.get().helpers().backEndConfig.apiVersion;
const endpoint = `/api/${api_version}/agreement-types/`;
const responseData = await ApplicationContext.get().helpers.callBackend(endpoint, "get");
return responseData;
};
96 changes: 13 additions & 83 deletions frontend/src/pages/budgetLines/AgreementSelect.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { useDispatch, useSelector } from "react-redux";
import { setSelectedAgreement, setBudgetLineAdded, setSelectedProcurementShop } from "./createBudgetLineSlice";
import { AGREEMENTS } from "./data";

export const AgreementSelect = () => {
const dispatch = useDispatch();
const agreements = useSelector(() => AGREEMENTS);
const agreements = useSelector((state) => state.createBudgetLine.agreements);
const selectedAgreement = useSelector((state) => state.createBudgetLine.selected_agreement);
const onChangeAgreementSelection = (agreementId = 0) => {
const selectedAgreement = agreements.find((agreement) => agreement.id === agreementId);

if (agreementId === 0) {
return;
}
Expand Down Expand Up @@ -58,90 +56,22 @@ export const AgreementSelect = () => {
<label className="usa-label" htmlFor="agreement" id="agreement-label">
Agreements
</label>
<div className="usa-combo-box" data-enhanced="true">
<div>
<select
className="usa-select usa-sr-only usa-combo-box__select"
name="agreement"
aria-hidden="true"
tabIndex="-1"
defaultValue={selectedAgreement?.name}
className="usa-select margin-top-0 width-full"
name="options"
id="options"
onChange={(e) => onChangeAgreementSelection(Number(e.target.value) || 0)}
value={selectedAgreement?.id}
required
>
{agreements.map((agreement) => {
return (
<option key={agreement?.id} value={agreement?.id}>
{agreement?.name}
</option>
);
})}
<option value={0}>- Select -</option>
{agreements.map((shop) => (
<option key={shop?.id} value={shop?.id}>
{shop?.name}
</option>
))}
</select>
<input
id="agreement"
aria-owns="agreement--list"
aria-controls="agreement--list"
aria-autocomplete="list"
aria-describedby="agreement--assistiveHint"
aria-expanded="false"
autoCapitalize="off"
autoComplete="off"
className="usa-combo-box__input"
type="text"
role="combobox"
aria-activedescendant=""
defaultValue={selectedAgreement?.name}
/>
<span className="usa-combo-box__clear-input__wrapper" tabIndex="-1">
<button
type="button"
className="usa-combo-box__clear-input"
aria-label="Clear the select contents"
onClick={() => dispatch(setSelectedAgreement({}))}
>
&nbsp;
</button>
</span>
<span className="usa-combo-box__input-button-separator">&nbsp;</span>
<span className="usa-combo-box__toggle-list__wrapper" tabIndex="-1">
<button
type="button"
tabIndex="-1"
className="usa-combo-box__toggle-list"
aria-label="Toggle the dropdown list"
>
&nbsp;
</button>
</span>
<ul
tabIndex="-1"
id="agreement--list"
className="usa-combo-box__list"
role="listbox"
aria-labelledby="agreement-label"
hidden
>
{agreements?.map((agreement, index) => {
return (
<li
key={agreement?.id}
aria-setsize={agreements?.length}
aria-posinset={index + 1}
aria-selected="false"
id={`dynamic-select--list--option-${index}`}
className="usa-combo-box__list-option"
tabIndex={index === 0 ? "0" : "-1"}
role="option"
data-value={agreement?.name}
>
{agreement?.name}
</li>
);
})}
</ul>
<div className="usa-combo-box__status usa-sr-only" role="status"></div>
<span id="agreement--assistiveHint" className="usa-sr-only">
When autocomplete results are available use up and down arrows to review and enter to select.
Touch device users, explore by touch or with swipe gestures.
</span>
</div>
</div>
{/* NOTE: Right side */}
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/pages/budgetLines/CreateBudgetLine.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ const StepThree = ({ goBack, goToNext }) => (

export const CreateBudgetLine = () => {
const dispatch = useDispatch();
const selectedProject = useSelector((state) => state.createBudgetLine.selectedProject);
const selectedProject = useSelector((state) => state.createBudgetLine.selected_project);

// Get initial list of Agreements (dependent on Research Project Selection)
useEffect(() => {
Expand All @@ -391,6 +391,16 @@ export const CreateBudgetLine = () => {
getProcurementShopsAndSetState().catch(console.error);
}, [dispatch]);

useEffect(() => {
const getAgreementsAndSetState = async () => {
if (selectedProject?.id > 0) {
const results = await getAgreementsByResearchProjectFilter(selectedProject?.id);
dispatch(setAgreements(results));
}
};
getAgreementsAndSetState().catch(console.error);
}, [dispatch, selectedProject]);

return (
<App>
<CreateBudgetLineFlow
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/pages/budgetLines/ProjectSelect.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useDispatch, useSelector } from "react-redux";
import { setSelectedProject } from "./createBudgetLineSlice";
import { setAgreements, setSelectedAgreement, setSelectedProject } from "./createBudgetLineSlice";

export const ProjectSelect = () => {
const dispatch = useDispatch();
const researchProjects = useSelector((state) => state.createBudgetLine.research_projects);
const selectedResearchProject = useSelector((state) => state.createBudgetLine.selected_project);
const onChangeResearchProjectSelection = (projectId = 0) => {
if (projectId === 0) {
clearAgreementState();
return;
}
dispatch(
Expand All @@ -18,6 +19,16 @@ export const ProjectSelect = () => {
);
};

const onInputCloseButtonClick = (event) => {
dispatch(setSelectedProject({}));
clearAgreementState();
};

const clearAgreementState = () => {
dispatch(setAgreements([]));
dispatch(setSelectedAgreement(-1));
};

const areThereTeamLeaders = selectedResearchProject?.teamLeaders?.length > 0;

const ProjectSummaryCard = () => {
Expand Down Expand Up @@ -83,7 +94,7 @@ export const ProjectSelect = () => {
type="button"
className="usa-combo-box__clear-input"
aria-label="Clear the select contents"
onClick={() => dispatch(setSelectedProject({}))}
onClick={(e) => onInputCloseButtonClick(e)}
>
&nbsp;
</button>
Expand Down