From 9bf40795d625c0082bc4a2f295a4877bca8cc98a Mon Sep 17 00:00:00 2001 From: Jono M Date: Wed, 13 Sep 2023 08:42:58 +0100 Subject: [PATCH] Added staff filtering to AdminX history view (#18104) refs https://github.com/TryGhost/Product/issues/3832 --- This pull request adds a new feature to filter and view the history of actions performed by staff users in the admin settings. It introduces a new route and a MultiSelect component for the history modal, and updates the UserDetailModal component to link to the history modal with the user parameter. --- .../components/providers/RoutingProvider.tsx | 1 + .../settings/advanced/HistoryModal.tsx | 62 ++++++++++++------- .../settings/general/UserDetailModal.tsx | 3 +- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/apps/admin-x-settings/src/components/providers/RoutingProvider.tsx b/apps/admin-x-settings/src/components/providers/RoutingProvider.tsx index a1bde12b88..0d6720f362 100644 --- a/apps/admin-x-settings/src/components/providers/RoutingProvider.tsx +++ b/apps/admin-x-settings/src/components/providers/RoutingProvider.tsx @@ -72,6 +72,7 @@ const modalPaths: {[key: string]: () => Promise<{default: React.FC void; toggleResourceType: (resource: string, included: boolean) => void; -}> = ({excludedEvents, excludedResources, toggleEventType, toggleResourceType}) => { +}> = ({userId, excludedEvents, excludedResources, toggleEventType, toggleResourceType}) => { + const {updateRoute} = useRouting(); + const {users} = useStaffUsers(); + return ( - }> -
- - - - - - - - - - - - -
-
+
+ }> +
+ + + + + + + + + + + + +
+
+ {userId ? +
); }; @@ -131,13 +151,12 @@ const formatDateForFilter = (date: Date) => { const PAGE_SIZE = 200; -const HistoryModal = NiceModal.create(() => { +const HistoryModal = NiceModal.create(({params}) => { const modal = useModal(); const {updateRoute} = useRouting(); const [excludedEvents, setExcludedEvents] = useState([]); const [excludedResources, setExcludedResources] = useState(['label']); - const [user] = useState(); const {data, fetchNextPage} = useBrowseActions({ searchParams: { @@ -146,12 +165,12 @@ const HistoryModal = NiceModal.create(() => { filter: [ excludedEvents.length && `event:-[${excludedEvents.join(',')}]`, excludedResources.length && `resource_type:-[${excludedResources.join(',')}]`, - user && `actor_id:${user}` + params?.user && `actor_id:${params.user}` ].filter(Boolean).join('+') }, getNextPageParams: (lastPage, otherParams) => ({ ...otherParams, - filter: [otherParams.filter, `created_at:<'${formatDateForFilter(new Date(lastPage.actions[lastPage.actions.length - 1].created_at))}'`].join('+') + filter: [otherParams.filter, lastPage.actions.length && `created_at:<'${formatDateForFilter(new Date(lastPage.actions[lastPage.actions.length - 1].created_at))}'`].join('+') }), keepPreviousData: true }); @@ -183,6 +202,7 @@ const HistoryModal = NiceModal.create(() => { excludedResources={excludedResources} toggleEventType={(event, included) => toggleValue(setExcludedEvents, event, !included)} toggleResourceType={(resource, included) => toggleValue(setExcludedResources, resource, !included)} + userId={params?.user} />} onOk={() => { modal.remove(); diff --git a/apps/admin-x-settings/src/components/settings/general/UserDetailModal.tsx b/apps/admin-x-settings/src/components/settings/general/UserDetailModal.tsx index 1cfafcb834..cd23bf9a4f 100644 --- a/apps/admin-x-settings/src/components/settings/general/UserDetailModal.tsx +++ b/apps/admin-x-settings/src/components/settings/general/UserDetailModal.tsx @@ -623,7 +623,8 @@ const UserDetailModalContent: React.FC<{user: User}> = ({user}) => { id: 'view-user-activity', label: 'View user activity', onClick: () => { - // TODO: show user activity + mainModal.remove(); + updateRoute(`history/view/${userData.id}`); } } ]);