I have a field, RoadmapType, which is populated with a hardcoded string based on the combination of values from four other fields, InvestmentCategory, FundingClass, InvestmentClass & Lifecycle. The value determining RoadmapType can vary, for example, in one instance, to get the RoadmapType "Incremental", the value of InvestmentCategory can be either "Enterprise" or "IT Roadmap", and the value of InvestmentClass can be "Transform", "Scale", "NPI" or "Run".
Right now, I am doing this the long way, where I am using multiple if blocks for each potential RoadmapType. I want a shorter, more reliable method to get my desired out come.
This table shows 3 example combinations and the resulting RoadmapType. Please note that only one value from each column can be used at a time.
| Investment Category | Funding Class | Investment Class | Lifecycle | Roadmap Type |
|---|---|---|---|---|
| Enterprise Roadmap, IT Roadmap | Incremental | Transform, Scale, NPI, Run | Any value | Incremental |
| Enterprise Roadmap | Roadmap | Transform, NPI | All except DD | Roadmap - BAT |
| Enterprise Roadmap | Chargeback | Transform, Scale, NPI, Run | IPT, SDM | Chargeback - DTS |
These are the if blocks I am using to get a RoadmapTypeof "Compliance".
const onTextChange = (e) => {
var id = e.target.id ? e?.target.id : e?.target.name;
var value = e.target.value;
function setRoadmapType(fieldId, fieldVal, roadmapTypeVal) {
setDetails({ ...details, [fieldId]: fieldVal, RoadmapType: roadmapTypeVal });
}
if (
id === "InvestmentClass" &&
value === "Compliance" &&
details?.FundingClass === "Roadmap" &&
details?.InvestmentCategory === "Enterprise Roadmap"
) {
setRoadmapType(id, value, "Roadmap - Compliance");
} else if (
id === "FundingClass" &&
value === "Roadmap" &&
details?.InvestmentClass === "Compliance" &&
details?.InvestmentCategory === "Enterprise Roadmap"
) {
setRoadmapType(id, value, "Roadmap - Compliance");
} else if (
// ! NOT WORKING when investment category is input as the deciding value of RoadmapType
id === "InvestmentCategory" &&
value === "Enterprise Roadmap" &&
details?.InvestmentClass === "Compliance" &&
details?.FundingClass === "Roadmap"
) else {
setDetails({ ...details, [id]: value });
}
}