chartFooter.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import * as React from 'react';
  2. import Feature from 'sentry/components/acl/feature';
  3. import OptionCheckboxSelector from 'sentry/components/charts/optionCheckboxSelector';
  4. import OptionSelector from 'sentry/components/charts/optionSelector';
  5. import {
  6. ChartControls,
  7. InlineContainer,
  8. SectionHeading,
  9. SectionValue,
  10. } from 'sentry/components/charts/styles';
  11. import {t} from 'sentry/locale';
  12. import {Organization, SelectValue} from 'sentry/types';
  13. import {TOP_EVENT_MODES} from 'sentry/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. {TOP_EVENT_MODES.includes(displayMode) && (
  65. <OptionSelector
  66. title={t('Limit')}
  67. selected={topEvents}
  68. options={topEventOptions}
  69. onChange={onTopEventsChange}
  70. menuWidth="60px"
  71. />
  72. )}
  73. <Feature
  74. organization={organization}
  75. features={['connect-discover-and-dashboards']}
  76. >
  77. {({hasFeature}) => {
  78. if (hasFeature) {
  79. return (
  80. <OptionCheckboxSelector
  81. title={t('Y-Axis')}
  82. selected={yAxisValue}
  83. options={yAxisOptions}
  84. onChange={onAxisChange}
  85. />
  86. );
  87. }
  88. return (
  89. <OptionSelector
  90. title={t('Y-Axis')}
  91. selected={yAxisValue[0]}
  92. options={yAxisOptions}
  93. onChange={value => onAxisChange([value])}
  94. />
  95. );
  96. }}
  97. </Feature>
  98. </InlineContainer>
  99. </ChartControls>
  100. );
  101. }