ActivityTable.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import type { FC } from 'react';
  2. import React, { useState, useCallback } from 'react';
  3. import { pagePathUtils } from '@growi/core/dist/utils';
  4. import { UserPicture } from '@growi/ui/dist/components';
  5. import { format } from 'date-fns/format';
  6. import { CopyToClipboard } from 'react-copy-to-clipboard';
  7. import { useTranslation } from 'react-i18next';
  8. import { Tooltip } from 'reactstrap';
  9. import type { IActivityHasId } from '~/interfaces/activity';
  10. type Props = {
  11. activityList: IActivityHasId[]
  12. }
  13. const formatDate = (date) => {
  14. return format(new Date(date), 'yyyy/MM/dd HH:mm:ss');
  15. };
  16. export const ActivityTable : FC<Props> = (props: Props) => {
  17. const { t } = useTranslation();
  18. const [tooltopOpen, setTooltipOpen] = useState(false);
  19. const showToolTip = useCallback(() => {
  20. setTooltipOpen(true);
  21. setTimeout(() => {
  22. setTooltipOpen(false);
  23. }, 1000);
  24. }, [setTooltipOpen]);
  25. return (
  26. <div className="table-responsive text-nowrap h-100">
  27. <table className="table table-default table-bordered table-user-list">
  28. <thead>
  29. <tr>
  30. <th scope="col">{t('admin:audit_log_management.user')}</th>
  31. <th scope="col">{t('admin:audit_log_management.date')}</th>
  32. <th scope="col">{t('admin:audit_log_management.action')}</th>
  33. <th scope="col">{t('admin:audit_log_management.ip')}</th>
  34. <th scope="col">{t('admin:audit_log_management.url')}</th>
  35. </tr>
  36. </thead>
  37. <tbody>
  38. {props.activityList.map((activity) => {
  39. return (
  40. <tr data-testid="activity-table" key={activity._id}>
  41. <td>
  42. { activity.user != null && (
  43. <>
  44. <UserPicture user={activity.user} />
  45. <a
  46. className="ms-2"
  47. href={pagePathUtils.userHomepagePath(activity.user)}
  48. >
  49. {activity.snapshot?.username}
  50. </a>
  51. </>
  52. )}
  53. </td>
  54. <td>{formatDate(activity.createdAt)}</td>
  55. <td>{t(`admin:audit_log_action.${activity.action}`)}</td>
  56. <td>{activity.ip}</td>
  57. <td>
  58. {activity.endpoint}
  59. <CopyToClipboard text={activity.endpoint} onCopy={showToolTip}>
  60. <button type="button" className="btn btn-outline-secondary border-0 pull-right" id="tooltipTarget">
  61. <span className="material-symbols-outlined" aria-hidden="true">content_paste</span>
  62. </button>
  63. </CopyToClipboard>
  64. <Tooltip placement="top" isOpen={tooltopOpen} fade={false} target="tooltipTarget">
  65. copied!
  66. </Tooltip>
  67. </td>
  68. </tr>
  69. );
  70. })}
  71. </tbody>
  72. </table>
  73. </div>
  74. );
  75. };