@@ -22,7 +22,6 @@ import { WfoAdvancedTableColumnConfig } from '@/components/WfoTable/WfoAdvancedT
22
22
import { ColumnType } from '@/components/WfoTable/WfoTable' ;
23
23
import { mapSortableAndFilterableValuesToTableColumnConfig } from '@/components/WfoTable/WfoTable/utils' ;
24
24
import { DataDisplayParams , useShowToastMessage } from '@/hooks' ;
25
- import { UseQuery } from '@/rtk' ;
26
25
import {
27
26
SubscriptionListResponse ,
28
27
useGetSubscriptionListQuery ,
@@ -78,6 +77,26 @@ export const WfoSubscriptionsList: FC<WfoSubscriptionsListProps> = ({
78
77
const tError = useTranslations ( 'errors' ) ;
79
78
const { showToastMessage } = useShowToastMessage ( ) ;
80
79
80
+ const { sortBy, queryString, pageIndex, pageSize } = dataDisplayParams ;
81
+
82
+ const graphqlQueryVariables : GraphqlQueryVariables < SubscriptionListItem > = {
83
+ first : pageSize ,
84
+ after : pageIndex * pageSize ,
85
+ sortBy,
86
+ filterBy : alwaysOnFilters ,
87
+ query : queryString || undefined ,
88
+ } ;
89
+
90
+ const {
91
+ data,
92
+ isFetching,
93
+ error,
94
+ endpointName = '' ,
95
+ } = useGetSubscriptionListQuery ( graphqlQueryVariables ) ;
96
+
97
+ const subscriptionList =
98
+ mapGraphQlSubscriptionsResultToSubscriptionListItems ( data ) ;
99
+
81
100
const tableColumnConfig : WfoAdvancedTableColumnConfig < SubscriptionListItem > =
82
101
{
83
102
subscriptionId : {
@@ -155,15 +174,11 @@ export const WfoSubscriptionsList: FC<WfoSubscriptionsListProps> = ({
155
174
renderData : ( cellValue , row ) => {
156
175
return (
157
176
< WfoSubscriptionNoteEdit
158
- queryVariables = { graphqlQueryVariables }
159
177
subscriptionId = { row . subscriptionId }
160
178
onlyShowOnHover = { true }
161
- useQuery = {
162
- useGetSubscriptionListQuery as UseQuery <
163
- SubscriptionListResponse ,
164
- Subscription
165
- >
166
- }
179
+ endpointName = { endpointName }
180
+ queryVariables = { graphqlQueryVariables }
181
+ data = { subscriptionList }
167
182
/>
168
183
) ;
169
184
} ,
@@ -182,19 +197,6 @@ export const WfoSubscriptionsList: FC<WfoSubscriptionsListProps> = ({
182
197
} ,
183
198
} ;
184
199
185
- const { sortBy, queryString, pageIndex, pageSize } = dataDisplayParams ;
186
-
187
- const graphqlQueryVariables : GraphqlQueryVariables < SubscriptionListItem > = {
188
- first : pageSize ,
189
- after : pageIndex * pageSize ,
190
- sortBy,
191
- filterBy : alwaysOnFilters ,
192
- query : queryString || undefined ,
193
- } ;
194
-
195
- const { data, isFetching, error } = useGetSubscriptionListQuery (
196
- graphqlQueryVariables ,
197
- ) ;
198
200
const [ getSubscriptionListTrigger , { isFetching : isFetchingCsv } ] =
199
201
useLazyGetSubscriptionListQuery ( ) ;
200
202
const getSubscriptionListForExport = ( ) =>
@@ -217,54 +219,55 @@ export const WfoSubscriptionsList: FC<WfoSubscriptionsListProps> = ({
217
219
} ;
218
220
const { totalItems, sortFields, filterFields } = data ?. pageInfo ?? { } ;
219
221
222
+ const pageChange =
223
+ getPageIndexChangeHandler < SubscriptionListItem > ( setDataDisplayParam ) ;
224
+ const pageSizeChange =
225
+ getPageSizeChangeHandler < SubscriptionListItem > ( setDataDisplayParam ) ;
226
+ const updateQuery =
227
+ getQueryStringHandler < SubscriptionListItem > ( setDataDisplayParam ) ;
228
+ const updateSorting =
229
+ getDataSortHandler < SubscriptionListItem > ( setDataDisplayParam ) ;
230
+
220
231
const pagination : Pagination = {
221
232
pageIndex : dataDisplayParams . pageIndex ,
222
233
pageSize : dataDisplayParams . pageSize ,
223
234
pageSizeOptions : DEFAULT_PAGE_SIZES ,
224
235
totalItemCount : totalItems ?? 0 ,
225
- onChangePage :
226
- getPageIndexChangeHandler < SubscriptionListItem > (
227
- setDataDisplayParam ,
228
- ) ,
229
- onChangeItemsPerPage :
230
- getPageSizeChangeHandler < SubscriptionListItem > ( setDataDisplayParam ) ,
236
+ onChangePage : pageChange ,
237
+ onChangeItemsPerPage : pageSizeChange ,
231
238
} ;
232
239
240
+ const exportData = csvDownloadHandler (
241
+ getSubscriptionListForExport ,
242
+ mapGraphQlSubscriptionsResultToSubscriptionListItems ,
243
+ mapGraphQlSubscriptionsResultToPageInfo ,
244
+ Object . keys ( tableColumnConfig ) ,
245
+ getCsvFileNameWithDate ( 'Subscriptions' ) ,
246
+ showToastMessage ,
247
+ tError ,
248
+ ) ;
249
+
250
+ const mapTableConfig = mapSortableAndFilterableValuesToTableColumnConfig (
251
+ tableColumnConfig ,
252
+ sortFields ,
253
+ filterFields ,
254
+ ) ;
255
+
233
256
return (
234
257
< WfoAdvancedTable
235
258
queryString = { dataDisplayParams . queryString }
236
- onUpdateQueryString = { getQueryStringHandler < SubscriptionListItem > (
237
- setDataDisplayParam ,
238
- ) }
239
- data = {
240
- data
241
- ? mapGraphQlSubscriptionsResultToSubscriptionListItems ( data )
242
- : [ ]
243
- }
244
- tableColumnConfig = { mapSortableAndFilterableValuesToTableColumnConfig (
245
- tableColumnConfig ,
246
- sortFields ,
247
- filterFields ,
248
- ) }
259
+ onUpdateQueryString = { updateQuery }
260
+ data = { subscriptionList }
261
+ tableColumnConfig = { mapTableConfig }
249
262
defaultHiddenColumns = { hiddenColumns }
250
263
dataSorting = { [ dataSorting ] }
251
264
isLoading = { isFetching }
252
265
localStorageKey = { SUBSCRIPTIONS_TABLE_LOCAL_STORAGE_KEY }
253
266
detailModalTitle = { 'Details - Subscription' }
254
267
pagination = { pagination }
255
268
error = { mapRtkErrorToWfoError ( error ) }
256
- onUpdateDataSorting = { getDataSortHandler < SubscriptionListItem > (
257
- setDataDisplayParam ,
258
- ) }
259
- onExportData = { csvDownloadHandler (
260
- getSubscriptionListForExport ,
261
- mapGraphQlSubscriptionsResultToSubscriptionListItems ,
262
- mapGraphQlSubscriptionsResultToPageInfo ,
263
- Object . keys ( tableColumnConfig ) ,
264
- getCsvFileNameWithDate ( 'Subscriptions' ) ,
265
- showToastMessage ,
266
- tError ,
267
- ) }
269
+ onUpdateDataSorting = { updateSorting }
270
+ onExportData = { exportData }
268
271
exportDataIsLoading = { isFetchingCsv }
269
272
/>
270
273
) ;
0 commit comments