From 117cfbdd569c83229204a4f9e424e91c9315315b Mon Sep 17 00:00:00 2001 From: Valerii Sidorenko Date: Thu, 27 Jun 2024 15:54:27 +0200 Subject: [PATCH] feat(autoRefresh): use user settings to store auto refresh interval --- src/containers/Heatmap/Heatmap.tsx | 5 ++- src/containers/Nodes/Nodes.tsx | 11 +++++-- src/containers/Storage/Storage.tsx | 4 +-- src/containers/Tablets/Tablets.tsx | 5 ++- .../Autorefresh/AutorefreshControl.tsx | 10 ++---- .../Diagnostics/Consumers/Consumers.tsx | 5 ++- .../Tenant/Diagnostics/Describe/Describe.tsx | 5 ++- .../Tenant/Diagnostics/Network/Network.tsx | 5 ++- .../Tenant/Diagnostics/Overview/Overview.tsx | 5 ++- .../Overview/TopicStats/TopicStats.tsx | 5 ++- .../Diagnostics/Partitions/Partitions.tsx | 10 ++++-- .../Healthcheck/HealthcheckDetails.tsx | 5 ++- .../Healthcheck/HealthcheckPreview.tsx | 5 ++- .../TenantCpu/TopNodesByCpu.tsx | 5 ++- .../TenantCpu/TopNodesByLoad.tsx | 5 ++- .../TenantOverview/TenantCpu/TopQueries.tsx | 5 ++- .../TenantOverview/TenantCpu/TopShards.tsx | 5 ++- .../TenantDashboard/TenantDashboard.tsx | 5 ++- .../TenantMemory/TopNodesByMemory.tsx | 5 ++- .../TenantOverview/TenantOverview.tsx | 5 ++- .../TenantStorage/TopGroups.tsx | 5 ++- .../TenantStorage/TopTables.tsx | 5 ++- .../Diagnostics/TopQueries/TopQueries.tsx | 5 ++- .../Diagnostics/TopShards/TopShards.tsx | 5 ++- .../Tenant/Query/Preview/Preview.tsx | 5 ++- src/services/settings.ts | 2 ++ src/store/reducers/autoRefreshControl.ts | 31 ------------------- src/store/reducers/index.ts | 2 -- src/utils/hooks/index.ts | 1 + src/utils/hooks/useAutoRefreshInterval.ts | 7 +++++ 30 files changed, 72 insertions(+), 111 deletions(-) delete mode 100644 src/store/reducers/autoRefreshControl.ts create mode 100644 src/utils/hooks/useAutoRefreshInterval.ts diff --git a/src/containers/Heatmap/Heatmap.tsx b/src/containers/Heatmap/Heatmap.tsx index 30b182bbbb..6dd3299871 100644 --- a/src/containers/Heatmap/Heatmap.tsx +++ b/src/containers/Heatmap/Heatmap.tsx @@ -4,13 +4,12 @@ import {Checkbox, Select} from '@gravity-ui/uikit'; import {ResponseError} from '../../components/Errors/ResponseError'; import {Loader} from '../../components/Loader'; -import {selectAutoRefreshInterval} from '../../store/reducers/autoRefreshControl'; import {heatmapApi, setHeatmapOptions} from '../../store/reducers/heatmap'; import {hideTooltip, showTooltip} from '../../store/reducers/tooltip'; import type {IHeatmapMetricValue} from '../../types/store/heatmap'; import {cn} from '../../utils/cn'; import {formatNumber} from '../../utils/dataFormatters/dataFormatters'; -import {useTypedDispatch, useTypedSelector} from '../../utils/hooks'; +import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks'; import {HeatmapCanvas} from './HeatmapCanvas/HeatmapCanvas'; import {Histogram} from './Histogram/Histogram'; @@ -30,7 +29,7 @@ export const Heatmap = ({path}: HeatmapProps) => { const itemsContainer = React.createRef(); - const autoRefreshInterval = useTypedSelector(selectAutoRefreshInterval); + const [autoRefreshInterval] = useAutoRefreshInterval(); const {currentData, isFetching, error} = heatmapApi.useGetHeatmapTabletsInfoQuery( {path}, diff --git a/src/containers/Nodes/Nodes.tsx b/src/containers/Nodes/Nodes.tsx index ef54a4e6fa..1d29b969f2 100644 --- a/src/containers/Nodes/Nodes.tsx +++ b/src/containers/Nodes/Nodes.tsx @@ -13,7 +13,6 @@ import {ResizeableDataTable} from '../../components/ResizeableDataTable/Resizeab import {Search} from '../../components/Search'; import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout'; import {UptimeFilter} from '../../components/UptimeFIlter'; -import {selectAutoRefreshInterval} from '../../store/reducers/autoRefreshControl'; import {nodesApi} from '../../store/reducers/nodes/nodes'; import {filterNodes} from '../../store/reducers/nodes/selectors'; import type {NodesSortParams} from '../../store/reducers/nodes/types'; @@ -30,7 +29,13 @@ import { DEFAULT_TABLE_SETTINGS, USE_NODES_ENDPOINT_IN_DIAGNOSTICS_KEY, } from '../../utils/constants'; -import {useSetting, useTableSort, useTypedDispatch, useTypedSelector} from '../../utils/hooks'; +import { + useAutoRefreshInterval, + useSetting, + useTableSort, + useTypedDispatch, + useTypedSelector, +} from '../../utils/hooks'; import { NodesUptimeFilterValues, isSortableNodesProperty, @@ -63,7 +68,7 @@ export const Nodes = ({path, additionalNodesProps = {}}: NodesProps) => { const isClusterNodes = !path; const problemFilter = useTypedSelector(selectProblemFilter); - const autorefresh = useTypedSelector(selectAutoRefreshInterval); + const [autorefresh] = useAutoRefreshInterval(); const [useNodesEndpoint] = useSetting(USE_NODES_ENDPOINT_IN_DIAGNOSTICS_KEY); diff --git a/src/containers/Storage/Storage.tsx b/src/containers/Storage/Storage.tsx index debbc249ca..568de955e3 100644 --- a/src/containers/Storage/Storage.tsx +++ b/src/containers/Storage/Storage.tsx @@ -5,7 +5,6 @@ import {ArrayParam, StringParam, useQueryParams, withDefault} from 'use-query-pa import {AccessDenied} from '../../components/Errors/403'; import {ResponseError} from '../../components/Errors/ResponseError'; import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout'; -import {selectAutoRefreshInterval} from '../../store/reducers/autoRefreshControl'; import type {NodesSortParams} from '../../store/reducers/nodes/types'; import {selectNodesMap} from '../../store/reducers/nodesList'; import {STORAGE_TYPES, VISIBLE_ENTITIES} from '../../store/reducers/storage/constants'; @@ -24,6 +23,7 @@ import type { import type {AdditionalNodesProps} from '../../types/additionalProps'; import {DEFAULT_POLLING_INTERVAL, DEFAULT_TABLE_SETTINGS} from '../../utils/constants'; import { + useAutoRefreshInterval, useNodesRequestParams, useStorageRequestParams, useTableSort, @@ -63,7 +63,7 @@ interface StorageProps { } export const Storage = ({additionalNodesProps, tenant, nodeId}: StorageProps) => { - const autorefresh = useTypedSelector(selectAutoRefreshInterval); + const [autorefresh] = useAutoRefreshInterval(); const [queryParams, setQueryParams] = useQueryParams({ type: StringParam, visible: StringParam, diff --git a/src/containers/Tablets/Tablets.tsx b/src/containers/Tablets/Tablets.tsx index 76768cee4a..8dcf1224e3 100644 --- a/src/containers/Tablets/Tablets.tsx +++ b/src/containers/Tablets/Tablets.tsx @@ -10,7 +10,6 @@ import {InternalLink} from '../../components/InternalLink'; import {ResizeableDataTable} from '../../components/ResizeableDataTable/ResizeableDataTable'; import {TableSkeleton} from '../../components/TableSkeleton/TableSkeleton'; import routes, {createHref} from '../../routes'; -import {selectAutoRefreshInterval} from '../../store/reducers/autoRefreshControl'; import {selectTabletsWithFqdn, tabletsApi} from '../../store/reducers/tablets'; import {ETabletState} from '../../types/api/tablet'; import type {TTabletStateInfo} from '../../types/api/tablet'; @@ -18,7 +17,7 @@ import type {TabletsApiRequestParams} from '../../types/store/tablets'; import {cn} from '../../utils/cn'; import {DEFAULT_TABLE_SETTINGS} from '../../utils/constants'; import {calcUptime} from '../../utils/dataFormatters/dataFormatters'; -import {useTypedDispatch, useTypedSelector} from '../../utils/hooks'; +import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks'; import {mapTabletStateToLabelTheme} from '../../utils/tablet'; import {getDefaultNodePath} from '../Node/NodePages'; @@ -146,7 +145,7 @@ interface TabletsProps { } export function Tablets({nodeId, path, className}: TabletsProps) { - const autoRefreshInterval = useTypedSelector(selectAutoRefreshInterval); + const [autoRefreshInterval] = useAutoRefreshInterval(); let params: TabletsApiRequestParams = {}; const node = nodeId === undefined ? undefined : String(nodeId); diff --git a/src/containers/Tenant/Diagnostics/Autorefresh/AutorefreshControl.tsx b/src/containers/Tenant/Diagnostics/Autorefresh/AutorefreshControl.tsx index 40c75436b3..c2c83429e2 100644 --- a/src/containers/Tenant/Diagnostics/Autorefresh/AutorefreshControl.tsx +++ b/src/containers/Tenant/Diagnostics/Autorefresh/AutorefreshControl.tsx @@ -2,12 +2,8 @@ import {ArrowsRotateLeft} from '@gravity-ui/icons'; import {Button, Select} from '@gravity-ui/uikit'; import {api} from '../../../../store/reducers/api'; -import { - selectAutoRefreshInterval, - setAutoRefreshInterval, -} from '../../../../store/reducers/autoRefreshControl'; import {cn} from '../../../../utils/cn'; -import {useTypedDispatch, useTypedSelector} from '../../../../utils/hooks'; +import {useAutoRefreshInterval, useTypedDispatch} from '../../../../utils/hooks'; import i18n from './i18n'; @@ -21,7 +17,7 @@ interface AutorefreshControlProps { export function AutorefreshControl({className}: AutorefreshControlProps) { const dispatch = useTypedDispatch(); - const autoRefreshInterval = useTypedSelector(selectAutoRefreshInterval); + const [autoRefreshInterval, setAutoRefreshInterval] = useAutoRefreshInterval(); return (