Skip to content

Commit ff3f476

Browse files
authored
Merge pull request #272 from aali309/pagination-release-4.18
Add Pagination in release branch 4.18
2 parents 2ab6506 + c8494d0 commit ff3f476

18 files changed

Lines changed: 994 additions & 119 deletions

‎locales/en/plugin__gitops-plugin.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,13 @@
352352
"You don't have permission to perform this action": "You don't have permission to perform this action",
353353
"annotations": "annotations",
354354
"annotation": "annotation",
355-
"No owner": "No owner"
355+
"No owner": "No owner",
356+
"Pagination": "Pagination",
357+
"Go to first page": "Go to first page",
358+
"Go to previous page": "Go to previous page",
359+
"Go to next page": "Go to next page",
360+
"Go to last page": "Go to last page",
361+
"Items per page": "Items per page",
362+
"per page": "per page",
363+
"of": "of"
356364
}

‎locales/ja/plugin__gitops-plugin.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,13 @@
352352
"You don't have permission to perform this action": "You don't have permission to perform this action",
353353
"annotations": "annotations",
354354
"annotation": "annotation",
355-
"No owner": "No owner"
355+
"No owner": "No owner",
356+
"Pagination": "Pagination",
357+
"Go to first page": "Go to first page",
358+
"Go to previous page": "Go to previous page",
359+
"Go to next page": "Go to next page",
360+
"Go to last page": "Go to last page",
361+
"Items per page": "Items per page",
362+
"per page": "per page",
363+
"of": "of"
356364
}

‎locales/ko/plugin__gitops-plugin.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,13 @@
352352
"You don't have permission to perform this action": "You don't have permission to perform this action",
353353
"annotations": "annotations",
354354
"annotation": "annotation",
355-
"No owner": "No owner"
355+
"No owner": "No owner",
356+
"Pagination": "Pagination",
357+
"Go to first page": "Go to first page",
358+
"Go to previous page": "Go to previous page",
359+
"Go to next page": "Go to next page",
360+
"Go to last page": "Go to last page",
361+
"Items per page": "Items per page",
362+
"per page": "per page",
363+
"of": "of"
356364
}

‎locales/zh/plugin__gitops-plugin.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,13 @@
352352
"You don't have permission to perform this action": "You don't have permission to perform this action",
353353
"annotations": "annotations",
354354
"annotation": "annotation",
355-
"No owner": "No owner"
355+
"No owner": "No owner",
356+
"Pagination": "Pagination",
357+
"Go to first page": "Go to first page",
358+
"Go to previous page": "Go to previous page",
359+
"Go to next page": "Go to next page",
360+
"Go to last page": "Go to last page",
361+
"Items per page": "Items per page",
362+
"per page": "per page",
363+
"of": "of"
356364
}

‎src/gitops/components/imageupdater/ImageUpdaterList.tsx‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ import {
3838
ShowOperandsInAllNamespacesRadioGroup,
3939
useShowOperandsInAllNamespaces,
4040
} from '../shared/AllNamespaces';
41-
import { GitOpsDataViewTable, useGitOpsDataViewSort } from '../shared/DataView';
41+
import {
42+
GitOpsDataViewTable,
43+
useGitOpsDataViewSort,
44+
useGitOpsListPagePagination,
45+
} from '../shared/DataView';
46+
import { filterByConsoleNameAndLabels, parseLabelFilterParam } from '../shared/listPageTextFilters';
4247
import MetadataLabels from '../shared/MetadataLabels';
4348

4449
import { useImageUpdaterActionsProvider } from './hooks/useImageUpdaterActionsProvider';
@@ -87,6 +92,8 @@ const ImageUpdaterList: React.FC<ImageUpdaterListTabProps> = ({
8792

8893
// Get search query from URL parameters
8994
const searchQuery = searchParams.get('q') || '';
95+
const nameQuery = searchParams.get('name') || '';
96+
const labelsParam = searchParams.get('labels') || '';
9097

9198
const { t } = useTranslation('plugin__gitops-plugin');
9299

@@ -98,11 +105,16 @@ const ImageUpdaterList: React.FC<ImageUpdaterListTabProps> = ({
98105
const filters = getFilters(t);
99106
const [data, filteredData, onFilterChange] = useListPageFilter(sortedItems, filters);
100107

108+
const filteredByNameAndLabels = React.useMemo(
109+
() => filterByConsoleNameAndLabels(filteredData, nameQuery, parseLabelFilterParam(labelsParam)),
110+
[filteredData, nameQuery, labelsParam],
111+
);
112+
101113
const filteredBySearch = React.useMemo(() => {
102-
if (!searchQuery) return filteredData;
114+
if (!searchQuery) return filteredByNameAndLabels;
103115

104116
const lowerQuery = searchQuery.toLowerCase();
105-
return filteredData.filter((item) => {
117+
return filteredByNameAndLabels.filter((item) => {
106118
const name = item.metadata?.name || '';
107119
const labels = item.metadata?.labels || {};
108120
return (
@@ -116,9 +128,14 @@ const ImageUpdaterList: React.FC<ImageUpdaterListTabProps> = ({
116128
})
117129
);
118130
});
119-
}, [filteredData, searchQuery]);
131+
}, [filteredByNameAndLabels, searchQuery]);
120132

121-
const rows = useImageUpdaterRowsDV(filteredBySearch as ImageUpdaterKind[], effectiveNamespace);
133+
const { pagination, pagedItems, itemCount } = useGitOpsListPagePagination({
134+
items: filteredBySearch as ImageUpdaterKind[],
135+
namespace: effectiveNamespace,
136+
searchParams,
137+
});
138+
const rows = useImageUpdaterRowsDV(pagedItems, effectiveNamespace);
122139

123140
const hasItems = React.useMemo(() => {
124141
return sortedItems.length > 0;
@@ -207,6 +224,8 @@ const ImageUpdaterList: React.FC<ImageUpdaterListTabProps> = ({
207224
emptyState={empty}
208225
isError={!!loadError}
209226
errorState={error || undefined}
227+
itemCount={itemCount}
228+
pagination={pagination}
210229
/>
211230
</ListPageBody>
212231
</div>

‎src/gitops/components/project/ProjectList.tsx‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ import {
3636
ShowOperandsInAllNamespacesRadioGroup,
3737
useShowOperandsInAllNamespaces,
3838
} from '../shared/AllNamespaces';
39-
import { GitOpsDataViewTable, useGitOpsDataViewSort } from '../shared/DataView';
39+
import {
40+
GitOpsDataViewTable,
41+
useGitOpsDataViewSort,
42+
useGitOpsListPagePagination,
43+
} from '../shared/DataView';
44+
import { filterByConsoleNameAndLabels, parseLabelFilterParam } from '../shared/listPageTextFilters';
4045
import { MetadataLabels } from '../shared/MetadataLabels/MetadataLabels';
4146

4247
import { useProjectActionsProvider } from './hooks/useProjectActionsProvider';
@@ -101,6 +106,8 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
101106

102107
// Get search query from URL parameters
103108
const searchQuery = searchParams.get('q') || '';
109+
const nameQuery = searchParams.get('name') || '';
110+
const labelsParam = searchParams.get('labels') || '';
104111

105112
const { t } = useTranslation('plugin__gitops-plugin');
106113

@@ -112,11 +119,16 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
112119
const filters = getFilters(t, applications, appsLoaded);
113120
const [data, filteredData, onFilterChange] = useListPageFilter(sortedProjects, filters);
114121

122+
const filteredByNameAndLabels = React.useMemo(
123+
() => filterByConsoleNameAndLabels(filteredData, nameQuery, parseLabelFilterParam(labelsParam)),
124+
[filteredData, nameQuery, labelsParam],
125+
);
126+
115127
// Filter by search query if present (after other filters)
116128
const filteredBySearch = React.useMemo(() => {
117-
if (!searchQuery) return filteredData;
129+
if (!searchQuery) return filteredByNameAndLabels;
118130

119-
return filteredData.filter((project) => {
131+
return filteredByNameAndLabels.filter((project) => {
120132
const name = project.metadata?.name || '';
121133
const description = project.spec?.description || '';
122134
const labels = project.metadata?.labels || {};
@@ -136,9 +148,14 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
136148
})
137149
);
138150
});
139-
}, [filteredData, searchQuery]);
151+
}, [filteredByNameAndLabels, searchQuery]);
140152

141-
const rows = useProjectsRowsDV(filteredBySearch, namespace, applications, appsLoaded);
153+
const { pagination, pagedItems, itemCount } = useGitOpsListPagePagination({
154+
items: filteredBySearch,
155+
namespace,
156+
searchParams,
157+
});
158+
const rows = useProjectsRowsDV(pagedItems, namespace, applications, appsLoaded);
142159
const showNamespaceColumn = !namespace || namespace === '';
143160

144161
// Check if there are projects initially (before search)
@@ -236,6 +253,8 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
236253
emptyState={empty}
237254
isError={!!loadError}
238255
errorState={error || undefined}
256+
itemCount={itemCount}
257+
pagination={pagination}
239258
/>
240259
</div>
241260
</ListPageBody>

‎src/gitops/components/rollout/RolloutList.tsx‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ import {
3636
ShowOperandsInAllNamespacesRadioGroup,
3737
useShowOperandsInAllNamespaces,
3838
} from '../shared/AllNamespaces';
39-
import { GitOpsDataViewTable, useGitOpsDataViewSort } from '../shared/DataView';
39+
import {
40+
GitOpsDataViewTable,
41+
useGitOpsDataViewSort,
42+
useGitOpsListPagePagination,
43+
} from '../shared/DataView';
44+
import {
45+
filterByConsoleNameAndLabels,
46+
filterResourcesByLabelQuery,
47+
parseLabelFilterParam,
48+
} from '../shared/listPageTextFilters';
4049
import { MetadataLabels } from '../shared/MetadataLabels/MetadataLabels';
4150

4251
import { useRolloutActionsProvider } from './hooks/useRolloutActionsProvider';
@@ -112,6 +121,8 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
112121

113122
// Get search query from URL parameters
114123
const searchQuery = searchParams.get('q') || '';
124+
const nameQuery = searchParams.get('name') || '';
125+
const labelsParam = searchParams.get('labels') || '';
115126

116127
const { t } = useGitOpsTranslation();
117128

@@ -123,22 +134,22 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
123134
const filters = getFilters(t);
124135
const [data, filteredData, onFilterChange] = useListPageFilter(sortedRollouts, filters);
125136

126-
// TODO: use alternate filter since it is deprecated. See DataTableView potentially
127-
// Filter by search query if present (after other filters)
128-
const filteredBySearch = React.useMemo(() => {
129-
if (!searchQuery) return filteredData;
137+
const filteredByNameAndLabels = React.useMemo(
138+
() => filterByConsoleNameAndLabels(filteredData, nameQuery, parseLabelFilterParam(labelsParam)),
139+
[filteredData, nameQuery, labelsParam],
140+
);
130141

131-
return filteredData.filter((app) => {
132-
const labels = app.metadata?.labels || {};
133-
// Check if any label matches the search query
134-
return Object.entries(labels).some(([key, value]) => {
135-
const labelSelector = `${key}=${value}`;
136-
return labelSelector.includes(searchQuery) || key.includes(searchQuery);
137-
});
138-
});
139-
}, [filteredData, searchQuery]);
142+
const filteredBySearch = React.useMemo(
143+
() => filterResourcesByLabelQuery(filteredByNameAndLabels, searchQuery),
144+
[filteredByNameAndLabels, searchQuery],
145+
);
140146

141-
const rows = useRolloutsRowsDV(filteredBySearch, namespace, t);
147+
const { pagination, pagedItems, itemCount } = useGitOpsListPagePagination({
148+
items: filteredBySearch,
149+
namespace,
150+
searchParams,
151+
});
152+
const rows = useRolloutsRowsDV(pagedItems, namespace, t);
142153

143154
const empty = (
144155
<Tbody>
@@ -206,7 +217,7 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
206217
onFilterChange={onFilterChange}
207218
/>
208219
</span>
209-
{rows.length > 0 && !loadError && (
220+
{filteredBySearch.length > 0 && !loadError && (
210221
<span className="rollout-list-page__topology-link pf-m-mb-sm">
211222
{topologyLink(topologyUrl, t)}
212223
</span>
@@ -220,6 +231,8 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
220231
emptyState={empty}
221232
isError={!!loadError}
222233
errorState={error || undefined}
234+
itemCount={itemCount}
235+
pagination={pagination}
223236
/>
224237
</ListPageBody>
225238
</>

0 commit comments

Comments
 (0)