index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {Fragment, MouseEventHandler} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import SwitchButton from 'sentry/components/switchButton';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import ResourceTable from 'sentry/views/performance/browser/resources/jsCssView/resourceTable';
  9. import DomainSelector from 'sentry/views/performance/browser/resources/shared/domainSelector';
  10. import SelectControlWithProps from 'sentry/views/performance/browser/resources/shared/selectControlWithProps';
  11. import {
  12. BrowserStarfishFields,
  13. useResourceModuleFilters,
  14. } from 'sentry/views/performance/browser/resources/utils/useResourceFilters';
  15. import {useResourcePagesQuery} from 'sentry/views/performance/browser/resources/utils/useResourcePagesQuery';
  16. import {useResourceSort} from 'sentry/views/performance/browser/resources/utils/useResourceSort';
  17. const {
  18. SPAN_OP: RESOURCE_TYPE,
  19. SPAN_DOMAIN,
  20. TRANSACTION,
  21. RESOURCE_RENDER_BLOCKING_STATUS,
  22. } = BrowserStarfishFields;
  23. type Option = {
  24. label: string;
  25. value: string;
  26. };
  27. function JSCSSView() {
  28. const filters = useResourceModuleFilters();
  29. const sort = useResourceSort();
  30. const location = useLocation();
  31. const handleBlockingToggle: MouseEventHandler = () => {
  32. const hasBlocking = filters[RESOURCE_RENDER_BLOCKING_STATUS] === 'blocking';
  33. const newBlocking = hasBlocking ? undefined : 'blocking';
  34. browserHistory.push({
  35. ...location,
  36. query: {
  37. ...location.query,
  38. [RESOURCE_RENDER_BLOCKING_STATUS]: newBlocking,
  39. },
  40. });
  41. };
  42. return (
  43. <Fragment>
  44. <FilterOptionsContainer>
  45. <DomainSelector value={filters[SPAN_DOMAIN] || ''} />
  46. <ResourceTypeSelector value={filters[RESOURCE_TYPE] || ''} />
  47. <PageSelector value={filters[TRANSACTION] || ''} />
  48. <SwitchContainer>
  49. <SwitchButton
  50. isActive={filters[RESOURCE_RENDER_BLOCKING_STATUS] === 'blocking'}
  51. toggle={handleBlockingToggle}
  52. />
  53. {t('Render Blocking')}
  54. </SwitchContainer>
  55. </FilterOptionsContainer>
  56. <ResourceTable sort={sort} />
  57. </Fragment>
  58. );
  59. }
  60. function ResourceTypeSelector({value}: {value?: string}) {
  61. const location = useLocation();
  62. const options: Option[] = [
  63. {value: '', label: 'All'},
  64. {value: 'resource.script', label: `${t('JavaScript')} (.js)`},
  65. {value: 'resource.css', label: `${t('Stylesheet')} (.css)`},
  66. ];
  67. return (
  68. <SelectControlWithProps
  69. inFieldLabel={`${t('Type')}:`}
  70. options={options}
  71. value={value}
  72. onChange={newValue => {
  73. browserHistory.push({
  74. ...location,
  75. query: {
  76. ...location.query,
  77. [RESOURCE_TYPE]: newValue?.value,
  78. },
  79. });
  80. }}
  81. />
  82. );
  83. }
  84. function PageSelector({value}: {value?: string}) {
  85. const location = useLocation();
  86. const {data: pages} = useResourcePagesQuery();
  87. const options: Option[] = [
  88. {value: '', label: 'All'},
  89. ...pages.map(page => ({value: page, label: page})),
  90. ];
  91. return (
  92. <SelectControlWithProps
  93. inFieldLabel={`${t('Page')}:`}
  94. options={options}
  95. value={value}
  96. onChange={newValue => {
  97. browserHistory.push({
  98. ...location,
  99. query: {
  100. ...location.query,
  101. [TRANSACTION]: newValue?.value,
  102. },
  103. });
  104. }}
  105. />
  106. );
  107. }
  108. const SwitchContainer = styled('div')`
  109. display: flex;
  110. align-items: center;
  111. column-gap: ${space(1)};
  112. `;
  113. export const FilterOptionsContainer = styled('div')`
  114. display: grid;
  115. grid-template-columns: repeat(4, 1fr);
  116. gap: ${space(2)};
  117. margin-bottom: ${space(2)};
  118. max-width: 800px;
  119. `;
  120. export default JSCSSView;