Skip to content

Commit

Permalink
feat(product): update the retrieval of current/past benchmarks for a …
Browse files Browse the repository at this point in the history
…product
  • Loading branch information
dleard committed May 13, 2020
1 parent 38c52b2 commit b24b122
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
1 change: 0 additions & 1 deletion app/components/SearchTableLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const SearchTableLayoutComponent: React.FunctionComponent<Props> = (
))}
</tr>
</thead>
<th />
{body}
</Table>
</>
Expand Down
26 changes: 3 additions & 23 deletions app/containers/Products/ProductRowItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,9 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
updateProductCount,
productCount
}) => {
const {reportingYear: nextReportingYear} = query.nextReportingYear;
const currentBenchmark = product.benchmarksByProductId?.edges[0]?.node;

const currentBenchmark = useMemo(() => {
return product.benchmarksByProductId.edges.find(({node: benchmark}) => {
return (
!benchmark.deletedAt &&
benchmark.startReportingYear <= nextReportingYear &&
benchmark.endReportingYear >= nextReportingYear
);
})?.node;
}, [product.benchmarksByProductId.edges, nextReportingYear]);

const pastBenchmarks = useMemo(
() =>
product.benchmarksByProductId.edges
.filter(
({node}) =>
!node.deletedAt && node.endReportingYear < nextReportingYear
)
.map(({node}) => node),
[nextReportingYear, product.benchmarksByProductId.edges]
);
const pastBenchmarks = product.benchmarksByProductId?.edges.slice(1);

// Schema for ProductRowItemContainer
const benchmarkSchema = useMemo<JSONSchema6>(() => {
Expand Down Expand Up @@ -377,7 +358,6 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
</Modal>
);

console.log(product);
return (
<>
<tr>
Expand Down Expand Up @@ -417,7 +397,7 @@ export default createFragmentContainer(ProductRowItemComponent, {
addEmissionsFromEios
requiresProductAmount
updatedAt
benchmarksByProductId {
benchmarksByProductId(orderBy: CREATED_AT_DESC) {
edges {
node {
id
Expand Down

0 comments on commit b24b122

Please sign in to comment.