doubleAxisDisplay.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {useState} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import type {Location} from 'history';
  5. import Panel from 'sentry/components/panels/panel';
  6. import {space} from 'sentry/styles/space';
  7. import type {Organization} from 'sentry/types';
  8. import {trackAnalytics} from 'sentry/utils/analytics';
  9. import type EventView from 'sentry/utils/discover/eventView';
  10. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  11. import withApi from 'sentry/utils/withApi';
  12. import _Footer from '../../charts/footer';
  13. import type {AxisOption} from '../../data';
  14. import {getTransactionSearchQuery} from '../../utils';
  15. import {SingleAxisChart} from './singleAxisChart';
  16. import {getAxisOrBackupAxis, getBackupAxes} from './utils';
  17. type Props = {
  18. axisOptions: AxisOption[];
  19. eventView: EventView;
  20. leftAxis: AxisOption;
  21. location: Location;
  22. organization: Organization;
  23. rightAxis: AxisOption;
  24. };
  25. function DoubleAxisDisplay(props: Props) {
  26. const {eventView, location, organization, axisOptions, leftAxis, rightAxis} = props;
  27. const [usingBackupAxis, setUsingBackupAxis] = useState(false);
  28. const onFilterChange = (field: string) => (minValue, maxValue) => {
  29. const filterString = getTransactionSearchQuery(location);
  30. const conditions = new MutableSearch(filterString);
  31. conditions.setFilterValues(field, [
  32. `>=${Math.round(minValue)}`,
  33. `<${Math.round(maxValue)}`,
  34. ]);
  35. const query = conditions.formatString();
  36. trackAnalytics('performance_views.landingv2.display.filter_change', {
  37. organization,
  38. field,
  39. min_value: parseInt(minValue, 10),
  40. max_value: parseInt(maxValue, 10),
  41. });
  42. browserHistory.push({
  43. pathname: location.pathname,
  44. query: {
  45. ...location.query,
  46. query: String(query).trim(),
  47. },
  48. });
  49. };
  50. const didReceiveMultiAxis = (useBackup: boolean) => {
  51. setUsingBackupAxis(useBackup);
  52. };
  53. const leftAxisOrBackup = getAxisOrBackupAxis(leftAxis, usingBackupAxis);
  54. const rightAxisOrBackup = getAxisOrBackupAxis(rightAxis, usingBackupAxis);
  55. const optionsOrBackup = getBackupAxes(axisOptions, usingBackupAxis);
  56. return (
  57. <Panel>
  58. <DoubleChartContainer>
  59. <SingleAxisChart
  60. axis={leftAxis}
  61. onFilterChange={onFilterChange(leftAxis.field)}
  62. didReceiveMultiAxis={didReceiveMultiAxis}
  63. usingBackupAxis={usingBackupAxis}
  64. {...props}
  65. />
  66. <SingleAxisChart
  67. axis={rightAxis}
  68. onFilterChange={onFilterChange(rightAxis.field)}
  69. didReceiveMultiAxis={didReceiveMultiAxis}
  70. usingBackupAxis={usingBackupAxis}
  71. {...props}
  72. />
  73. </DoubleChartContainer>
  74. <Footer
  75. options={optionsOrBackup}
  76. leftAxis={leftAxisOrBackup.value}
  77. rightAxis={rightAxisOrBackup.value}
  78. organization={organization}
  79. eventView={eventView}
  80. location={location}
  81. />
  82. </Panel>
  83. );
  84. }
  85. const DoubleChartContainer = styled('div')`
  86. display: grid;
  87. grid-template-columns: 1fr 1fr;
  88. gap: ${space(3)};
  89. min-height: 282px;
  90. `;
  91. const Footer = withApi(_Footer);
  92. export default DoubleAxisDisplay;