releaseSelector.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {browserHistory} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {CompactSelect} from 'sentry/components/compactSelect';
  4. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  5. import {t} from 'sentry/locale';
  6. import {defined} from 'sentry/utils';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import {
  9. useReleases,
  10. useReleaseSelection,
  11. } from 'sentry/views/starfish/queries/useReleases';
  12. const ALL_RELEASES = {
  13. value: '',
  14. label: t('All Releases'),
  15. };
  16. type Props = {
  17. selectorKey: string;
  18. selectorName?: string;
  19. selectorValue?: string;
  20. };
  21. export function ReleaseSelector({selectorName, selectorKey, selectorValue}: Props) {
  22. const {data, isLoading} = useReleases();
  23. const location = useLocation();
  24. let value = selectorValue;
  25. if (!isLoading && !defined(value)) {
  26. value = ALL_RELEASES.value;
  27. }
  28. return (
  29. <StyledCompactSelect
  30. triggerProps={{
  31. prefix: selectorName,
  32. }}
  33. value={selectorValue}
  34. options={[
  35. ...(data ?? [ALL_RELEASES]).map(release => ({
  36. value: release.version,
  37. label: release.shortVersion ?? release.version,
  38. })),
  39. ]}
  40. onChange={newValue => {
  41. browserHistory.push({
  42. ...location,
  43. query: {
  44. ...location.query,
  45. [selectorKey]: newValue.value,
  46. },
  47. });
  48. }}
  49. />
  50. );
  51. }
  52. export function ReleaseComparisonSelector() {
  53. const {primaryRelease, secondaryRelease} = useReleaseSelection();
  54. return (
  55. <PageFilterBar condensed>
  56. <ReleaseSelector selectorKey="primaryRelease" selectorValue={primaryRelease} />
  57. <ReleaseSelector
  58. selectorKey="secondaryRelease"
  59. selectorName={t('Compared To')}
  60. selectorValue={secondaryRelease}
  61. />
  62. </PageFilterBar>
  63. );
  64. }
  65. const StyledCompactSelect = styled(CompactSelect)`
  66. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  67. max-width: 275px;
  68. }
  69. `;