Skip to content

Commit

Permalink
fix overwritten values count
Browse files Browse the repository at this point in the history
  • Loading branch information
terryttsai committed Sep 20, 2022
1 parent 8cf93db commit 88774c3
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions publisher/src/components/ReviewMetrics/ReviewMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const ReviewMetrics: React.FC = observer(() => {
datapoints: metric.datapoints.filter((dp) => dp.value !== null),
}))
.filter((metric) => metric.datapoints.length > 0);
console.log("metrics", location.state);
console.log("filteredMetrics", filteredMetrics);

const renderSection = (metric: UploadedMetric, index: number) => {
const startDates = Array.from(
Expand All @@ -106,9 +108,6 @@ const ReviewMetrics: React.FC = observer(() => {
}, {} as { [key: string]: number });

metric.datapoints.forEach((dp) => {
if (dp.old_value !== null) {
overwrittenValuesCount += 1;
}
if (dp.disaggregation_display_name && dp.dimension_display_name) {
if (!disaggregationRowData[dp.disaggregation_display_name]) {
disaggregationRowData[dp.disaggregation_display_name] = {};
Expand All @@ -122,11 +121,23 @@ const ReviewMetrics: React.FC = observer(() => {
dp.dimension_display_name
] = [];
}
disaggregationRowData[dp.disaggregation_display_name][
dp.dimension_display_name
][startDatesIndexLookup[dp.start_date]] = dp;
} else {
if (
!disaggregationRowData[dp.disaggregation_display_name][
dp.dimension_display_name
][startDatesIndexLookup[dp.start_date]]
) {
disaggregationRowData[dp.disaggregation_display_name][
dp.dimension_display_name
][startDatesIndexLookup[dp.start_date]] = dp;
if (dp.old_value !== null) {
overwrittenValuesCount += 1;
}
}
} else if (!aggregateRowData[startDatesIndexLookup[dp.start_date]]) {
aggregateRowData[startDatesIndexLookup[dp.start_date]] = dp;
if (dp.old_value !== null) {
overwrittenValuesCount += 1;
}
}
});

Expand All @@ -137,7 +148,7 @@ const ReviewMetrics: React.FC = observer(() => {
<SectionTitle>{metric.display_name}</SectionTitle>
{overwrittenValuesCount > 0 && (
<SectionTitleOverwrites>
* {overwrittenValuesCount} Overwrite
* {overwrittenValuesCount} Overwritten Value
{overwrittenValuesCount !== 1 ? "s" : ""}
</SectionTitleOverwrites>
)}
Expand Down Expand Up @@ -274,10 +285,7 @@ const ReviewMetrics: React.FC = observer(() => {
</a>
</Subheading>
{filteredMetrics.map((metric, idx) => {
if (metric.datapoints.length > 0) {
return renderSection(metric, idx);
}
return null;
return renderSection(metric, idx);
})}
</MainPanel>
</Container>
Expand Down

0 comments on commit 88774c3

Please sign in to comment.