From 7f9cba98193441c5f133dc099157b7edf7d3e0d0 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 18 Apr 2021 09:38:13 -0700 Subject: [PATCH] feat: Record share link last accessed time (#2047) * chore: Migrations * chore: Add recording of share link views * feat: Add display of share link accessed date in admin * translations * test * translations, admin pagination --- app/models/Share.js | 1 + app/scenes/Settings/Shares.js | 46 +++++++++---------- .../Settings/components/ShareListItem.js | 20 ++++++-- server/api/documents.js | 2 + server/api/documents.test.js | 3 ++ server/api/shares.js | 6 +-- .../20210418053152-share-last-viewed.js | 14 ++++++ server/models/Share.js | 1 + server/presenters/event.js | 4 +- server/presenters/share.js | 11 ++++- shared/i18n/locales/en_US/translation.json | 8 ++++ 11 files changed, 80 insertions(+), 36 deletions(-) create mode 100644 server/migrations/20210418053152-share-last-viewed.js diff --git a/app/models/Share.js b/app/models/Share.js index 3c5305552..c290271a3 100644 --- a/app/models/Share.js +++ b/app/models/Share.js @@ -9,6 +9,7 @@ class Share extends BaseModel { documentId: string; documentTitle: string; documentUrl: string; + lastAccessedAt: ?string; createdBy: User; createdAt: string; updatedAt: string; diff --git a/app/scenes/Settings/Shares.js b/app/scenes/Settings/Shares.js index eaceaa978..b606d56bb 100644 --- a/app/scenes/Settings/Shares.js +++ b/app/scenes/Settings/Shares.js @@ -1,12 +1,13 @@ // @flow import { observer } from "mobx-react"; import * as React from "react"; +import { useTranslation, Trans } from "react-i18next"; import { Link } from "react-router-dom"; import CenteredContent from "components/CenteredContent"; import Empty from "components/Empty"; import HelpText from "components/HelpText"; -import List from "components/List"; import PageTitle from "components/PageTitle"; +import PaginatedList from "components/PaginatedList"; import Subheading from "components/Subheading"; import ShareListItem from "./components/ShareListItem"; import useCurrentTeam from "hooks/useCurrentTeam"; @@ -14,43 +15,40 @@ import useStores from "hooks/useStores"; function Shares() { const team = useCurrentTeam(); + const { t } = useTranslation(); const { shares, auth, policies } = useStores(); const canShareDocuments = auth.team && auth.team.sharing; - const hasSharedDocuments = shares.orderedData.length > 0; const can = policies.abilities(team.id); - React.useEffect(() => { - shares.fetchPage({ limit: 100 }); - }, [shares]); - return ( - -

Share Links

+ +

{t("Share Links")}

- Documents that have been shared are listed below. Anyone that has the - public link can access a read-only version of the document until the - link has been revoked. + + Documents that have been shared are listed below. Anyone that has the + public link can access a read-only version of the document until the + link has been revoked. + {can.manage && ( {!canShareDocuments && ( - Sharing is currently disabled. + {t("Sharing is currently disabled.")} )}{" "} - You can turn {canShareDocuments ? "off" : "on"} public document - sharing in security settings. + }} + /> )} - Shared Documents - {hasSharedDocuments ? ( - - {shares.published.map((share) => ( - - ))} - - ) : ( - No share links, yet. - )} + {t("Shared documents")} + {t("No share links, yet.")}} + fetch={shares.fetchPage} + renderItem={(item) => } + />
); } diff --git a/app/scenes/Settings/components/ShareListItem.js b/app/scenes/Settings/components/ShareListItem.js index 78cb7b5a1..d948b5179 100644 --- a/app/scenes/Settings/components/ShareListItem.js +++ b/app/scenes/Settings/components/ShareListItem.js @@ -1,23 +1,33 @@ // @flow import * as React from "react"; +import { useTranslation } from "react-i18next"; import Share from "models/Share"; import ListItem from "components/List/Item"; import Time from "components/Time"; import ShareMenu from "menus/ShareMenu"; -type Props = { +type Props = {| share: Share, -}; +|}; const ShareListItem = ({ share }: Props) => { + const { t } = useTranslation(); + const { lastAccessedAt } = share; + return ( - Shared