Last active
February 27, 2018 16:49
-
-
Save innerdaze/b83aed476d09b839ff094090eaabd0cb to your computer and use it in GitHub Desktop.
Different Component Structure with Ramda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { map, apply, zip, times } from 'ramda' | |
import { v4 } from 'uuid' | |
import Box from 'grommet/components/Box' | |
const propArray = [ | |
'Supplier Code', | |
'PackSize', | |
'In Stock', | |
'On Order', | |
'Avg Weekly Sales' | |
] | |
const renderItemDetailPair = (key, prop, value) => ( | |
<Box key={key} margin={{ right: 'medium' }} flex='grow'> | |
<span style={{ color: '#6b6b6b', fontWeight: 600 }}>{prop}</span> {value} | |
</Box> | |
) | |
const applyDataToRender = apply(renderItemDetailPair) | |
const keyAndPropsArray = zip(times(v4, propArray.length), propArray) | |
const mergeValuesIntoProps = (values, props) => { | |
values.forEach((item, index) => props[index].push(item)) | |
return props | |
} | |
const OrderMeta = ({ | |
order: { product: { SupplierID, PackSize, CurrStock, OnOrder, AvgSales } } | |
}) => | |
map( | |
applyDataToRender, | |
mergeValuesIntoProps( | |
[SupplierID, PackSize, CurrStock, OnOrder, AvgSales], | |
keyAndPropsArray | |
) | |
) | |
export default OrderMeta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment