doubleAxisDisplay.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {useState} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Location} from 'history';
  5. import {Panel} from 'sentry/components/panels';
  6. import space from 'sentry/styles/space';
  7. import {Organization} from 'sentry/types';
  8. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  9. import 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 {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. trackAnalyticsEvent({
  37. eventKey: 'performance_views.landingv2.display.filter_change',
  38. eventName: 'Performance Views: Landing v2 Display Filter Change',
  39. organization_id: parseInt(organization.id, 10),
  40. field,
  41. min_value: parseInt(minValue, 10),
  42. max_value: parseInt(maxValue, 10),
  43. });
  44. browserHistory.push({
  45. pathname: location.pathname,
  46. query: {
  47. ...location.query,
  48. query: String(query).trim(),
  49. },
  50. });
  51. };
  52. const didReceiveMultiAxis = (useBackup: boolean) => {
  53. setUsingBackupAxis(useBackup);
  54. };
  55. const leftAxisOrBackup = getAxisOrBackupAxis(leftAxis, usingBackupAxis);
  56. const rightAxisOrBackup = getAxisOrBackupAxis(rightAxis, usingBackupAxis);
  57. const optionsOrBackup = getBackupAxes(axisOptions, usingBackupAxis);
  58. return (
  59. <Panel>
  60. <DoubleChartContainer>
  61. <SingleAxisChart
  62. axis={leftAxis}
  63. onFilterChange={onFilterChange(leftAxis.field)}
  64. didReceiveMultiAxis={didReceiveMultiAxis}
  65. usingBackupAxis={usingBackupAxis}
  66. {...props}
  67. />
  68. <SingleAxisChart
  69. axis={rightAxis}
  70. onFilterChange={onFilterChange(rightAxis.field)}
  71. didReceiveMultiAxis={didReceiveMultiAxis}
  72. usingBackupAxis={usingBackupAxis}
  73. {...props}
  74. />
  75. </DoubleChartContainer>
  76. <Footer
  77. options={optionsOrBackup}
  78. leftAxis={leftAxisOrBackup.value}
  79. rightAxis={rightAxisOrBackup.value}
  80. organization={organization}
  81. eventView={eventView}
  82. location={location}
  83. />
  84. </Panel>
  85. );
  86. }
  87. const DoubleChartContainer = styled('div')`
  88. display: grid;
  89. grid-template-columns: 1fr 1fr;
  90. gap: ${space(3)};
  91. min-height: 282px;
  92. `;
  93. const Footer = withApi(_Footer);
  94. export default DoubleAxisDisplay;