From f42acd38827c9a365754ac45bdfc67f5ba81c5ea Mon Sep 17 00:00:00 2001 From: Rafal Dziegielewski Date: Thu, 17 Aug 2023 16:42:15 +0200 Subject: [PATCH] chore: show list component under bulk actions opened in drawer --- .../components/routes/bulk-action.tsx | 104 ++++++++++++------ 1 file changed, 68 insertions(+), 36 deletions(-) diff --git a/src/frontend/components/routes/bulk-action.tsx b/src/frontend/components/routes/bulk-action.tsx index 5cb840c7e..11b5044f9 100644 --- a/src/frontend/components/routes/bulk-action.tsx +++ b/src/frontend/components/routes/bulk-action.tsx @@ -26,34 +26,42 @@ const BulkAction: React.FC = () => { const params = useParams() const [records, setRecords] = useState>([]) const [loading, setLoading] = useState(false) + const [tag, setTag] = useState('') + const [filterVisible, setFilterVisible] = useState(false) const { translateMessage } = useTranslation() const addNotice = useNotice() const location = useLocation() const { resourceId, actionName } = params + const resource = useResource(resourceId!) + const listActionName = 'list' + const listAction = resource?.resourceActions.find((r) => r.name === listActionName) const fetchRecords = (): Promise => { const recordIdsString = new URLSearchParams(location.search).get('recordIds') const recordIds = recordIdsString ? recordIdsString.split(',') : [] setLoading(true) - return api.bulkAction({ - resourceId: resourceId!, - recordIds, - actionName: actionName!, - }).then((response) => { - setLoading(false) - setRecords(response.data.records) - }).catch((error) => { - setLoading(false) - addNotice({ - message: 'errorFetchingRecords', - type: 'error', - resourceId, + return api + .bulkAction({ + resourceId: resourceId!, + recordIds, + actionName: actionName!, + }) + .then((response) => { + setLoading(false) + setRecords(response.data.records) + }) + .catch((error) => { + setLoading(false) + addNotice({ + message: 'errorFetchingRecords', + type: 'error', + resourceId, + }) + throw error }) - throw error - }) } useEffect(() => { @@ -61,7 +69,7 @@ const BulkAction: React.FC = () => { }, [params.resourceId, params.actionName]) if (!resource) { - return () + return } if (!records && !loading) { @@ -76,38 +84,62 @@ const BulkAction: React.FC = () => { if (loading) { const actionFromResource = resource.actions.find((r) => r.name === actionName) - return actionFromResource?.showInDrawer ? () : + return actionFromResource?.showInDrawer ? ( + + + + ) : ( + + ) } if (!action) { - return () + return } if (action.showInDrawer) { + if (!listAction) { + return ( + + + + ) + } + + const toggleFilter = listAction.showFilter + ? (): void => setFilterVisible(!filterVisible) + : undefined + return ( - - - + <> + + + + + + + + ) } return ( - {!action?.showInDrawer ? ( - - ) : ''} - + {!action?.showInDrawer ? : ''} + ) }