Guest User

Untitled

a guest
Jul 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. function renderCustomTab(chart, tabInfo) {
  2. return ({ key, label, active, handleClick }) => {
  3. const isActive = active;
  4. const isHover = active;
  5. const cssActive = isActive ? 'active' : '';
  6. const btnStyle = _.extend(
  7. {},
  8. chart.props.styles.chartTypeTabsLiButton,
  9. isActive
  10. ? chart.props.styles.chartTypeTabsBtnActive
  11. : { borderTop: 'none' },
  12. isHover
  13. ? chart.props.styles.chartTypeTabsLiBtnHover
  14. : { backgroundColor: 'white' }
  15. );
  16. return (
  17. <div>
  18. <ul
  19. className="chart-type-tabs"
  20. style={chart.props.styles.chartTypeTabs}
  21. >
  22. <li style={chart.props.styles.chartTypeTabsLi}>
  23. <button
  24. style={btnStyle}
  25. onClick={e => {
  26. // wrap HIG handler and set state before calling it
  27. chart.setState({ activeTab: label });
  28. handleClick(e); // HIG handler
  29. }}
  30. >
  31. <span
  32. className="tab-name"
  33. style={chart.props.styles.chartTypeTabsLabels}
  34. >
  35. {tabInfo.name}
  36. </span>
  37. <span
  38. className="percentage"
  39. style={chart.props.styles.chartTypeTabsPercentage}
  40. >
  41. {tabInfo.formattedLabel()}
  42. </span>
  43. <span
  44. className="usage"
  45. style={chart.props.styles.chartTypeTabsUsage}
  46. >
  47. {tabInfo.label}
  48. </span>
  49. </button>
  50. </li>
  51. </ul>
  52. </div>
  53. );
  54. };
  55. }
  56.  
  57. function postUrlRequest(contractNumber) {
  58. return function lambda() {
  59. return postUrl({
  60. url: '/usage/' + contractNumber + '/query',
  61. query: {
  62. fields: ['contractYear', 'usageCategory'],
  63. metrics: ['uniqueProducts', 'uniqueUsers', 'tokensConsumed'],
  64. where: "usageCategory in ('DESKTOP_PRODUCT')",
  65. },
  66. }).then(function(response) {
  67. const usage = response.result.rows[0][3];
  68. // Total unique Users
  69. return usage;
  70. });
  71. };
  72. }
  73.  
  74. // Chart Renderer
  75. export function getMainRender(category) {
  76. return function(data) {
  77. const contract = data.contract;
  78. const styles = this.props.styles;
  79. const usage = data.data;
  80. const selectedYear = this.state.contractYear || getCurrentYear(contract);
  81.  
  82. const DEFAULT_TAB = 'Products used';
  83. const currentUsage = getUsage(
  84. usage,
  85. selectedYear,
  86. this.state.activeTab || DEFAULT_TAB
  87. );
  88.  
  89.  
  90.  
  91. formattedTokensConsumedMax = formatLargeNumber(tokensConsumedMax);
  92. usersMax = separateNumber(usersMax.toString());
  93.  
  94. let fetchData = postUrlRequest(contract.contractNumber);
  95.  
  96. const tabInfos = [
  97. {
  98. name: 'Products used',
  99. formattedLabel: fetchData,
  100. label: ' ',
  101. emptyMessage: 'No products used',
  102. },
  103. {
  104. name: 'Tokens used',
  105. formattedLabel: fetchData,
  106. label: separateNumber(tokensConsumedMax),
  107. emptyMessage: 'No tokens used',
  108. },
  109. {
  110. name: 'Unique users',
  111. formattedLabel: fetchData,
  112. label: ' ',
  113. emptyMessage: 'No unique users',
  114. },
  115. ];
  116.  
  117.  
  118. return (
  119. <section style={styles.chartTypeTabs}>
  120. <div style={styles.divStyles}>
  121. <style type="text/css">
  122. {`
  123. #container .hig__s {
  124. justify-content: left !important;
  125. }
  126. #container .hig__tabs__tab-label {
  127. color: #1b97d5;
  128. }
  129.  
  130. .hig__tabs {
  131. margin:0;
  132. padding:0;
  133. }
  134.  
  135. #container .hig__dropdown, #container .hig__text-field {
  136. min-width: 150px;
  137. max-width: 250px;
  138. margin: 0;
  139. padding: 0;
  140. }
  141. .chart-type-tabs li button:hover {
  142. background-color: #eaeaea !important;
  143. }
  144. `}
  145. </style>
  146. {
  147. <div>
  148. <Tabs align="center">
  149. {tabInfos.map(tabInfo => {
  150. return (
  151. <Tab
  152. label={tabInfo.name}
  153. render={renderCustomTab(this, tabInfo)}
  154. >
  155. {currentUsage.length === 0 ? (
  156. <Message>{tabInfo.emptyMessage}</Message>
  157. ) : (
  158. <ReactHighcharts
  159. config={getChartConfig(
  160. this.chartConfig,
  161. currentUsage,
  162. contract,
  163. selectedYear,
  164. this.state.activeTab
  165. )}
  166. isPureConfig={false}
  167. />
  168. )}
  169. </Tab>
  170. );
  171. })}
  172. </Tabs>
  173. </div>
  174. }
  175. </div>
  176. </section>
  177. );
  178. };
  179. }
Add Comment
Please, Sign In to add comment