Skip to content

Commit 40e87b8

Browse files
fix(storage): keep separate search for groups and nodes
1 parent 44dd3b4 commit 40e87b8

File tree

8 files changed

+53
-27
lines changed

8 files changed

+53
-27
lines changed

src/containers/Storage/PaginatedStorageGroups/GroupedStorageGroupsComponent.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function GroupedStorageGroupsComponent({
9696
viewContext,
9797
}: PaginatedStorageProps) {
9898
const [autoRefreshInterval] = useAutoRefreshInterval();
99-
const {searchValue, storageGroupsGroupByParam, visibleEntities, handleShowAllGroups} =
99+
const {groupsSearchValue, storageGroupsGroupByParam, visibleEntities, handleShowAllGroups} =
100100
useStorageQueryParams();
101101

102102
const {columnsToShow, columnsToSelect, setColumns} = useStorageGroupsSelectedColumns({
@@ -111,7 +111,7 @@ export function GroupedStorageGroupsComponent({
111111
nodeId,
112112
groupId,
113113
pDiskId,
114-
filter: searchValue,
114+
filter: groupsSearchValue,
115115
shouldUseGroupsHandler: true,
116116
group: storageGroupsGroupByParam,
117117
},
@@ -152,7 +152,7 @@ export function GroupedStorageGroupsComponent({
152152
groupId={groupId}
153153
pDiskId={pDiskId}
154154
filterGroupBy={storageGroupsGroupByParam}
155-
searchValue={searchValue}
155+
searchValue={groupsSearchValue}
156156
visibleEntities={'all'}
157157
scrollContainerRef={scrollContainerRef}
158158
onIsExpandedChange={setIsGroupExpanded}
@@ -190,7 +190,7 @@ export function GroupedStorageGroupsComponent({
190190
initialState={initialState}
191191
tableWrapperProps={{
192192
scrollContainerRef,
193-
scrollDependencies: [searchValue, storageGroupsGroupByParam, tableGroups],
193+
scrollDependencies: [groupsSearchValue, storageGroupsGroupByParam, tableGroups],
194194
loading: isLoading,
195195
className: b('groups-wrapper'),
196196
}}

src/containers/Storage/PaginatedStorageGroups/StorageGroupsComponent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function StorageGroupsComponent({
1818
scrollContainerRef,
1919
initialEntitiesCount,
2020
}: PaginatedStorageProps) {
21-
const {searchValue, visibleEntities, handleShowAllGroups} = useStorageQueryParams();
21+
const {groupsSearchValue, visibleEntities, handleShowAllGroups} = useStorageQueryParams();
2222

2323
const storageGroupsHandlerHasGrouping = useStorageGroupsHandlerHasGrouping();
2424

@@ -49,7 +49,7 @@ export function StorageGroupsComponent({
4949
nodeId={nodeId}
5050
groupId={groupId}
5151
pDiskId={pDiskId}
52-
searchValue={searchValue}
52+
searchValue={groupsSearchValue}
5353
visibleEntities={visibleEntities}
5454
onShowAll={handleShowAllGroups}
5555
scrollContainerRef={scrollContainerRef}
@@ -60,7 +60,7 @@ export function StorageGroupsComponent({
6060
}
6161
tableWrapperProps={{
6262
scrollContainerRef,
63-
scrollDependencies: [searchValue, visibleEntities],
63+
scrollDependencies: [groupsSearchValue, visibleEntities],
6464
}}
6565
/>
6666
);

src/containers/Storage/PaginatedStorageGroups/StorageGroupsControls.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export function StorageGroupsControls({
3232
entitiesLoading,
3333
}: StorageControlsProps) {
3434
const {
35-
searchValue,
35+
groupsSearchValue,
3636
storageType,
3737
visibleEntities,
3838
storageGroupsGroupByParam,
39-
handleTextFilterChange,
39+
handleTextFilterGroupsChange,
4040
handleStorageTypeChange,
4141
handleVisibleEntitiesChange,
4242
handleStorageGroupsGroupByParamChange,
@@ -60,8 +60,8 @@ export function StorageGroupsControls({
6060
return (
6161
<React.Fragment>
6262
<Search
63-
value={searchValue}
64-
onChange={handleTextFilterChange}
63+
value={groupsSearchValue}
64+
onChange={handleTextFilterGroupsChange}
6565
placeholder={i18n('controls_groups-search-placeholder')}
6666
className={b('search')}
6767
/>

src/containers/Storage/PaginatedStorageNodes/GroupedStorageNodesComponent.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ export function GroupedStorageNodesComponent({
9898
}: PaginatedStorageProps) {
9999
const [autoRefreshInterval] = useAutoRefreshInterval();
100100

101-
const {searchValue, storageNodesGroupByParam, handleShowAllNodes} = useStorageQueryParams();
101+
const {nodesSearchValue, storageNodesGroupByParam, handleShowAllNodes} =
102+
useStorageQueryParams();
102103

103104
const {handleDataFetched, columnsSettings} = useStorageColumnsSettings();
104105
const {columnsToShow, columnsToSelect, setColumns} = useStorageNodesColumnsToSelect({
@@ -111,7 +112,7 @@ export function GroupedStorageNodesComponent({
111112
{
112113
database,
113114
with: 'all',
114-
filter: searchValue,
115+
filter: nodesSearchValue,
115116
node_id: nodeId,
116117
group_id: groupId,
117118
group: storageNodesGroupByParam,
@@ -151,7 +152,7 @@ export function GroupedStorageNodesComponent({
151152
database={database}
152153
nodeId={nodeId}
153154
groupId={groupId}
154-
searchValue={searchValue}
155+
searchValue={nodesSearchValue}
155156
visibleEntities="all"
156157
filterGroupBy={storageNodesGroupByParam}
157158
scrollContainerRef={scrollContainerRef}
@@ -191,7 +192,7 @@ export function GroupedStorageNodesComponent({
191192
initialState={initialState}
192193
tableWrapperProps={{
193194
scrollContainerRef,
194-
scrollDependencies: [searchValue, storageNodesGroupByParam, tableGroups],
195+
scrollDependencies: [nodesSearchValue, storageNodesGroupByParam, tableGroups],
195196
loading: isLoading,
196197
className: b('groups-wrapper'),
197198
}}

src/containers/Storage/PaginatedStorageNodes/StorageNodesComponent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function StorageNodesComponent({
1818
scrollContainerRef,
1919
initialEntitiesCount,
2020
}: PaginatedStorageProps) {
21-
const {searchValue, visibleEntities, nodesUptimeFilter, handleShowAllNodes} =
21+
const {nodesSearchValue, visibleEntities, nodesUptimeFilter, handleShowAllNodes} =
2222
useStorageQueryParams();
2323

2424
const viewerNodesHandlerHasGrouping = useViewerNodesHandlerHasGrouping();
@@ -52,7 +52,7 @@ export function StorageNodesComponent({
5252
database={database}
5353
nodeId={nodeId}
5454
groupId={groupId}
55-
searchValue={searchValue}
55+
searchValue={nodesSearchValue}
5656
visibleEntities={visibleEntities}
5757
nodesUptimeFilter={nodesUptimeFilter}
5858
onShowAll={handleShowAllNodes}
@@ -65,7 +65,7 @@ export function StorageNodesComponent({
6565
}
6666
tableWrapperProps={{
6767
scrollContainerRef,
68-
scrollDependencies: [searchValue, visibleEntities, nodesUptimeFilter],
68+
scrollDependencies: [nodesSearchValue, visibleEntities, nodesUptimeFilter],
6969
}}
7070
/>
7171
);

src/containers/Storage/PaginatedStorageNodes/StorageNodesControls.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export function StorageNodesControls({
3131
entitiesLoading,
3232
}: StorageControlsProps) {
3333
const {
34-
searchValue,
34+
nodesSearchValue,
3535
storageType,
3636
visibleEntities,
3737
nodesUptimeFilter,
3838
storageNodesGroupByParam,
39-
handleTextFilterChange,
39+
handleTextFilterNodesChange,
4040
handleStorageTypeChange,
4141
handleVisibleEntitiesChange,
4242
handleUptimeFilterChange,
@@ -50,8 +50,8 @@ export function StorageNodesControls({
5050
return (
5151
<React.Fragment>
5252
<Search
53-
value={searchValue}
54-
onChange={handleTextFilterChange}
53+
value={nodesSearchValue}
54+
onChange={handleTextFilterNodesChange}
5555
placeholder={i18n('controls_nodes-search-placeholder')}
5656
className={b('search')}
5757
/>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const STORAGE_SEARCH_PARAM_BY_TYPE: Record<string, string> = {
2+
groups: 'groupsSearch',
3+
nodes: 'nodesSearch',
4+
};

src/containers/Storage/useStorageQueryParams.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {useEffect} from 'react';
2+
13
import {StringParam, useQueryParams} from 'use-query-params';
24

35
import type {StorageType, VisibleEntities} from '../../store/reducers/storage/types';
@@ -6,11 +8,14 @@ import {NodesUptimeFilterValues, nodesUptimeFilterValuesSchema} from '../../util
68

79
import {storageGroupsGroupByParamSchema} from './PaginatedStorageGroupsTable/columns/constants';
810
import {storageNodesGroupByParamSchema} from './PaginatedStorageNodesTable/columns/constants';
11+
import {STORAGE_SEARCH_PARAM_BY_TYPE} from './constants';
912

1013
export function useStorageQueryParams() {
1114
const [queryParams, setQueryParams] = useQueryParams({
1215
type: StringParam,
1316
visible: StringParam,
17+
groupsSearch: StringParam,
18+
nodesSearch: StringParam,
1419
search: StringParam,
1520
uptimeFilter: StringParam,
1621
storageNodesGroupBy: StringParam,
@@ -20,7 +25,8 @@ export function useStorageQueryParams() {
2025
const storageType = storageTypeSchema.parse(queryParams.type);
2126

2227
const visibleEntities = visibleEntitiesSchema.parse(queryParams.visible);
23-
const searchValue = queryParams.search ?? '';
28+
const groupsSearchValue = queryParams.groupsSearch ?? '';
29+
const nodesSearchValue = queryParams.nodesSearch ?? '';
2430
const nodesUptimeFilter = nodesUptimeFilterValuesSchema.parse(queryParams.uptimeFilter);
2531

2632
const storageGroupsGroupByParam = storageGroupsGroupByParamSchema.parse(
@@ -30,8 +36,20 @@ export function useStorageQueryParams() {
3036
queryParams.storageNodesGroupBy,
3137
);
3238

33-
const handleTextFilterChange = (value: string) => {
34-
setQueryParams({search: value || undefined}, 'replaceIn');
39+
useEffect(() => {
40+
if (queryParams.search) {
41+
const patch: Record<string, string | undefined> = {search: undefined};
42+
patch[STORAGE_SEARCH_PARAM_BY_TYPE[storageType]] = queryParams.search;
43+
setQueryParams(patch, 'replaceIn');
44+
}
45+
}, [queryParams.search, storageType]);
46+
47+
const handleTextFilterGroupsChange = (value: string) => {
48+
setQueryParams({groupsSearch: value || undefined}, 'replaceIn');
49+
};
50+
51+
const handleTextFilterNodesChange = (value: string) => {
52+
setQueryParams({nodesSearch: value || undefined}, 'replaceIn');
3553
};
3654

3755
const handleVisibleEntitiesChange = (value: VisibleEntities) => {
@@ -49,6 +67,7 @@ export function useStorageQueryParams() {
4967
const handleStorageGroupsGroupByParamChange = (value: string) => {
5068
setQueryParams({storageGroupsGroupBy: value}, 'replaceIn');
5169
};
70+
5271
const handleStorageNodesGroupByParamChange = (value: string) => {
5372
setQueryParams({storageNodesGroupBy: value}, 'replaceIn');
5473
};
@@ -65,12 +84,14 @@ export function useStorageQueryParams() {
6584
return {
6685
storageType,
6786
visibleEntities,
68-
searchValue,
87+
groupsSearchValue,
88+
nodesSearchValue,
6989
nodesUptimeFilter,
7090
storageGroupsGroupByParam,
7191
storageNodesGroupByParam,
7292

73-
handleTextFilterChange,
93+
handleTextFilterGroupsChange,
94+
handleTextFilterNodesChange,
7495
handleVisibleEntitiesChange,
7596
handleStorageTypeChange,
7697
handleUptimeFilterChange,

0 commit comments

Comments
 (0)