|
1 | | -import {StringParam, useQueryParams} from 'use-query-params'; |
| 1 | +import {PaginatedStorageGroups} from './PaginatedStorageGroups'; |
| 2 | +import {PaginatedStorageNodes} from './PaginatedStorageNodes'; |
| 3 | +import {useStorageQueryParams} from './useStorageQueryParams'; |
2 | 4 |
|
3 | | -import {AccessDenied} from '../../components/Errors/403/AccessDenied'; |
4 | | -import {ResponseError} from '../../components/Errors/ResponseError/ResponseError'; |
5 | | -import type {RenderControls, RenderErrorMessage} from '../../components/PaginatedTable'; |
6 | | -import {useClusterBaseInfo} from '../../store/reducers/cluster/cluster'; |
7 | | -import {VISIBLE_ENTITIES} from '../../store/reducers/storage/constants'; |
8 | | -import {storageTypeSchema, visibleEntitiesSchema} from '../../store/reducers/storage/types'; |
9 | | -import type {StorageType, VisibleEntities} from '../../store/reducers/storage/types'; |
10 | | -import {NodesUptimeFilterValues, nodesUptimeFilterValuesSchema} from '../../utils/nodes'; |
11 | | -import {useAdditionalNodeProps} from '../AppWithClusters/useClusterData'; |
12 | | - |
13 | | -import {StorageControls} from './StorageControls/StorageControls'; |
14 | | -import {PaginatedStorageGroups} from './StorageGroups/PaginatedStorageGroups'; |
15 | | -import {useStorageGroupsSelectedColumns} from './StorageGroups/columns/hooks'; |
16 | | -import {PaginatedStorageNodes} from './StorageNodes/PaginatedStorageNodes'; |
17 | | -import {useStorageNodesSelectedColumns} from './StorageNodes/columns/hooks'; |
18 | | - |
19 | | -interface PaginatedStorageProps { |
| 5 | +export interface PaginatedStorageProps { |
20 | 6 | database?: string; |
21 | 7 | nodeId?: string; |
22 | 8 | groupId?: string; |
23 | 9 | parentContainer?: Element | null; |
24 | 10 | } |
25 | 11 |
|
26 | | -export const PaginatedStorage = ({ |
27 | | - database, |
28 | | - nodeId, |
29 | | - groupId, |
30 | | - parentContainer, |
31 | | -}: PaginatedStorageProps) => { |
32 | | - const {balancer} = useClusterBaseInfo(); |
33 | | - const {additionalNodesProps} = useAdditionalNodeProps({balancer}); |
| 12 | +export const PaginatedStorage = (props: PaginatedStorageProps) => { |
| 13 | + const {storageType} = useStorageQueryParams(); |
34 | 14 |
|
35 | | - const [queryParams, setQueryParams] = useQueryParams({ |
36 | | - type: StringParam, |
37 | | - visible: StringParam, |
38 | | - search: StringParam, |
39 | | - uptimeFilter: StringParam, |
40 | | - }); |
41 | | - const storageType = storageTypeSchema.parse(queryParams.type); |
42 | | - const isGroups = storageType === 'groups'; |
43 | 15 | const isNodes = storageType === 'nodes'; |
44 | 16 |
|
45 | | - const visibleEntities = visibleEntitiesSchema.parse(queryParams.visible); |
46 | | - const searchValue = queryParams.search ?? ''; |
47 | | - const nodesUptimeFilter = nodesUptimeFilterValuesSchema.parse(queryParams.uptimeFilter); |
48 | | - |
49 | | - const { |
50 | | - columnsToShow: storageNodesColumnsToShow, |
51 | | - columnsToSelect: storageNodesColumnsToSelect, |
52 | | - setColumns: setStorageNodesSelectedColumns, |
53 | | - } = useStorageNodesSelectedColumns({ |
54 | | - additionalNodesProps, |
55 | | - visibleEntities, |
56 | | - database, |
57 | | - groupId, |
58 | | - }); |
59 | | - |
60 | | - const { |
61 | | - columnsToShow: storageGroupsColumnsToShow, |
62 | | - columnsToSelect: storageGroupsColumnsToSelect, |
63 | | - setColumns: setStorageGroupsSelectedColumns, |
64 | | - } = useStorageGroupsSelectedColumns(visibleEntities); |
65 | | - |
66 | | - const handleTextFilterChange = (value: string) => { |
67 | | - setQueryParams({search: value || undefined}, 'replaceIn'); |
68 | | - }; |
69 | | - |
70 | | - const handleGroupVisibilityChange = (value: VisibleEntities) => { |
71 | | - setQueryParams({visible: value}, 'replaceIn'); |
72 | | - }; |
73 | | - |
74 | | - const handleStorageTypeChange = (value: StorageType) => { |
75 | | - setQueryParams({type: value}, 'replaceIn'); |
76 | | - }; |
77 | | - |
78 | | - const handleUptimeFilterChange = (value: NodesUptimeFilterValues) => { |
79 | | - setQueryParams({uptimeFilter: value}, 'replaceIn'); |
80 | | - }; |
81 | | - |
82 | | - const handleShowAllGroups = () => { |
83 | | - handleGroupVisibilityChange(VISIBLE_ENTITIES.all); |
84 | | - }; |
85 | | - |
86 | | - const handleShowAllNodes = () => { |
87 | | - setQueryParams( |
88 | | - { |
89 | | - visible: VISIBLE_ENTITIES.all, |
90 | | - uptimeFilter: NodesUptimeFilterValues.All, |
91 | | - }, |
92 | | - 'replaceIn', |
93 | | - ); |
94 | | - }; |
95 | | - |
96 | | - const renderControls: RenderControls = ({totalEntities, foundEntities, inited}) => { |
97 | | - const columnsToSelect = isGroups |
98 | | - ? storageGroupsColumnsToSelect |
99 | | - : storageNodesColumnsToSelect; |
100 | | - |
101 | | - const handleSelectedColumnsUpdate = isGroups |
102 | | - ? setStorageGroupsSelectedColumns |
103 | | - : setStorageNodesSelectedColumns; |
104 | | - |
105 | | - return ( |
106 | | - <StorageControls |
107 | | - searchValue={searchValue} |
108 | | - handleSearchValueChange={handleTextFilterChange} |
109 | | - withTypeSelector |
110 | | - storageType={storageType} |
111 | | - handleStorageTypeChange={handleStorageTypeChange} |
112 | | - visibleEntities={visibleEntities} |
113 | | - handleVisibleEntitiesChange={handleGroupVisibilityChange} |
114 | | - nodesUptimeFilter={nodesUptimeFilter} |
115 | | - handleNodesUptimeFilterChange={handleUptimeFilterChange} |
116 | | - entitiesCountCurrent={foundEntities} |
117 | | - entitiesCountTotal={totalEntities} |
118 | | - entitiesLoading={!inited} |
119 | | - columnsToSelect={columnsToSelect} |
120 | | - handleSelectedColumnsUpdate={handleSelectedColumnsUpdate} |
121 | | - /> |
122 | | - ); |
123 | | - }; |
124 | | - |
125 | | - const renderErrorMessage: RenderErrorMessage = (error) => { |
126 | | - if (error.status === 403) { |
127 | | - return <AccessDenied position="left" />; |
128 | | - } |
129 | | - |
130 | | - return <ResponseError error={error} />; |
131 | | - }; |
132 | | - |
133 | 17 | if (isNodes) { |
134 | | - return ( |
135 | | - <PaginatedStorageNodes |
136 | | - searchValue={searchValue} |
137 | | - visibleEntities={visibleEntities} |
138 | | - nodesUptimeFilter={nodesUptimeFilter} |
139 | | - database={database} |
140 | | - onShowAll={handleShowAllNodes} |
141 | | - parentContainer={parentContainer} |
142 | | - renderControls={renderControls} |
143 | | - renderErrorMessage={renderErrorMessage} |
144 | | - columns={storageNodesColumnsToShow} |
145 | | - /> |
146 | | - ); |
| 18 | + return <PaginatedStorageNodes {...props} />; |
147 | 19 | } |
148 | 20 |
|
149 | | - return ( |
150 | | - <PaginatedStorageGroups |
151 | | - searchValue={searchValue} |
152 | | - visibleEntities={visibleEntities} |
153 | | - database={database} |
154 | | - nodeId={nodeId} |
155 | | - onShowAll={handleShowAllGroups} |
156 | | - parentContainer={parentContainer} |
157 | | - renderControls={renderControls} |
158 | | - renderErrorMessage={renderErrorMessage} |
159 | | - columns={storageGroupsColumnsToShow} |
160 | | - /> |
161 | | - ); |
| 21 | + return <PaginatedStorageGroups {...props} />; |
162 | 22 | }; |
0 commit comments