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