Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. import React, { PropTypes } from 'react';
  2. import CSSModules from 'react-css-modules';
  3. import { flatMap } from 'lodash';
  4. import { DataGrid, Row, Cell } from '../data-grid';
  5. import { Age, Draw, OrdinalNumber, Price, Runner, Selection, Spotlight, JockeyShirt } from '../cell';
  6. import styles from './Racecard.scss';
  7.  
  8. const Racecard = ({
  9. selections,
  10. onSelectionToggle,
  11. onGuideDiscard,
  12. onExpand,
  13. onGuideClose
  14. }) => (
  15. <DataGrid styleName="racecard">
  16. <tbody>
  17. <tr styleName="racecard-header">
  18. <td styleName="racecard__heading" style={{ width: '30px' }}>No.</td>
  19. <td styleName="racecard__heading" style={{ width: '25px' }}>Draw</td>
  20. <td styleName="racecard__heading" style={{ width: '45px' }}/>
  21. <td styleName="racecard__heading">Selection</td>
  22. <td styleName="racecard__heading racecard__heading--centered" style={{ width: '80px' }}>
  23. <div>Age,</div>
  24. <div>weight</div>
  25. </td>
  26. <td styleName="racecard__heading--centered" style={{ width: '112px' }}>RP</td>
  27. <td styleName="racecard__heading racecard__heading--centered" style={{ width: '55px' }}>
  28. <div>Guide</div>
  29. <div>price</div>
  30. </td>
  31. <td styleName="racecard__heading racecard__heading--centered" style={{ width: '58px' }}/>
  32. </tr>
  33. {flatMap(selections, ({
  34. id,
  35. number,
  36. draw,
  37. shirtNumber,
  38. silk,
  39. daysSinceRun,
  40. name,
  41. jockey,
  42. trainer,
  43. age,
  44. weight,
  45. rp,
  46. odds,
  47. overview,
  48. selected,
  49. guided,
  50. expanded,
  51. scratched
  52. }) => [(
  53. <Row data-test="selection" key={id}>
  54. <Cell styleName="racecard__cell" align="top" width="30">
  55. <OrdinalNumber number={number} draw={draw} scratched={scratched} />
  56. </Cell>
  57. <Cell styleName="racecard__cell racecard__cell--tablet" align="top" width="25">
  58. <Draw draw={draw} scratched={scratched} />
  59. </Cell>
  60. <Cell styleName="racecard__cell" align="top" width="55">
  61. <JockeyShirt silk={silk} number={shirtNumber} scratched={scratched} />
  62. </Cell>
  63. <Cell>
  64. <Runner
  65. id={id}
  66. expanded={expanded}
  67. daysSinceRun={daysSinceRun}
  68. name={name}
  69. description={overview}
  70. jockey={jockey}
  71. trainer={trainer}
  72. onExpand={onExpand}
  73. scratched={scratched}
  74. />
  75. </Cell>
  76. <Cell styleName="racecard__cell--tablet" width="80">
  77. <Age age={age} weight={weight} scratched={scratched} />
  78. </Cell>
  79. <Cell styleName="racecard__cell--tablet" width="112">
  80. <Spotlight
  81. id={id}
  82. rating={rp}
  83. description={overview}
  84. onExpand={onExpand}
  85. scratched={scratched}
  86. />
  87. </Cell>
  88. <Cell styleName="racecard__odds-column" width="55">
  89. <Price odds={scratched ? 'Non runner' : odds} scratched={scratched} />
  90. </Cell>
  91. <Cell width="58">
  92. <Selection
  93. id={id}
  94. guided={guided}
  95. selected={selected}
  96. onGuideClose={onGuideClose}
  97. onSelectionToggle={onSelectionToggle}
  98. onGuideDiscard={onGuideDiscard}
  99. disabled={scratched}
  100. />
  101. </Cell>
  102. </Row>
  103. ), expanded && (
  104. <Row key={`${id}_expanded`}>
  105. <Cell styleName="racecard__overview" colSpan="8">{overview}</Cell>
  106. </Row>
  107. )])}
  108. </tbody>
  109. </DataGrid>
  110. );
  111.  
  112. Racecard.propTypes = {
  113. selections: PropTypes.arrayOf(PropTypes.shape({
  114. id: PropTypes.number,
  115. number: PropTypes.number,
  116. draw: PropTypes.number,
  117. shirtNumber: PropTypes.string,
  118. name: PropTypes.string,
  119. jockey: PropTypes.string,
  120. trainer: PropTypes.string,
  121. age: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  122. weight: PropTypes.string,
  123. rp: PropTypes.string,
  124. previousOdds: PropTypes.string,
  125. odds: PropTypes.string,
  126. silk: PropTypes.string.isRequired,
  127. daysSinceRun: PropTypes.number,
  128. overview: PropTypes.string,
  129. selected: PropTypes.bool,
  130. guided: PropTypes.bool,
  131. expanded: PropTypes.bool,
  132. scratched: PropTypes.bool
  133. })),
  134. onSelectionToggle: PropTypes.func,
  135. onGuideDiscard: PropTypes.func,
  136. onExpand: PropTypes.func,
  137. onGuideClose: PropTypes.func
  138. };
  139.  
  140. export default CSSModules(
  141. Racecard,
  142. styles,
  143. { allowMultiple: true }
  144. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement