Skip to content

Commit 2ac7dac

Browse files
committed
apply sorting when label is clicked and formatting
Signed-off-by: Atif Ali <atali@redhat.com>
1 parent 730c40e commit 2ac7dac

File tree

4 files changed

+90
-17
lines changed

4 files changed

+90
-17
lines changed

console-extensions.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,5 +424,31 @@
424424
"$codeRef": "ApplicationSetDetailsPage"
425425
}
426426
}
427+
},
428+
{
429+
"type": "console.page/resource/search",
430+
"properties": {
431+
"model": {
432+
"group": "argoproj.io",
433+
"version": "v1alpha1",
434+
"kind": "ApplicationSet"
435+
},
436+
"component": {
437+
"$codeRef": "ApplicationSetList"
438+
}
439+
}
440+
},
441+
{
442+
"type": "console.page/resource/search",
443+
"properties": {
444+
"model": {
445+
"group": "argoproj.io",
446+
"version": "v1alpha1",
447+
"kind": "Application"
448+
},
449+
"component": {
450+
"$codeRef": "ApplicationList"
451+
}
452+
}
427453
}
428454
]

src/gitops/components/shared/ApplicationList.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ const ApplicationList: React.FC<ApplicationProps> = ({
108108
() => COLUMNS_KEYS_INDEXES.findIndex((item) => item.key === sortBy),
109109
[COLUMNS_KEYS_INDEXES, sortBy],
110110
);
111+
112+
// Get search query from URL parameters
113+
const searchQuery = searchParams.get('q') || '';
114+
111115
const getSortParams = (columnIndex: number): ThProps['sort'] => ({
112116
sortBy: {
113117
index: sortByIndex,
@@ -124,8 +128,23 @@ const ApplicationList: React.FC<ApplicationProps> = ({
124128
const sortedApplications = React.useMemo(() => {
125129
return sortData(applications, sortBy, direction);
126130
}, [applications, sortBy, direction]);
131+
132+
// Filter by search query if present
133+
const filteredBySearch = React.useMemo(() => {
134+
if (!searchQuery) return sortedApplications;
135+
136+
return sortedApplications.filter((app) => {
137+
const labels = app.metadata?.labels || {};
138+
// Check if any label matches the search query
139+
return Object.entries(labels).some(([key, value]) => {
140+
const labelSelector = `${key}=${value}`;
141+
return labelSelector.includes(searchQuery) || key.includes(searchQuery);
142+
});
143+
});
144+
}, [sortedApplications, searchQuery]);
145+
127146
// TODO: use alternate filter since it is deprecated. See DataTableView potentially
128-
const [, filteredData, onFilterChange] = useListPageFilter(sortedApplications, filters);
147+
const [, filteredData, onFilterChange] = useListPageFilter(filteredBySearch, filters);
129148
// Filter applications by project or appset before rendering rows
130149
const filteredByOwner = React.useMemo(
131150
() => filteredData.filter(filterApp(project, appset)),

src/gitops/components/shared/ApplicationSetList.tsx

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ const ApplicationSetList: React.FC<ApplicationSetProps> = ({
133133

134134
const [searchParams, setSearchParams] = useSearchParams();
135135
const { sortBy, direction, onSort } = useDataViewSort({ searchParams, setSearchParams });
136+
137+
// Get search query from URL parameters
138+
const searchQuery = searchParams.get('q') || '';
139+
136140
const getSortParams = (columnId: string, columnIndex: number) => ({
137141
sortBy: {
138142
index: columnIndex,
@@ -149,7 +153,22 @@ const ApplicationSetList: React.FC<ApplicationSetProps> = ({
149153
const sortedApplicationSets = React.useMemo(() => {
150154
return sortData(applicationSets as ApplicationSetKind[], sortBy, direction, applications, appsLoaded);
151155
}, [applicationSets, sortBy, direction, applications, appsLoaded]);
152-
const [data, filteredData, onFilterChange] = useListPageFilter(sortedApplicationSets, filters);
156+
157+
// Filter by search query if present
158+
const filteredBySearch = React.useMemo(() => {
159+
if (!searchQuery) return sortedApplicationSets;
160+
161+
return sortedApplicationSets.filter((appSet) => {
162+
const labels = appSet.metadata?.labels || {};
163+
// Check if any label matches the search query
164+
return Object.entries(labels).some(([key, value]) => {
165+
const labelSelector = `${key}=${value}`;
166+
return labelSelector.includes(searchQuery) || key.includes(searchQuery);
167+
});
168+
});
169+
}, [sortedApplicationSets, searchQuery]);
170+
171+
const [data, filteredData, onFilterChange] = useListPageFilter(filteredBySearch, filters);
153172
const rows = useApplicationSetRowsDV(filteredData, namespace, applications, appsLoaded);
154173

155174
const empty = (
@@ -262,24 +281,32 @@ const useApplicationSetRowsDV = (applicationSetsList, namespace, applications, a
262281
: []),
263282
{
264283
id: getAppSetStatus(appSet),
284+
cell: <ApplicationSetStatusFragment status={getAppSetStatus(appSet)} />,
285+
},
286+
{
287+
id: 'generated-apps-' + index,
265288
cell: (
266289
<div>
267-
<ApplicationSetStatusFragment status={getAppSetStatus(appSet)} />
290+
{getGeneratedAppsCount(appSet, applications, appsLoaded).toString()}
268291
</div>
269292
),
270293
},
271294
{
272-
id: 'generated-apps-' + index,
273-
cell: getGeneratedAppsCount(appSet, applications, appsLoaded).toString(),
295+
id: 'generators-' + index,
296+
cell: (
297+
<div>
298+
{getAppSetGeneratorCount(appSet).toString()}
299+
</div>
300+
),
274301
},
275302
{
276-
id: 'generators-' + index,
277-
cell: getAppSetGeneratorCount(appSet).toString(),
303+
id: 'created-at-' + index,
304+
cell: (
305+
<div>
306+
{formatCreationTimestamp(appSet.metadata.creationTimestamp)}
307+
</div>
308+
),
278309
},
279-
{
280-
id: 'created-at-' + index,
281-
cell: formatCreationTimestamp(appSet.metadata.creationTimestamp),
282-
},
283310
{
284311
id: 'actions-' + index,
285312
cell: <ApplicationSetActionsCell appSet={appSet} />,
@@ -312,7 +339,7 @@ const useColumnsDV = (namespace, getSortParams) => {
312339
props: {
313340
key: 'namespace',
314341
'aria-label': 'namespace',
315-
className: 'pf-m-width-12',
342+
className: 'pf-m-width-15',
316343
sort: getSortParams('namespace', 1),
317344
},
318345
},
@@ -324,7 +351,7 @@ const useColumnsDV = (namespace, getSortParams) => {
324351
props: {
325352
key: 'status',
326353
'aria-label': 'health status',
327-
className: 'pf-m-width-12',
354+
className: 'pf-m-width-15',
328355
sort: getSortParams('status', 1 + i),
329356
},
330357
},
@@ -334,7 +361,7 @@ const useColumnsDV = (namespace, getSortParams) => {
334361
props: {
335362
key: 'generated-apps',
336363
'aria-label': 'generated apps',
337-
className: 'pf-m-width-12',
364+
className: 'pf-m-width-15',
338365
sort: getSortParams('generated-apps', 2 + i),
339366
},
340367
},
@@ -344,7 +371,7 @@ const useColumnsDV = (namespace, getSortParams) => {
344371
props: {
345372
key: 'generators',
346373
'aria-label': 'generators',
347-
className: 'pf-m-width-12',
374+
className: 'pf-m-width-15',
348375
sort: getSortParams('generators', 3 + i),
349376
},
350377
},

src/gitops/components/shared/BaseDetailsSummary/BaseDetailsSummary.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import classNames from 'classnames';
33

44
import { OwnerReferences } from '@gitops/utils/components/OwnerReferences/owner-references';
55
import { useGitOpsTranslation } from '@gitops/utils/hooks/useGitOpsTranslation';
6-
import { kindForReference, useObjectModifyPermissions } from '@gitops/utils/utils';
6+
import { kindForReference, useObjectModifyPermissions, getSelectorSearchURL } from '@gitops/utils/utils';
77
import {
88
K8sModel,
99
K8sResourceKind,
@@ -58,7 +58,8 @@ type LabelProps = {
5858
};
5959

6060
const LabelL: React.SFC<LabelProps> = ({ kind, name, value, expand }) => {
61-
const href = `/search?kind=${kind}&q=${value ? encodeURIComponent(`${name}=${value}`) : name}`;
61+
const selector = value ? `${name}=${value}` : name;
62+
const href = getSelectorSearchURL('', kind, selector);
6263
const kindOf = `co-m-${kindForReference(kind.toLowerCase())}`;
6364
const klass = classNames(kindOf, { 'co-m-expand': expand }, 'co-label');
6465
return (

0 commit comments

Comments
 (0)