useReplayLayout.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import {useCallback} from 'react';
  2. import PreferencesStore from 'sentry/stores/preferencesStore';
  3. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  4. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import useUrlParams from 'sentry/utils/useUrlParams';
  7. import {getDefaultLayout} from 'sentry/views/replays/detail/layout/utils';
  8. export enum LayoutKey {
  9. /**
  10. * ### Top
  11. *┌────────────────────┐
  12. *│ Timeline │
  13. *├───────────┬────────┤
  14. *│ Video > Crumbs │
  15. *│ > │
  16. *├^^^^^^^^^^^> |
  17. *│ Details > │
  18. *│ > │
  19. *└───────────┴────────┘
  20. */
  21. top = 'top',
  22. /**
  23. * ### Top
  24. *┌────────────────────┐
  25. *│ Timeline │
  26. *├───────────┬────────┤
  27. *│ Details > Crumbs │
  28. *│ > │
  29. *│ > |
  30. *│ > │
  31. *│ > │
  32. *└───────────┴────────┘
  33. */
  34. no_video = 'no_video',
  35. /**
  36. * ### Video Only
  37. *┌────────────────────┐
  38. *│ Timeline │
  39. *├────────────────────┤
  40. *│ │
  41. *│ |
  42. *│ Video │
  43. *│ │
  44. *│ │
  45. *└────────────────────┘
  46. */
  47. video_only = 'video_only',
  48. /**
  49. * ### Topbar
  50. *┌────────────────────┐
  51. *│ Timeline │
  52. *├───────────┬────────┤
  53. *│ Video │ Crumbs │
  54. *│ │ │
  55. *├^^^^^^^^^^^^^^^^^^^^┤
  56. *│ Details │
  57. *│ │
  58. *└────────────────────┘
  59. */
  60. topbar = 'topbar',
  61. /**
  62. * ### Sidebar Left
  63. * ┌───────────────────┐
  64. * │ Timeline │
  65. * ├────────┬──────────┤
  66. * │ Video > Details │
  67. * │ > │
  68. * │^^^^^^^ > |
  69. * │ Crumbs > │
  70. * │ Tabs > │
  71. * └────────┴──────────┘
  72. */
  73. sidebar_left = 'sidebar_left',
  74. /**
  75. * ### Sidebar Right
  76. * ┌───────────────────┐
  77. * │ Timeline │
  78. * ├──────────┬────────┤
  79. * │ Details > Video │
  80. * │ > │
  81. * │ >^^^^^^^^┤
  82. * │ > Crumbs │
  83. * │ > Tabs │
  84. * └──────────┴────────┘
  85. */
  86. sidebar_right = 'sidebar_right',
  87. }
  88. function isLayout(val: string): val is LayoutKey {
  89. return val in LayoutKey;
  90. }
  91. function useActiveReplayTab() {
  92. const collapsed = !!useLegacyStore(PreferencesStore).collapsed;
  93. const defaultLayout = getDefaultLayout(collapsed);
  94. const organization = useOrganization();
  95. const {getParamValue, setParamValue} = useUrlParams('l_page', defaultLayout);
  96. const paramValue = getParamValue();
  97. return {
  98. getLayout: useCallback(
  99. (): LayoutKey =>
  100. isLayout(paramValue || '') ? (paramValue as LayoutKey) : defaultLayout,
  101. [defaultLayout, paramValue]
  102. ),
  103. setLayout: useCallback(
  104. (value: string) => {
  105. const chosenLayout = isLayout(value) ? value : defaultLayout;
  106. setParamValue(chosenLayout);
  107. trackAdvancedAnalyticsEvent('replay.details-layout-changed', {
  108. organization,
  109. default_layout: defaultLayout,
  110. chosen_layout: chosenLayout,
  111. });
  112. },
  113. [organization, defaultLayout, setParamValue]
  114. ),
  115. };
  116. }
  117. export default useActiveReplayTab;