chartFooter.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import OptionSelector from 'sentry/components/charts/optionSelector';
  2. import {
  3. ChartControls,
  4. InlineContainer,
  5. SectionHeading,
  6. SectionValue,
  7. } from 'sentry/components/charts/styles';
  8. import {t} from 'sentry/locale';
  9. import {Organization, SelectValue} from 'sentry/types';
  10. import {TOP_EVENT_MODES} from 'sentry/utils/discover/types';
  11. type Props = {
  12. displayMode: string;
  13. displayOptions: SelectValue<string>[];
  14. onAxisChange: (value: string[]) => void;
  15. onDisplayChange: (value: string) => void;
  16. onTopEventsChange: (value: string) => void;
  17. organization: Organization;
  18. topEvents: string;
  19. total: number | null;
  20. yAxisOptions: SelectValue<string>[];
  21. yAxisValue: string[];
  22. };
  23. export default function ChartFooter({
  24. total,
  25. yAxisValue,
  26. yAxisOptions,
  27. onAxisChange,
  28. displayMode,
  29. displayOptions,
  30. onDisplayChange,
  31. onTopEventsChange,
  32. topEvents,
  33. }: Props) {
  34. const elements: React.ReactNode[] = [];
  35. elements.push(<SectionHeading key="total-label">{t('Total Events')}</SectionHeading>);
  36. elements.push(
  37. total === null ? (
  38. <SectionValue data-test-id="loading-placeholder" key="total-value">
  39. &mdash;
  40. </SectionValue>
  41. ) : (
  42. <SectionValue key="total-value">{total.toLocaleString()}</SectionValue>
  43. )
  44. );
  45. const topEventOptions: SelectValue<string>[] = [];
  46. for (let i = 1; i <= 10; i++) {
  47. topEventOptions.push({value: i.toString(), label: i.toString()});
  48. }
  49. return (
  50. <ChartControls>
  51. <InlineContainer>{elements}</InlineContainer>
  52. <InlineContainer>
  53. <OptionSelector
  54. title={t('Display')}
  55. selected={displayMode}
  56. options={displayOptions}
  57. onChange={onDisplayChange}
  58. />
  59. {TOP_EVENT_MODES.includes(displayMode) && (
  60. <OptionSelector
  61. title={t('Limit')}
  62. selected={topEvents}
  63. options={topEventOptions}
  64. onChange={onTopEventsChange}
  65. />
  66. )}
  67. {TOP_EVENT_MODES.includes(displayMode) ? (
  68. <OptionSelector
  69. title={t('Y-Axis')}
  70. selected={yAxisValue[0]}
  71. options={yAxisOptions}
  72. onChange={yAxis => onAxisChange([yAxis])}
  73. />
  74. ) : (
  75. <OptionSelector
  76. multiple
  77. title={t('Y-Axis')}
  78. selected={yAxisValue}
  79. options={yAxisOptions}
  80. onChange={onAxisChange}
  81. />
  82. )}
  83. </InlineContainer>
  84. </ChartControls>
  85. );
  86. }