@@ -28,27 +28,35 @@ const SyncRecords = (): JSX.Element => {
28
28
const toast = useCustomToast();
29
29
30
30
const pageId = searchParams.get('page');
31
- const [currentPage, setCurrentPage] = useState(Number(pageId) || 1 );
31
+ const statusTab = searchParams.get('status' );
32
32
33
- const [currentFilter, setCurrentFilter] = useState<SyncRecordStatus>(SyncRecordStatus.success);
33
+ const [currentPage, setCurrentPage] = useState(Number(pageId) || 1);
34
+ const [currentStatusTab, setCurrentStatusTab] = useState<SyncRecordStatus>(
35
+ statusTab === SyncRecordStatus.failed ? SyncRecordStatus.failed : SyncRecordStatus.success,
36
+ );
34
37
35
38
const {
36
- data: syncRunRecords,
37
- isLoading: isSyncRecordsLoading,
38
- isError: isSyncRecordsError,
39
+ data: filteredSyncRunRecords,
40
+ isLoading: isFilteredSyncRecordsLoading,
41
+ isError: isFilteredSyncRecordsError,
42
+ refetch: refetchFilteredSyncRecords,
39
43
} = useQueryWrapper<ApiResponse<Array<SyncRecordResponse>>, Error>(
40
- ['activate', 'sync-records', syncRunId, currentPage],
41
- () => getSyncRecords(syncId as string, syncRunId as string, currentPage.toString()),
44
+ ['activate', 'sync-records', syncRunId, currentPage, statusTab],
45
+ () =>
46
+ getSyncRecords(
47
+ syncId as string,
48
+ syncRunId as string,
49
+ currentPage.toString(),
50
+ true,
51
+ statusTab || 'success',
52
+ ),
42
53
{
43
- refetchOnMount: true ,
54
+ refetchOnMount: false ,
44
55
refetchOnWindowFocus: false,
45
56
},
46
57
);
47
58
48
- const data = useMemo(
49
- () => syncRunRecords?.data?.filter?.((record) => record.attributes.status === currentFilter),
50
- [syncRunRecords, currentFilter],
51
- );
59
+ const data = filteredSyncRunRecords?.data;
52
60
53
61
const dynamicSyncColumns = useDynamicSyncColumns(data ? data : []);
54
62
const allColumns = useMemo(
@@ -57,11 +65,11 @@ const SyncRecords = (): JSX.Element => {
57
65
);
58
66
59
67
useEffect(() => {
60
- setSearchParams({ page: currentPage.toString() });
61
- }, [currentPage, setSearchParams]);
68
+ setSearchParams({ page: currentPage.toString(), status: currentStatusTab });
69
+ }, [currentPage, currentStatusTab, setSearchParams]);
62
70
63
71
useEffect(() => {
64
- if (isSyncRecordsError ) {
72
+ if (isFilteredSyncRecordsError ) {
65
73
toast({
66
74
title: 'Error',
67
75
description: 'There was an issue fetching the sync records.',
@@ -71,29 +79,36 @@ const SyncRecords = (): JSX.Element => {
71
79
position: 'bottom-right',
72
80
});
73
81
}
74
- }, [isSyncRecordsError , toast]);
82
+ }, [isFilteredSyncRecordsError , toast]);
75
83
76
84
const handleNextPage = () => {
77
- if (syncRunRecords ?.links?.next) {
85
+ if (filteredSyncRunRecords ?.links?.next) {
78
86
setCurrentPage((prevPage) => prevPage + 1);
79
87
}
80
88
};
81
89
82
90
const handlePrevPage = () => {
83
- if (syncRunRecords ?.links?.prev) {
91
+ if (filteredSyncRunRecords ?.links?.prev) {
84
92
setCurrentPage((prevPage) => Math.max(prevPage - 1, 1));
85
93
}
86
94
};
87
95
96
+ const handleStatusTabChange = (status: SyncRecordStatus) => {
97
+ setCurrentPage(1);
98
+ setCurrentStatusTab(status);
99
+ refetchFilteredSyncRecords;
100
+ };
101
+
88
102
return (
89
103
<ContentContainer>
90
104
{syncId && syncRunId ? <SyncRecordsTopBar syncId={syncId} syncRunId={syncRunId} /> : <></>}
91
105
<Tabs
92
106
size='md'
93
107
variant='indicator'
94
108
onChange={(index) =>
95
- setCurrentFilter (index === 0 ? SyncRecordStatus.success : SyncRecordStatus.failed)
109
+ handleStatusTabChange (index === 0 ? SyncRecordStatus.success : SyncRecordStatus.failed)
96
110
}
111
+ index={currentStatusTab === SyncRecordStatus.success ? 0 : 1}
97
112
background='gray.300'
98
113
padding='4px'
99
114
borderRadius='8px'
@@ -103,9 +118,9 @@ const SyncRecords = (): JSX.Element => {
103
118
width='fit-content'
104
119
height='fit'
105
120
>
106
- <FilterTabs setFilter={setCurrentFilter} syncRunRecords={syncRunRecords } />
121
+ <FilterTabs setFilter={handleStatusTabChange } />
107
122
</Tabs>
108
- {isSyncRecordsLoading ? (
123
+ {isFilteredSyncRecordsLoading ? (
109
124
<Loader />
110
125
) : (
111
126
<Box width='100%' pt={'20px'}>
@@ -131,8 +146,8 @@ const SyncRecords = (): JSX.Element => {
131
146
<Box display='flex' flexDirection='row-reverse' pt='10px'>
132
147
<Pagination
133
148
currentPage={currentPage}
134
- isPrevPageEnabled={syncRunRecords ?.links?.prev != null}
135
- isNextPageEnabled={syncRunRecords ?.links?.next != null}
149
+ isPrevPageEnabled={filteredSyncRunRecords ?.links?.prev != null}
150
+ isNextPageEnabled={filteredSyncRunRecords ?.links?.next != null}
136
151
handleNextPage={handleNextPage}
137
152
handlePrevPage={handlePrevPage}
138
153
/>
0 commit comments