Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 190a977

Browse files
committedNov 18, 2023
used by depenendencies - use HubListToolbar
mostly because the onChange-based filter would really need a cancel token, but we want unified filters everywhere too
1 parent 0a7c843 commit 190a977

File tree

2 files changed

+30
-68
lines changed

2 files changed

+30
-68
lines changed
 

‎src/components/collection-dependencies-list/collection-usedby-dependencies-list.tsx

+26-55
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import { t } from '@lingui/macro';
2-
import {
3-
SearchInput,
4-
Toolbar,
5-
ToolbarGroup,
6-
ToolbarItem,
7-
} from '@patternfly/react-core';
82
import React from 'react';
93
import { Link } from 'react-router-dom';
104
import { CollectionUsedByDependencies } from 'src/api';
115
import {
126
EmptyStateFilter,
137
EmptyStateNoData,
8+
HubListToolbar,
149
LoadingPageSpinner,
1510
Pagination,
16-
Sort,
1711
} from 'src/components';
1812
import 'src/containers/collection-detail/collection-dependencies.scss';
1913
import { Paths, formatPath } from 'src/paths';
@@ -40,8 +34,6 @@ export const CollectionUsedbyDependenciesList = ({
4034
updateParams,
4135
usedByDependenciesLoading,
4236
}: IProps) => {
43-
const ignoredParams = ['page_size', 'page', 'sort', 'name__icontains'];
44-
4537
if (!itemCount && !filterIsSet(params, ['name__icontains'])) {
4638
return (
4739
<EmptyStateNoData
@@ -51,50 +43,29 @@ export const CollectionUsedbyDependenciesList = ({
5143
);
5244
}
5345

46+
const ignoredParams = ['page_size', 'page', 'sort'];
47+
48+
const filterConfig = [
49+
{
50+
id: 'name__icontains',
51+
title: t`Name`,
52+
},
53+
];
54+
55+
const sortOptions = [
56+
{ title: t`Collection`, id: 'collection', type: 'alpha' },
57+
];
58+
5459
return (
5560
<>
56-
<div className='hub-toolbar'>
57-
<Toolbar>
58-
<ToolbarGroup>
59-
<ToolbarItem>
60-
<SearchInput
61-
value={params.name__icontains || ''}
62-
onChange={(_e, val) =>
63-
updateParams(
64-
ParamHelper.setParam(params, 'name__icontains', val),
65-
)
66-
}
67-
onClear={() =>
68-
updateParams(
69-
ParamHelper.setParam(params, 'name__icontains', ''),
70-
)
71-
}
72-
aria-label='filter-collection-name'
73-
placeholder={t`Filter by name`}
74-
/>
75-
</ToolbarItem>
76-
<ToolbarItem>
77-
<Sort
78-
options={[
79-
{ title: t`Collection`, id: 'collection', type: 'alpha' },
80-
]}
81-
params={params}
82-
updateParams={({ sort }) =>
83-
updateParams(ParamHelper.setParam(params, 'sort', sort))
84-
}
85-
/>
86-
</ToolbarItem>
87-
</ToolbarGroup>
88-
</Toolbar>
89-
{!!itemCount && (
90-
<Pagination
91-
params={params}
92-
updateParams={(p) => updateParams(p)}
93-
count={itemCount}
94-
isTop
95-
/>
96-
)}
97-
</div>
61+
<HubListToolbar
62+
count={itemCount}
63+
filterConfig={filterConfig}
64+
ignoredParams={ignoredParams}
65+
params={params}
66+
sortOptions={sortOptions}
67+
updateParams={updateParams}
68+
/>
9869

9970
{usedByDependenciesLoading ? (
10071
<LoadingPageSpinner />
@@ -118,10 +89,10 @@ export const CollectionUsedbyDependenciesList = ({
11889
namespace,
11990
repo: repository_list[0],
12091
},
121-
ParamHelper.getReduced(
122-
{ version },
123-
ignoredParams,
124-
),
92+
ParamHelper.getReduced({ version }, [
93+
...ignoredParams,
94+
'name__icontains',
95+
]),
12596
)}
12697
>
12798
{namespace + '.' + name} v{version}

‎src/containers/collection-detail/collection-dependencies.tsx

+4-13
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class CollectionDependencies extends React.Component<RouteProps, IState> {
115115
const noDependencies = !Object.keys(version.dependencies).length;
116116

117117
return (
118-
<React.Fragment>
118+
<>
119119
<AlertList alerts={alerts} closeAlert={(i) => this.closeAlert(i)} />
120120
<CollectionHeader
121121
activeTab='dependencies'
@@ -129,9 +129,7 @@ class CollectionDependencies extends React.Component<RouteProps, IState> {
129129
reload={() => this.loadData(true)}
130130
repo={repository.name}
131131
updateParams={(p) => {
132-
this.updateParams(this.combineParams(this.state.params, p), () =>
133-
this.loadData(true),
134-
);
132+
this.updateParams(p, () => this.loadData(true));
135133
}}
136134
/>
137135
<Main>
@@ -160,15 +158,12 @@ class CollectionDependencies extends React.Component<RouteProps, IState> {
160158
params={dependenciesParams}
161159
usedByDependenciesLoading={usedByDependenciesLoading}
162160
updateParams={(p) =>
163-
this.updateParams(
164-
this.combineParams(this.state.params, p),
165-
() => this.loadUsedByDependencies(),
166-
)
161+
this.updateParams(p, () => this.loadUsedByDependencies())
167162
}
168163
/>
169164
</section>
170165
</Main>
171-
</React.Fragment>
166+
</>
172167
);
173168
}
174169

@@ -298,10 +293,6 @@ class CollectionDependencies extends React.Component<RouteProps, IState> {
298293
return ParamHelper.updateParamsMixin();
299294
}
300295

301-
private combineParams(...params) {
302-
return params.reduce((acc, cur) => ({ ...acc, ...cur }));
303-
}
304-
305296
get closeAlert() {
306297
return closeAlertMixin('alerts');
307298
}

0 commit comments

Comments
 (0)
Please sign in to comment.