policyRevisions.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import styled from '@emotion/styled';
  2. import moment from 'moment-timezone';
  3. import {Tag} from 'sentry/components/core/badge/tag';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import {space} from 'sentry/styles/space';
  6. import DropdownActions from 'admin/components/dropdownActions';
  7. import ResultGrid from 'admin/components/resultGrid';
  8. import type {Policy, PolicyRevision} from 'getsentry/types';
  9. type Props = {
  10. onUpdate: (data: {[key: string]: any}, version: PolicyRevision['version']) => void;
  11. policy: Policy;
  12. };
  13. type RowProps = Props & {row: PolicyRevision};
  14. const getRow = ({row, policy, onUpdate}: RowProps) => {
  15. return [
  16. <td key="version">
  17. <strong>{row.version}</strong>
  18. {row.version === policy.version && <CurrentTag>current</CurrentTag>}
  19. {row.url ? (
  20. <div>
  21. <ExternalLink href={row.url}>{row.url}</ExternalLink>
  22. </div>
  23. ) : null}
  24. {row.file ? (
  25. <FileName>
  26. {row.file.name} ({row.file.checksum})
  27. </FileName>
  28. ) : null}
  29. </td>,
  30. <td key="date" style={{textAlign: 'right'}}>
  31. {moment(row.createdAt).format('MMMM YYYY')}
  32. <br />
  33. </td>,
  34. <td key="actions" data-test-id="revision-actions">
  35. <DropdownActions
  36. actions={[
  37. {
  38. key: 'make-current',
  39. name: 'Make current',
  40. help: 'Make this the active version of this policy.',
  41. skipConfirmModal: true,
  42. disabled: policy.version === row.version,
  43. onAction: () => onUpdate({current: true}, row.version),
  44. },
  45. ]}
  46. />
  47. </td>,
  48. ];
  49. };
  50. function PolicyRevisions({policy, onUpdate}: Props) {
  51. return (
  52. <ResultGrid
  53. inPanel
  54. panelTitle="Revisions"
  55. path={`/_admin/policies/${policy.slug}/revisions/`}
  56. endpoint={`/policies/${policy.slug}/revisions/`}
  57. method="GET"
  58. columns={[
  59. <th key="customer">Version</th>,
  60. <th key="date" style={{width: 200, textAlign: 'right'}}>
  61. Date Created
  62. </th>,
  63. <th key="actions" style={{width: 50}} />,
  64. ]}
  65. columnsForRow={row => getRow({row, policy, onUpdate})}
  66. defaultParams={{
  67. per_page: 10,
  68. }}
  69. useQueryString={false}
  70. />
  71. );
  72. }
  73. const CurrentTag = styled(Tag)`
  74. margin-left: ${space(1)};
  75. `;
  76. const FileName = styled('div')`
  77. margin-top: ${space(1)};
  78. font-size: ${p => p.theme.fontSizeSmall};
  79. `;
  80. export default PolicyRevisions;