Skip to content

Commit d1273e8

Browse files
committed
fix sorting order icons && filter disappears
Signed-off-by: Atif Ali <atali@redhat.com>
1 parent ae80365 commit d1273e8

File tree

2 files changed

+47
-32
lines changed

2 files changed

+47
-32
lines changed

src/gitops/components/shared/ApplicationList.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const ApplicationList: React.FC<ApplicationProps> = ({
130130
}, [applications, sortBy, direction]);
131131

132132
// TODO: use alternate filter since it is deprecated. See DataTableView potentially
133-
const [, filteredData, onFilterChange] = useListPageFilter(sortedApplications, filters);
133+
const [data, filteredData, onFilterChange] = useListPageFilter(sortedApplications, filters);
134134

135135
// Filter applications by project or appset before rendering rows
136136
const filteredByOwner = React.useMemo(
@@ -152,6 +152,11 @@ const ApplicationList: React.FC<ApplicationProps> = ({
152152
});
153153
}, [filteredByOwner, searchQuery]);
154154
const rows = useApplicationRowsDV(filteredBySearch, namespace);
155+
156+
// Check if there are applications owned by this ApplicationSet initially (before search)
157+
const hasOwnedApplications = React.useMemo(() => {
158+
return sortedApplications.some(filterApp(project, appset));
159+
}, [sortedApplications, project, appset]);
155160
const empty = (
156161
<Tbody>
157162
<Tr key="loading" ouiaId="table-tr-loading">
@@ -200,12 +205,13 @@ const ApplicationList: React.FC<ApplicationProps> = ({
200205
</ListPageHeader>
201206
)}
202207
<ListPageBody>
203-
{!hideNameLabelFilters && (
208+
{!hideNameLabelFilters && hasOwnedApplications && (
204209
<ListPageFilter
205-
data={filteredByOwner}
210+
data={data}
206211
loaded={loaded}
207212
rowFilters={filters}
208213
onFilterChange={onFilterChange}
214+
nameFilterPlaceholder={t('plugin__gitops-plugin~Search by name...')}
209215
/>
210216
)}
211217
<DataView activeState={currentActiveState}>

src/gitops/components/shared/ApplicationSetList.tsx

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import { useDataViewSort } from '@patternfly/react-data-view/dist/dynamic/Hooks';
2424
import DataView, { DataViewState } from '@patternfly/react-data-view/dist/esm/DataView';
2525
import { CubesIcon } from '@patternfly/react-icons';
26-
import { Tbody, Td, Tr } from '@patternfly/react-table';
26+
import { Tbody, Td, ThProps, Tr } from '@patternfly/react-table';
2727

2828
import DevPreviewBadge from '../../../components/import/badges/DevPreviewBadge';
2929
import { useApplicationSetActionsProvider } from '../../hooks/useApplicationSetActionsProvider';
@@ -132,20 +132,37 @@ const ApplicationSetList: React.FC<ApplicationSetProps> = ({
132132

133133
const { t } = useTranslation('plugin__gitops-plugin');
134134

135+
const initIndex: number = namespace ? 0 : 1;
136+
const COLUMNS_KEYS_INDEXES = React.useMemo(
137+
() => [
138+
{ key: 'name', index: 0 },
139+
...(!namespace ? [{ key: 'namespace', index: 1 }] : []),
140+
{ key: 'status', index: 1 + initIndex },
141+
{ key: 'generated-apps', index: 2 + initIndex },
142+
{ key: 'generators', index: 3 + initIndex },
143+
{ key: 'created-at', index: 4 + initIndex },
144+
],
145+
[namespace, initIndex],
146+
);
147+
135148
const [searchParams, setSearchParams] = useSearchParams();
136149
const { sortBy, direction, onSort } = useDataViewSort({ searchParams, setSearchParams });
150+
const sortByIndex = React.useMemo(
151+
() => COLUMNS_KEYS_INDEXES.findIndex((item) => item.key === sortBy),
152+
[COLUMNS_KEYS_INDEXES, sortBy],
153+
);
137154

138155
// Get search query from URL parameters
139156
const searchQuery = searchParams.get('q') || '';
140157

141-
const getSortParams = (columnId: string, columnIndex: number) => ({
158+
const getSortParams = (columnIndex: number): ThProps['sort'] => ({
142159
sortBy: {
143-
index: columnIndex,
160+
index: sortByIndex,
144161
direction,
145-
defaultDirection: 'asc' as const,
162+
defaultDirection: 'asc',
146163
},
147-
onSort: (_event: any, index: number, dir: 'asc' | 'desc') => {
148-
onSort(_event, columnId, dir);
164+
onSort: (_event: any, index: number, dir) => {
165+
onSort(_event, COLUMNS_KEYS_INDEXES[index].key, dir);
149166
},
150167
columnIndex,
151168
});
@@ -179,6 +196,11 @@ const ApplicationSetList: React.FC<ApplicationSetProps> = ({
179196

180197
const rows = useApplicationSetRowsDV(filteredBySearch, namespace, applications, appsLoaded);
181198

199+
// Check if there are ApplicationSets initially (before search)
200+
const hasApplicationSets = React.useMemo(() => {
201+
return sortedApplicationSets.length > 0;
202+
}, [sortedApplicationSets]);
203+
182204
const empty = (
183205
<Tbody>
184206
<Tr key="loading" ouiaId="table-tr-loading">
@@ -246,7 +268,7 @@ const ApplicationSetList: React.FC<ApplicationSetProps> = ({
246268
</ListPageHeader>
247269
)}
248270
<ListPageBody>
249-
{!hideNameLabelFilters && (
271+
{!hideNameLabelFilters && hasApplicationSets && (
250272
<ListPageFilter
251273
data={data}
252274
loaded={loaded}
@@ -333,76 +355,63 @@ const useApplicationSetRowsDV = (
333355
return rows;
334356
};
335357

336-
const useColumnsDV = (namespace, getSortParams) => {
337-
const i: number = namespace ? 1 : 0;
358+
const useColumnsDV = (namespace, getSortParams): DataViewTh[] => {
359+
const i: number = namespace ? 0 : 1;
338360
const { t } = useTranslation('plugin__gitops-plugin');
339361
const columns: DataViewTh[] = [
340362
{
341-
id: 'name',
342363
cell: t('plugin__gitops-plugin~Name'),
343364
props: {
344-
key: 'name',
345365
'aria-label': 'name',
346-
className: 'pf-m-width-20',
347-
sort: getSortParams('name', 0),
366+
className: 'pf-m-width-25',
367+
sort: getSortParams(0),
348368
},
349369
},
350370
...(!namespace
351371
? [
352372
{
353-
id: 'namespace',
354373
cell: 'Namespace',
355374
props: {
356-
key: 'namespace',
357375
'aria-label': 'namespace',
358376
className: 'pf-m-width-15',
359-
sort: getSortParams('namespace', 1),
377+
sort: getSortParams(1),
360378
},
361379
},
362380
]
363381
: []),
364382
{
365-
id: 'status',
366383
cell: 'Health Status',
367384
props: {
368-
key: 'status',
369385
'aria-label': 'health status',
370386
className: 'pf-m-width-15',
371-
sort: getSortParams('status', 1 + i),
387+
sort: getSortParams(1 + i),
372388
},
373389
},
374390
{
375-
id: 'generated-apps',
376391
cell: 'Generated Apps',
377392
props: {
378-
key: 'generated-apps',
379393
'aria-label': 'generated apps',
380394
className: 'pf-m-width-15',
381-
sort: getSortParams('generated-apps', 2 + i),
395+
sort: getSortParams(2 + i),
382396
},
383397
},
384398
{
385-
id: 'generators',
386399
cell: 'Generators',
387400
props: {
388-
key: 'generators',
389401
'aria-label': 'generators',
390402
className: 'pf-m-width-15',
391-
sort: getSortParams('generators', 3 + i),
403+
sort: getSortParams(3 + i),
392404
},
393405
},
394406
{
395-
id: 'created-at',
396407
cell: 'Created At',
397408
props: {
398-
key: 'created-at',
399409
'aria-label': 'created at',
400410
className: 'pf-m-width-15',
401-
sort: getSortParams('created-at', 4 + i),
411+
sort: getSortParams(4 + i),
402412
},
403413
},
404414
{
405-
id: 'actions',
406415
cell: '',
407416
props: { 'aria-label': 'actions' },
408417
},

0 commit comments

Comments
 (0)