chartFooter.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. type Props = {
  14. organization: Organization;
  15. total: number | null;
  16. yAxisValue: string[];
  17. yAxisOptions: SelectValue<string>[];
  18. onAxisChange: (value: string[]) => void;
  19. displayMode: string;
  20. displayOptions: SelectValue<string>[];
  21. onDisplayChange: (value: string) => void;
  22. };
  23. export default function ChartFooter({
  24. organization,
  25. total,
  26. yAxisValue,
  27. yAxisOptions,
  28. onAxisChange,
  29. displayMode,
  30. displayOptions,
  31. onDisplayChange,
  32. }: Props) {
  33. const elements: React.ReactNode[] = [];
  34. elements.push(<SectionHeading key="total-label">{t('Total Events')}</SectionHeading>);
  35. elements.push(
  36. total === null ? (
  37. <SectionValue data-test-id="loading-placeholder" key="total-value">
  38. &mdash;
  39. </SectionValue>
  40. ) : (
  41. <SectionValue key="total-value">{total.toLocaleString()}</SectionValue>
  42. )
  43. );
  44. return (
  45. <ChartControls>
  46. <InlineContainer>{elements}</InlineContainer>
  47. <InlineContainer>
  48. <OptionSelector
  49. title={t('Display')}
  50. selected={displayMode}
  51. options={displayOptions}
  52. onChange={onDisplayChange}
  53. menuWidth="170px"
  54. />
  55. <Feature
  56. organization={organization}
  57. features={['connect-discover-and-dashboards']}
  58. >
  59. {({hasFeature}) => {
  60. if (hasFeature) {
  61. return (
  62. <OptionCheckboxSelector
  63. title={t('Y-Axis')}
  64. selected={yAxisValue}
  65. options={yAxisOptions}
  66. onChange={onAxisChange}
  67. />
  68. );
  69. } else {
  70. return (
  71. <OptionSelector
  72. title={t('Y-Axis')}
  73. selected={yAxisValue[0]}
  74. options={yAxisOptions}
  75. onChange={value => onAxisChange([value])}
  76. />
  77. );
  78. }
  79. }}
  80. </Feature>
  81. </InlineContainer>
  82. </ChartControls>
  83. );
  84. }