11import React from 'react' ;
22
3- import { StringParam , useQueryParams } from 'use-query-params' ;
3+ import { StringParam , useQueryParam , useQueryParams } from 'use-query-params' ;
44
5+ import { SETTING_KEYS } from '../../store/reducers/settings/constants' ;
6+ import { STORAGE_TYPES } from '../../store/reducers/storage/constants' ;
57import type { StorageType , VisibleEntities } from '../../store/reducers/storage/types' ;
68import { storageTypeSchema , visibleEntitiesSchema } from '../../store/reducers/storage/types' ;
9+ import { useSetting } from '../../utils/hooks' ;
710import { NodesUptimeFilterValues , nodesUptimeFilterValuesSchema } from '../../utils/nodes' ;
811
912import { storageGroupsGroupByParamSchema } from './PaginatedStorageGroupsTable/columns/constants' ;
@@ -22,6 +25,11 @@ export function useStorageQueryParams() {
2225 storageGroupsGroupBy : StringParam ,
2326 } ) ;
2427
28+ const [ _savedStorageType , setSavedStorageType ] = useSetting < StorageType > (
29+ SETTING_KEYS . STORAGE_TYPE ,
30+ STORAGE_TYPES . groups ,
31+ ) ;
32+
2533 const storageType = storageTypeSchema . parse ( queryParams . type ) ;
2634
2735 const visibleEntities = visibleEntitiesSchema . parse ( queryParams . visible ) ;
@@ -42,7 +50,7 @@ export function useStorageQueryParams() {
4250 patch [ STORAGE_SEARCH_PARAM_BY_TYPE [ storageType ] ] = queryParams . search ;
4351 setQueryParams ( patch , 'replaceIn' ) ;
4452 }
45- } , [ queryParams . search , storageType ] ) ;
53+ } , [ queryParams . search , storageType , setQueryParams ] ) ;
4654
4755 const handleTextFilterGroupsChange = ( value : string ) => {
4856 setQueryParams ( { groupsSearch : value || undefined } , 'replaceIn' ) ;
@@ -56,9 +64,13 @@ export function useStorageQueryParams() {
5664 setQueryParams ( { visible : value } , 'replaceIn' ) ;
5765 } ;
5866
59- const handleStorageTypeChange = ( value : StorageType ) => {
60- setQueryParams ( { type : value } , 'replaceIn' ) ;
61- } ;
67+ const handleStorageTypeChange = React . useCallback (
68+ ( value : StorageType ) => {
69+ setQueryParams ( { type : value } , 'replaceIn' ) ;
70+ setSavedStorageType ( value ) ;
71+ } ,
72+ [ setQueryParams , setSavedStorageType ] ,
73+ ) ;
6274
6375 const handleUptimeFilterChange = ( value : NodesUptimeFilterValues ) => {
6476 setQueryParams ( { uptimeFilter : value } , 'replaceIn' ) ;
@@ -103,3 +115,22 @@ export function useStorageQueryParams() {
103115 handleShowAllNodes,
104116 } ;
105117}
118+
119+ export function useSaveStorageType ( ) {
120+ const [ queryStorageType , setQueryStorageType ] = useQueryParam ( 'type' , StringParam ) ;
121+ const [ savedStorageType ] = useSetting < StorageType > (
122+ SETTING_KEYS . STORAGE_TYPE ,
123+ STORAGE_TYPES . groups ,
124+ ) ;
125+
126+ const normalizedStorageType = React . useMemo (
127+ ( ) => storageTypeSchema . parse ( queryStorageType ?? savedStorageType ) ,
128+ [ queryStorageType , savedStorageType ] ,
129+ ) ;
130+
131+ React . useEffect ( ( ) => {
132+ if ( normalizedStorageType !== queryStorageType ) {
133+ setQueryStorageType ( normalizedStorageType ) ;
134+ }
135+ } , [ normalizedStorageType , queryStorageType , setQueryStorageType ] ) ;
136+ }
0 commit comments