chartFooter.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import * as React from 'react';
  2. import Feature from 'app/components/acl/feature';
  3. import OptionCheckboxSelector from 'app/components/charts/optionCheckboxSelector';
  4. import OptionSelector from 'app/components/charts/optionSelector';
  5. import {
  6. ChartControls,
  7. InlineContainer,
  8. SectionHeading,
  9. SectionValue,
  10. } from 'app/components/charts/styles';
  11. import {t} from 'app/locale';
  12. import {Organization, SelectValue} from 'app/types';
  13. import {TOP_EVENT_MODES} from 'app/utils/discover/types';
  14. type Props = {
  15. organization: Organization;
  16. total: number | null;
  17. yAxisValue: string[];
  18. yAxisOptions: SelectValue<string>[];
  19. onAxisChange: (value: string[]) => void;
  20. displayMode: string;
  21. displayOptions: SelectValue<string>[];
  22. onDisplayChange: (value: string) => void;
  23. onTopEventsChange: (value: string) => void;
  24. topEvents: string;
  25. };
  26. export default function ChartFooter({
  27. organization,
  28. total,
  29. yAxisValue,
  30. yAxisOptions,
  31. onAxisChange,
  32. displayMode,
  33. displayOptions,
  34. onDisplayChange,
  35. onTopEventsChange,
  36. topEvents,
  37. }: Props) {
  38. const elements: React.ReactNode[] = [];
  39. elements.push(<SectionHeading key="total-label">{t('Total Events')}</SectionHeading>);
  40. elements.push(
  41. total === null ? (
  42. <SectionValue data-test-id="loading-placeholder" key="total-value">
  43. &mdash;
  44. </SectionValue>
  45. ) : (
  46. <SectionValue key="total-value">{total.toLocaleString()}</SectionValue>
  47. )
  48. );
  49. const topEventOptions: SelectValue<string>[] = [];
  50. for (let i = 1; i <= 10; i++) {
  51. topEventOptions.push({value: i.toString(), label: i.toString()});
  52. }
  53. return (
  54. <ChartControls>
  55. <InlineContainer>{elements}</InlineContainer>
  56. <InlineContainer>
  57. <OptionSelector
  58. title={t('Display')}
  59. selected={displayMode}
  60. options={displayOptions}
  61. onChange={onDisplayChange}
  62. menuWidth="170px"
  63. />
  64. <Feature organization={organization} features={['discover-top-events']}>
  65. {({hasFeature}) => {
  66. if (hasFeature && TOP_EVENT_MODES.includes(displayMode)) {
  67. return (
  68. <OptionSelector
  69. title={t('Limit')}
  70. selected={topEvents}
  71. options={topEventOptions}
  72. onChange={onTopEventsChange}
  73. menuWidth="60px"
  74. featureType="beta"
  75. />
  76. );
  77. } else {
  78. return null;
  79. }
  80. }}
  81. </Feature>
  82. <Feature
  83. organization={organization}
  84. features={['connect-discover-and-dashboards']}
  85. >
  86. {({hasFeature}) => {
  87. if (hasFeature) {
  88. return (
  89. <OptionCheckboxSelector
  90. title={t('Y-Axis')}
  91. selected={yAxisValue}
  92. options={yAxisOptions}
  93. onChange={onAxisChange}
  94. />
  95. );
  96. } else {
  97. return (
  98. <OptionSelector
  99. title={t('Y-Axis')}
  100. selected={yAxisValue[0]}
  101. options={yAxisOptions}
  102. onChange={value => onAxisChange([value])}
  103. />
  104. );
  105. }
  106. }}
  107. </Feature>
  108. </InlineContainer>
  109. </ChartControls>
  110. );
  111. }