feedbackListHeader.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import Checkbox from 'sentry/components/checkbox';
  4. import decodeMailbox from 'sentry/components/feedback/decodeMailbox';
  5. import FeedbackListBulkSelection from 'sentry/components/feedback/list/feedbackListBulkSelection';
  6. import MailboxPicker from 'sentry/components/feedback/list/mailboxPicker';
  7. import type useListItemCheckboxState from 'sentry/components/feedback/list/useListItemCheckboxState';
  8. import useFeedbackCache from 'sentry/components/feedback/useFeedbackCache';
  9. import useFeedbackHasNewItems from 'sentry/components/feedback/useFeedbackHasNewItems';
  10. import useFeedbackQueryKeys from 'sentry/components/feedback/useFeedbackQueryKeys';
  11. import {IconRefresh} from 'sentry/icons';
  12. import {t} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import useLocationQuery from 'sentry/utils/url/useLocationQuery';
  15. import useUrlParams from 'sentry/utils/useUrlParams';
  16. interface Props
  17. extends Pick<
  18. ReturnType<typeof useListItemCheckboxState>,
  19. | 'countSelected'
  20. | 'deselectAll'
  21. | 'isAllSelected'
  22. | 'isAnySelected'
  23. | 'selectAll'
  24. | 'selectedIds'
  25. > {}
  26. export default function FeedbackListHeader({
  27. countSelected,
  28. deselectAll,
  29. isAllSelected,
  30. isAnySelected,
  31. selectAll,
  32. selectedIds,
  33. }: Props) {
  34. const {mailbox} = useLocationQuery({
  35. fields: {
  36. mailbox: decodeMailbox,
  37. },
  38. });
  39. const {setParamValue: setMailbox} = useUrlParams('mailbox');
  40. const {listPrefetchQueryKey, resetListHeadTime} = useFeedbackQueryKeys();
  41. const hasNewItems = useFeedbackHasNewItems({listPrefetchQueryKey});
  42. const {invalidateListCache} = useFeedbackCache();
  43. return (
  44. <HeaderPanel>
  45. <HeaderPanelItem>
  46. <Checkbox
  47. checked={isAllSelected}
  48. onChange={() => {
  49. if (isAllSelected === true) {
  50. deselectAll();
  51. } else {
  52. selectAll();
  53. }
  54. }}
  55. />
  56. {isAnySelected ? (
  57. <FeedbackListBulkSelection
  58. mailbox={mailbox}
  59. countSelected={countSelected}
  60. selectedIds={selectedIds}
  61. deselectAll={deselectAll}
  62. />
  63. ) : (
  64. <MailboxPicker value={mailbox} onChange={setMailbox} />
  65. )}
  66. </HeaderPanelItem>
  67. {hasNewItems ? (
  68. <RefreshContainer>
  69. <Button
  70. priority="primary"
  71. size="xs"
  72. icon={<IconRefresh />}
  73. onClick={() => {
  74. // Get a new date for polling:
  75. resetListHeadTime();
  76. // Clear the list cache and let people start over from the newest
  77. // data in the list:
  78. invalidateListCache();
  79. }}
  80. >
  81. {t('Load new feedback')}
  82. </Button>
  83. </RefreshContainer>
  84. ) : null}
  85. </HeaderPanel>
  86. );
  87. }
  88. const HeaderPanel = styled('div')`
  89. flex-direction: column;
  90. `;
  91. const HeaderPanelItem = styled('div')`
  92. padding: ${space(1)} ${space(1.5)} ${space(1)} 18px;
  93. display: flex;
  94. gap: ${space(1)};
  95. align-items: center;
  96. border-bottom: 1px solid ${p => p.theme.innerBorder};
  97. `;
  98. const RefreshContainer = styled('div')`
  99. display: flex;
  100. align-items: center;
  101. justify-content: center;
  102. flex-grow: 1;
  103. padding: ${space(0.5)};
  104. `;