1- import {
2- ArrowSquareOut ,
3- FilePlus ,
4- ShareNetwork ,
5- Binoculars ,
6- Repeat ,
7- } from '@phosphor-icons/react' ;
1+ import { Binoculars } from '@phosphor-icons/react' ;
82import clsx from 'clsx' ;
93import React from 'react' ;
10- import { generatePath , useNavigate } from 'react-router-dom' ;
114
12- import { APP_URL , DEFAULT_NETWORK_INFO } from '~constants' ;
135import { useActionSidebarContext } from '~context/ActionSidebarContext/ActionSidebarContext.ts' ;
14- import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts' ;
156import { useMobile } from '~hooks/index.ts' ;
16- import { type ActivityFeedColonyAction } from '~hooks/useActivityFeed/types.ts' ;
17- import {
18- COLONY_ACTIVITY_ROUTE ,
19- COLONY_HOME_ROUTE ,
20- TX_SEARCH_PARAM ,
21- } from '~routes' ;
22- import TransactionLink from '~shared/TransactionLink/index.ts' ;
237import { type ColonyAction } from '~types/graphql.ts' ;
24- import { formatText } from '~utils/intl.ts' ;
258import { merge } from '~utils/lodash.ts' ;
269import EmptyContent from '~v5/common/EmptyContent/index.ts' ;
2710import { MEATBALL_MENU_COLUMN_ID } from '~v5/common/Table/consts.ts' ;
2811import { type TableProps } from '~v5/common/Table/types.ts' ;
2912
3013import { useFiltersContext } from '../FiltersContext/FiltersContext.ts' ;
31- import MeatballMenuCopyItem from '../partials/MeatballMenuCopyItem/MeatballMenuCopyItem.tsx' ;
3214import { type ColonyActionsTableProps } from '../types.ts' ;
3315
3416import useActionsTableData from './useActionsTableData.ts' ;
3517import useColonyActionsTableColumns from './useColonyActionsTableColumns.tsx' ;
18+ import { useGetMenuProps } from './useGetMenuProps.tsx' ;
3619import useRenderRowLink from './useRenderRowLink.tsx' ;
3720import useRenderSubComponent from './useRenderSubComponent.tsx' ;
3821
3922export const useActionsTableProps = (
4023 props : Omit < ColonyActionsTableProps , 'withHeader' | 'actionProps' > ,
41- setAction : ( actionHash : string ) => void ,
24+ setAction : ColonyActionsTableProps [ 'actionProps' ] [ 'setSelectedAction' ] ,
4225) => {
4326 const {
4427 className,
@@ -53,8 +36,8 @@ export const useActionsTableProps = (
5336 const { searchFilter, selectedFiltersCount } = useFiltersContext ( ) ;
5437
5538 const {
56- data,
57- loading,
39+ data : colonyActions ,
40+ loading : colonyActionsLoading ,
5841 loadingMotionStates,
5942 goToNextPage,
6043 goToPreviousPage,
@@ -67,86 +50,35 @@ export const useActionsTableProps = (
6750 } = useActionsTableData ( pageSize ) ;
6851
6952 const columns = useColonyActionsTableColumns ( {
70- loading,
53+ loading : colonyActionsLoading ,
7154 loadingMotionStates,
7255 refetchMotionStates,
7356 showUserAvatar,
7457 } ) ;
7558 const {
7659 actionSidebarToggle : [ , { toggleOn : toggleActionSidebarOn } ] ,
7760 } = useActionSidebarContext ( ) ;
78- const navigate = useNavigate ( ) ;
79- const {
80- colony : { name : colonyName } ,
81- } = useColonyContext ( ) ;
82- const getMenuProps : TableProps < ActivityFeedColonyAction > [ 'getMenuProps' ] = ( {
83- original : { transactionHash } ,
84- } ) => ( {
85- disabled : loading ,
86- dropdownPlacementProps : {
87- withAutoTopPlacement : true ,
88- top : 10 ,
89- } ,
90- items : [
91- {
92- key : '1' ,
93- label : formatText ( { id : 'activityFeedTable.menu.view' } ) ,
94- icon : FilePlus ,
95- onClick : ( ) => {
96- navigate (
97- `${ window . location . pathname } ?${ TX_SEARCH_PARAM } =${ transactionHash } ` ,
98- {
99- replace : true ,
100- } ,
101- ) ;
102- } ,
103- } ,
104- {
105- key : '2' ,
106- label : (
107- < TransactionLink hash = { transactionHash } >
108- { formatText (
109- { id : 'activityFeedTable.menu.viewOnNetwork' } ,
110- {
111- blockExplorerName : DEFAULT_NETWORK_INFO . blockExplorerName ,
112- } ,
113- ) }
114- </ TransactionLink >
115- ) ,
116- icon : ArrowSquareOut ,
117- } ,
118- {
119- key : '3' ,
120- label : formatText ( { id : 'activityFeedTable.menu.share' } ) ,
121- renderItemWrapper : ( itemWrapperProps , children ) => (
122- < MeatballMenuCopyItem
123- textToCopy = { `${ APP_URL . origin } /${ generatePath ( COLONY_HOME_ROUTE , {
124- colonyName,
125- } ) } ${ COLONY_ACTIVITY_ROUTE } ?${ TX_SEARCH_PARAM } =${ transactionHash } `}
126- { ...itemWrapperProps }
127- >
128- { children }
129- </ MeatballMenuCopyItem >
130- ) ,
131- icon : ShareNetwork ,
132- onClick : ( ) => false ,
133- } ,
134- {
135- key : '4' ,
136- label : formatText ( { id : 'completedAction.redoAction' } ) ,
137- icon : Repeat ,
138- onClick : ( ) => setAction ( transactionHash ) ,
139- } ,
140- ] ,
61+
62+ const getMenuProps = useGetMenuProps ( {
63+ setAction,
64+ colonyActions,
65+ colonyActionsLoading,
14166 } ) ;
142- const isMobile = useMobile ( ) ;
143- const renderRowLink = useRenderRowLink ( loading , isRecentActivityVariant ) ;
67+
68+ const renderRowLink = useRenderRowLink (
69+ colonyActionsLoading ,
70+ isRecentActivityVariant ,
71+ ) ;
72+
14473 const renderSubComponent = useRenderSubComponent ( {
14574 loadingMotionStates,
146- loading,
75+ loading : colonyActionsLoading ,
14776 refetchMotionStates,
14877 getMenuProps,
14978 } ) ;
79+
80+ const isMobile = useMobile ( ) ;
81+
15082 const tableProps = merge (
15183 {
15284 className : clsx (
@@ -155,7 +87,8 @@ export const useActionsTableProps = (
15587 {
15688 'sm:[&_td]:h-[66px]' : isRecentActivityVariant ,
15789 'sm:[&_td]:h-[70px]' : ! isRecentActivityVariant ,
158- 'sm:[&_tr:hover]:bg-gray-25' : data . length > 0 && ! loading ,
90+ 'sm:[&_tr:hover]:bg-gray-25' :
91+ colonyActions . length > 0 && ! colonyActionsLoading ,
15992 } ,
16093 ) ,
16194 enableSortingRemoval : false ,
@@ -178,22 +111,22 @@ export const useActionsTableProps = (
178111 pageSize,
179112 } ,
180113 } ,
181- additionalPaginationButtonsContent : loading
114+ additionalPaginationButtonsContent : colonyActionsLoading
182115 ? undefined
183116 : additionalPaginationButtonsContent ,
184117 onSortingChange : setSorting ,
185118 getRowId : ( row ) => row . transactionHash ,
186119 meatBallMenuStaticSize : isRecentActivityVariant ? '2rem' : '3rem' ,
187120 getMenuProps,
188121 columns,
189- data,
122+ data : colonyActions ,
190123 manualPagination : true ,
191- canNextPage : hasNextPage || loading ,
124+ canNextPage : hasNextPage || colonyActionsLoading ,
192125 canPreviousPage : hasPrevPage ,
193126 showTotalPagesNumber,
194127 nextPage : goToNextPage ,
195128 previousPage : goToPreviousPage ,
196- paginationDisabled : loading ,
129+ paginationDisabled : colonyActionsLoading ,
197130 getRowCanExpand : ( ) => isMobile ,
198131 emptyContent : (
199132 < EmptyContent
0 commit comments