Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function GroupedStorageGroupsComponent({
viewContext,
}: PaginatedStorageProps) {
const [autoRefreshInterval] = useAutoRefreshInterval();
const {searchValue, storageGroupsGroupByParam, visibleEntities, handleShowAllGroups} =
const {groupsSearchValue, storageGroupsGroupByParam, visibleEntities, handleShowAllGroups} =
useStorageQueryParams();

const {columnsToShow, columnsToSelect, setColumns} = useStorageGroupsSelectedColumns({
Expand All @@ -111,7 +111,7 @@ export function GroupedStorageGroupsComponent({
nodeId,
groupId,
pDiskId,
filter: searchValue,
filter: groupsSearchValue,
shouldUseGroupsHandler: true,
group: storageGroupsGroupByParam,
},
Expand Down Expand Up @@ -152,7 +152,7 @@ export function GroupedStorageGroupsComponent({
groupId={groupId}
pDiskId={pDiskId}
filterGroupBy={storageGroupsGroupByParam}
searchValue={searchValue}
searchValue={groupsSearchValue}
visibleEntities={'all'}
scrollContainerRef={scrollContainerRef}
onIsExpandedChange={setIsGroupExpanded}
Expand Down Expand Up @@ -190,7 +190,7 @@ export function GroupedStorageGroupsComponent({
initialState={initialState}
tableWrapperProps={{
scrollContainerRef,
scrollDependencies: [searchValue, storageGroupsGroupByParam, tableGroups],
scrollDependencies: [groupsSearchValue, storageGroupsGroupByParam, tableGroups],
loading: isLoading,
className: b('groups-wrapper'),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function StorageGroupsComponent({
scrollContainerRef,
initialEntitiesCount,
}: PaginatedStorageProps) {
const {searchValue, visibleEntities, handleShowAllGroups} = useStorageQueryParams();
const {groupsSearchValue, visibleEntities, handleShowAllGroups} = useStorageQueryParams();

const storageGroupsHandlerHasGrouping = useStorageGroupsHandlerHasGrouping();

Expand Down Expand Up @@ -49,7 +49,7 @@ export function StorageGroupsComponent({
nodeId={nodeId}
groupId={groupId}
pDiskId={pDiskId}
searchValue={searchValue}
searchValue={groupsSearchValue}
visibleEntities={visibleEntities}
onShowAll={handleShowAllGroups}
scrollContainerRef={scrollContainerRef}
Expand All @@ -60,7 +60,7 @@ export function StorageGroupsComponent({
}
tableWrapperProps={{
scrollContainerRef,
scrollDependencies: [searchValue, visibleEntities],
scrollDependencies: [groupsSearchValue, visibleEntities],
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export function StorageGroupsControls({
entitiesLoading,
}: StorageControlsProps) {
const {
searchValue,
groupsSearchValue,
storageType,
visibleEntities,
storageGroupsGroupByParam,
handleTextFilterChange,
handleTextFilterGroupsChange,
handleStorageTypeChange,
handleVisibleEntitiesChange,
handleStorageGroupsGroupByParamChange,
Expand All @@ -60,8 +60,8 @@ export function StorageGroupsControls({
return (
<React.Fragment>
<Search
value={searchValue}
onChange={handleTextFilterChange}
value={groupsSearchValue}
onChange={handleTextFilterGroupsChange}
placeholder={i18n('controls_groups-search-placeholder')}
className={b('search')}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export function GroupedStorageNodesComponent({
}: PaginatedStorageProps) {
const [autoRefreshInterval] = useAutoRefreshInterval();

const {searchValue, storageNodesGroupByParam, handleShowAllNodes} = useStorageQueryParams();
const {nodesSearchValue, storageNodesGroupByParam, handleShowAllNodes} =
useStorageQueryParams();

const {handleDataFetched, columnsSettings} = useStorageColumnsSettings();
const {columnsToShow, columnsToSelect, setColumns} = useStorageNodesColumnsToSelect({
Expand All @@ -111,7 +112,7 @@ export function GroupedStorageNodesComponent({
{
database,
with: 'all',
filter: searchValue,
filter: nodesSearchValue,
node_id: nodeId,
group_id: groupId,
group: storageNodesGroupByParam,
Expand Down Expand Up @@ -151,7 +152,7 @@ export function GroupedStorageNodesComponent({
database={database}
nodeId={nodeId}
groupId={groupId}
searchValue={searchValue}
searchValue={nodesSearchValue}
visibleEntities="all"
filterGroupBy={storageNodesGroupByParam}
scrollContainerRef={scrollContainerRef}
Expand Down Expand Up @@ -191,7 +192,7 @@ export function GroupedStorageNodesComponent({
initialState={initialState}
tableWrapperProps={{
scrollContainerRef,
scrollDependencies: [searchValue, storageNodesGroupByParam, tableGroups],
scrollDependencies: [nodesSearchValue, storageNodesGroupByParam, tableGroups],
loading: isLoading,
className: b('groups-wrapper'),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function StorageNodesComponent({
scrollContainerRef,
initialEntitiesCount,
}: PaginatedStorageProps) {
const {searchValue, visibleEntities, nodesUptimeFilter, handleShowAllNodes} =
const {nodesSearchValue, visibleEntities, nodesUptimeFilter, handleShowAllNodes} =
useStorageQueryParams();

const viewerNodesHandlerHasGrouping = useViewerNodesHandlerHasGrouping();
Expand Down Expand Up @@ -52,7 +52,7 @@ export function StorageNodesComponent({
database={database}
nodeId={nodeId}
groupId={groupId}
searchValue={searchValue}
searchValue={nodesSearchValue}
visibleEntities={visibleEntities}
nodesUptimeFilter={nodesUptimeFilter}
onShowAll={handleShowAllNodes}
Expand All @@ -65,7 +65,7 @@ export function StorageNodesComponent({
}
tableWrapperProps={{
scrollContainerRef,
scrollDependencies: [searchValue, visibleEntities, nodesUptimeFilter],
scrollDependencies: [nodesSearchValue, visibleEntities, nodesUptimeFilter],
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export function StorageNodesControls({
entitiesLoading,
}: StorageControlsProps) {
const {
searchValue,
nodesSearchValue,
storageType,
visibleEntities,
nodesUptimeFilter,
storageNodesGroupByParam,
handleTextFilterChange,
handleTextFilterNodesChange,
handleStorageTypeChange,
handleVisibleEntitiesChange,
handleUptimeFilterChange,
Expand All @@ -50,8 +50,8 @@ export function StorageNodesControls({
return (
<React.Fragment>
<Search
value={searchValue}
onChange={handleTextFilterChange}
value={nodesSearchValue}
onChange={handleTextFilterNodesChange}
placeholder={i18n('controls_nodes-search-placeholder')}
className={b('search')}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/containers/Storage/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const STORAGE_SEARCH_PARAM_BY_TYPE: Record<string, string> = {
groups: 'groupsSearch',
nodes: 'nodesSearch',
};
31 changes: 26 additions & 5 deletions src/containers/Storage/useStorageQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {useEffect} from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have lost linter rule about imports from react. Could you please fix this to import React from 'react'? I'll tune linter config!


import {StringParam, useQueryParams} from 'use-query-params';

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

import {storageGroupsGroupByParamSchema} from './PaginatedStorageGroupsTable/columns/constants';
import {storageNodesGroupByParamSchema} from './PaginatedStorageNodesTable/columns/constants';
import {STORAGE_SEARCH_PARAM_BY_TYPE} from './constants';

export function useStorageQueryParams() {
const [queryParams, setQueryParams] = useQueryParams({
type: StringParam,
visible: StringParam,
groupsSearch: StringParam,
nodesSearch: StringParam,
search: StringParam,
uptimeFilter: StringParam,
storageNodesGroupBy: StringParam,
Expand All @@ -20,7 +25,8 @@ export function useStorageQueryParams() {
const storageType = storageTypeSchema.parse(queryParams.type);

const visibleEntities = visibleEntitiesSchema.parse(queryParams.visible);
const searchValue = queryParams.search ?? '';
const groupsSearchValue = queryParams.groupsSearch ?? '';
const nodesSearchValue = queryParams.nodesSearch ?? '';
const nodesUptimeFilter = nodesUptimeFilterValuesSchema.parse(queryParams.uptimeFilter);

const storageGroupsGroupByParam = storageGroupsGroupByParamSchema.parse(
Expand All @@ -30,8 +36,20 @@ export function useStorageQueryParams() {
queryParams.storageNodesGroupBy,
);

const handleTextFilterChange = (value: string) => {
setQueryParams({search: value || undefined}, 'replaceIn');
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great that you've thought about this!

if (queryParams.search) {
const patch: Record<string, string | undefined> = {search: undefined};
patch[STORAGE_SEARCH_PARAM_BY_TYPE[storageType]] = queryParams.search;
setQueryParams(patch, 'replaceIn');
}
}, [queryParams.search, storageType]);

const handleTextFilterGroupsChange = (value: string) => {
setQueryParams({groupsSearch: value || undefined}, 'replaceIn');
};

const handleTextFilterNodesChange = (value: string) => {
setQueryParams({nodesSearch: value || undefined}, 'replaceIn');
};

const handleVisibleEntitiesChange = (value: VisibleEntities) => {
Expand All @@ -49,6 +67,7 @@ export function useStorageQueryParams() {
const handleStorageGroupsGroupByParamChange = (value: string) => {
setQueryParams({storageGroupsGroupBy: value}, 'replaceIn');
};

const handleStorageNodesGroupByParamChange = (value: string) => {
setQueryParams({storageNodesGroupBy: value}, 'replaceIn');
};
Expand All @@ -65,12 +84,14 @@ export function useStorageQueryParams() {
return {
storageType,
visibleEntities,
searchValue,
groupsSearchValue,
nodesSearchValue,
nodesUptimeFilter,
storageGroupsGroupByParam,
storageNodesGroupByParam,

handleTextFilterChange,
handleTextFilterGroupsChange,
handleTextFilterNodesChange,
handleVisibleEntitiesChange,
handleStorageTypeChange,
handleUptimeFilterChange,
Expand Down
Loading