chartFooter.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. isClearable
  78. menuTitle={
  79. yAxisOptions.length > 3 ? t('Select up to 3 options') : t('Y-axis')
  80. }
  81. title={t('Y-Axis')}
  82. selected={yAxisValue}
  83. options={yAxisOptions}
  84. onChange={onAxisChange}
  85. />
  86. )}
  87. </InlineContainer>
  88. </ChartControls>
  89. );
  90. }