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
3 changes: 2 additions & 1 deletion src/containers/Storage/PaginatedStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedT
import {PaginatedStorageGroups} from './PaginatedStorageGroups';
import {PaginatedStorageNodes} from './PaginatedStorageNodes';
import type {StorageViewContext} from './types';
import {useStorageQueryParams} from './useStorageQueryParams';
import {useSaveStorageType, useStorageQueryParams} from './useStorageQueryParams';
import {getStorageGroupsInitialEntitiesCount, getStorageNodesInitialEntitiesCount} from './utils';

export interface PaginatedStorageProps {
Expand All @@ -21,6 +21,7 @@ export interface PaginatedStorageProps {

export const PaginatedStorage = (props: PaginatedStorageProps) => {
const {storageType} = useStorageQueryParams();
useSaveStorageType();
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const isNodes = storageType === 'nodes';
Expand Down
38 changes: 33 additions & 5 deletions src/containers/Storage/useStorageQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';

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

import {SETTING_KEYS} from '../../store/reducers/settings/constants';
import {STORAGE_TYPES} from '../../store/reducers/storage/constants';
import type {StorageType, VisibleEntities} from '../../store/reducers/storage/types';
import {storageTypeSchema, visibleEntitiesSchema} from '../../store/reducers/storage/types';
import {useSetting} from '../../utils/hooks';
import {NodesUptimeFilterValues, nodesUptimeFilterValuesSchema} from '../../utils/nodes';

import {storageGroupsGroupByParamSchema} from './PaginatedStorageGroupsTable/columns/constants';
Expand All @@ -22,6 +25,11 @@ export function useStorageQueryParams() {
storageGroupsGroupBy: StringParam,
});

const [_savedStorageType, setSavedStorageType] = useSetting<StorageType>(
SETTING_KEYS.STORAGE_TYPE,
STORAGE_TYPES.groups,
);

const storageType = storageTypeSchema.parse(queryParams.type);

const visibleEntities = visibleEntitiesSchema.parse(queryParams.visible);
Expand All @@ -42,7 +50,7 @@ export function useStorageQueryParams() {
patch[STORAGE_SEARCH_PARAM_BY_TYPE[storageType]] = queryParams.search;
setQueryParams(patch, 'replaceIn');
}
}, [queryParams.search, storageType]);
}, [queryParams.search, storageType, setQueryParams]);

const handleTextFilterGroupsChange = (value: string) => {
setQueryParams({groupsSearch: value || undefined}, 'replaceIn');
Expand All @@ -56,9 +64,13 @@ export function useStorageQueryParams() {
setQueryParams({visible: value}, 'replaceIn');
};

const handleStorageTypeChange = (value: StorageType) => {
setQueryParams({type: value}, 'replaceIn');
};
const handleStorageTypeChange = React.useCallback(
(value: StorageType) => {
setQueryParams({type: value}, 'replaceIn');
setSavedStorageType(value);
},
[setQueryParams, setSavedStorageType],
);

const handleUptimeFilterChange = (value: NodesUptimeFilterValues) => {
setQueryParams({uptimeFilter: value}, 'replaceIn');
Expand Down Expand Up @@ -103,3 +115,19 @@ export function useStorageQueryParams() {
handleShowAllNodes,
};
}

export function useSaveStorageType() {
const [queryStorageType, setQueryStorageType] = useQueryParam('type', StringParam);
const [savedStorageType] = useSetting<StorageType>(
SETTING_KEYS.STORAGE_TYPE,
STORAGE_TYPES.groups,
);

const normalizedstorageType = queryStorageType ?? savedStorageType;

React.useEffect(() => {
if (normalizedstorageType !== queryStorageType) {
setQueryStorageType(normalizedstorageType);
}
}, [normalizedstorageType, queryStorageType, setQueryStorageType]);
}
3 changes: 3 additions & 0 deletions src/store/reducers/settings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {ValueOf} from '../../../types/common';
import {AclSyntax} from '../../../utils/constants';
import {Lang} from '../../../utils/i18n';
import {DEFAULT_QUERY_SETTINGS, QUERY_ACTIONS} from '../../../utils/query';
import {STORAGE_TYPES} from '../storage/constants';
import {TENANT_PAGES_IDS} from '../tenant/constants';

import type {SettingOptions} from './types';
Expand Down Expand Up @@ -36,6 +37,7 @@ export const SETTING_KEYS = {
QUERY_SETTINGS_BANNER_LAST_CLOSED: 'querySettingsBannerLastClosed',
QUERY_EXECUTION_SETTINGS: 'queryExecutionSettings',
ACL_SYNTAX: 'aclSyntax',
STORAGE_TYPE: 'storageType',
} as const;

export type SettingKey = ValueOf<typeof SETTING_KEYS>;
Expand Down Expand Up @@ -71,6 +73,7 @@ export const DEFAULT_USER_SETTINGS = {
[SETTING_KEYS.QUERY_SETTINGS_BANNER_LAST_CLOSED]: undefined,
[SETTING_KEYS.QUERY_EXECUTION_SETTINGS]: DEFAULT_QUERY_SETTINGS,
[SETTING_KEYS.ACL_SYNTAX]: AclSyntax.YdbShort,
[SETTING_KEYS.STORAGE_TYPE]: STORAGE_TYPES.groups,
} as const satisfies Record<SettingKey, unknown>;

export const SETTINGS_OPTIONS: Record<string, SettingOptions> = {
Expand Down
Loading