ActivityTable.tsx 3.0 KB

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