Skip to content

Commit

Permalink
Start supporting multi-valued "items" field (#156)
Browse files Browse the repository at this point in the history
## Description

In preparation for rolling out more granular `item` values for things
like heat pumps and weatherization, incentives will need to support
multiple values items. This change starts reading from a new
array-valued `items` field if it's available.

Next step will be to deploy a backend change that adds the
multi-valued field to responses. Then, remove `item` from the
frontend. Then, remove `item` from the backend.

https://app.asana.com/0/1206661332626418/1206911030685282

## Test Plan

Running calculations against a local backend that has the `items`
change applied succeeds; Cypress tests pass in that state.
  • Loading branch information
oyamauchi authored Apr 29, 2024
1 parent ddd9f86 commit f17b2cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/api/calculator-types-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export type ItemType =

export interface Item {
type: ItemType;
name: string;
}

export interface Incentive {
Expand All @@ -56,7 +55,9 @@ export interface Incentive {
program: string;
program_url: string;
more_info_url?: string;
// TODO when "items" backend change is deployed, remove "item"
item: Item;
items?: ItemType[];
amount: Amount;
start_date?: string;
end_date?: string;
Expand Down
9 changes: 6 additions & 3 deletions src/state-incentive-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const formatUnit = (unit: AmountUnit, msg: MsgFn) =>
: unit;

const formatTitle = (incentive: Incentive, msg: MsgFn) => {
const item = itemName(incentive.item.type, msg);
const itemValue = incentive.items ? incentive.items[0] : incentive.item.type;
const item = itemName(itemValue, msg);
const amount = incentive.amount;
if (amount.type === 'dollar_amount') {
return amount.maximum
Expand Down Expand Up @@ -421,9 +422,11 @@ export const StateIncentives: FC<Props> = ({
const allEligible = response.incentives.filter(i => i.eligible);

const incentivesByProject = Object.fromEntries(
Object.entries(PROJECTS).map(([project, info]) => [
Object.entries(PROJECTS).map(([project, projectInfo]) => [
project,
allEligible.filter(i => info.items.includes(i.item.type)),
allEligible.filter(i =>
projectInfo.items.includes(i.items ? i.items[0] : i.item.type),
),
]),
) as Record<Project, Incentive[]>;

Expand Down

0 comments on commit f17b2cf

Please sign in to comment.