Skip to content

Commit

Permalink
Add fetching of required signoffs, finding matching signoffs for the …
Browse files Browse the repository at this point in the history
…rule and setting signoff summary
  • Loading branch information
michellemounde committed Oct 20, 2023
1 parent f63d382 commit da4305a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ui/src/views/Rules/Rule/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,39 @@ function Rule({ isNewRule, user, ...props }) {
}
}, [ruleId, scId]);

useEffect(() => {
fetchRequiredSignoffs(OBJECT_NAMES.PRODUCT_REQUIRED_SIGNOFF).then(
rsResponse => {
const requiredSignoffs = rsResponse.data.data.required_signoffs;

if (rule.product) {
const matchingRs = requiredSignoffs.filter(rs =>
ruleMatchesRequiredSignoff(rule, rs)
);

setRuleRequiredSignoffs(curr => curr.concat(matchingRs));

if (!requiredSignoffs.length || !matchingRs.length) {
setSignoffSummary(' None');
} else {
const rsSummary = matchingRs.reduce((summary, rs, idx) => {
const memberStr = rs.signoffs_required > 1 ? 'members' : 'member';
const rsStr = `${rs.signoffs_required} ${memberStr} of ${rs.role}`;

if (idx !== matchingRs.length - 1) {
return `${summary}${rsStr}, `;
}

return summary + rsStr;
}, ' ');

setSignoffSummary(rsSummary);
}
}
}
);
}, [rule.product, rule.channel]);

const today = new Date();

// This will make sure the helperText
Expand Down

0 comments on commit da4305a

Please sign in to comment.