2
0
Эх сурвалжийг харах

Copy the URL to clipboard after clicking on it

Shun Miyazawa 3 жил өмнө
parent
commit
6554342e8f

+ 22 - 3
packages/app/src/components/Admin/AuditLog/ActivityTable.tsx

@@ -1,9 +1,11 @@
-import React, { FC } from 'react';
+import React, { FC, useState, useCallback } from 'react';
 
 
 import { pagePathUtils } from '@growi/core';
 import { pagePathUtils } from '@growi/core';
 import { UserPicture } from '@growi/ui';
 import { UserPicture } from '@growi/ui';
 import { format } from 'date-fns';
 import { format } from 'date-fns';
+import { CopyToClipboard } from 'react-copy-to-clipboard';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
+import { Tooltip } from 'reactstrap';
 
 
 import { IActivityHasId } from '~/interfaces/activity';
 import { IActivityHasId } from '~/interfaces/activity';
 
 
@@ -17,6 +19,14 @@ const formatDate = (date) => {
 
 
 export const ActivityTable : FC<Props> = (props: Props) => {
 export const ActivityTable : FC<Props> = (props: Props) => {
   const { t } = useTranslation();
   const { t } = useTranslation();
+  const [tooltopOpen, setTooltipOpen] = useState(false);
+
+  const showToolTip = useCallback(() => {
+    setTooltipOpen(true);
+    setTimeout(() => {
+      setTooltipOpen(false);
+    }, 1000);
+  }, [setTooltipOpen]);
 
 
   return (
   return (
     <div className="table-responsive text-nowrap h-100">
     <div className="table-responsive text-nowrap h-100">
@@ -27,7 +37,7 @@ export const ActivityTable : FC<Props> = (props: Props) => {
             <th scope="col">{t('admin:audit_log_management.date')}</th>
             <th scope="col">{t('admin:audit_log_management.date')}</th>
             <th scope="col">{t('admin:audit_log_management.action')}</th>
             <th scope="col">{t('admin:audit_log_management.action')}</th>
             <th scope="col">{t('admin:audit_log_management.ip')}</th>
             <th scope="col">{t('admin:audit_log_management.ip')}</th>
-            <th scope="col">{t('admin:audit_log_management.url')}</th>
+            <th scope="col">{t('admin:audit_log_management.url')} </th>
           </tr>
           </tr>
         </thead>
         </thead>
         <tbody>
         <tbody>
@@ -45,7 +55,16 @@ export const ActivityTable : FC<Props> = (props: Props) => {
                 <td>{formatDate(activity.createdAt)}</td>
                 <td>{formatDate(activity.createdAt)}</td>
                 <td>{t(`admin:audit_log_action.${activity.action}`)}</td>
                 <td>{t(`admin:audit_log_action.${activity.action}`)}</td>
                 <td>{activity.ip}</td>
                 <td>{activity.ip}</td>
-                <td>{activity.endpoint}</td>
+                <td>
+                  <CopyToClipboard text={activity.endpoint} onCopy={showToolTip}>
+                    <button id="urlButton" type="button" className="btn btn-link">
+                      {activity.endpoint}
+                    </button>
+                  </CopyToClipboard>
+                  <Tooltip placement="top" isOpen={tooltopOpen} fade={false} target="urlButton">
+                    copied!
+                  </Tooltip>
+                </td>
               </tr>
               </tr>
             );
             );
           })}
           })}