-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathconstants.ts
More file actions
232 lines (214 loc) · 6 KB
/
constants.ts
File metadata and controls
232 lines (214 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import type {SelectOption} from '@gravity-ui/uikit';
import {z} from 'zod';
import type {
GroupsGroupByField,
GroupsRequiredField,
StorageV2SortValue,
} from '../../../../types/api/storage';
import type {ValueOf} from '../../../../types/common';
import i18n from './i18n';
export const STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY = 'storageGroupsColumnsWidth';
export const STORAGE_GROUPS_SELECTED_COLUMNS_LS_KEY = 'storageGroupsSelectedColumns';
export const STORAGE_GROUPS_COLUMNS_IDS = {
GroupId: 'GroupId',
PoolName: 'PoolName',
MediaType: 'MediaType',
Erasure: 'Erasure',
Used: 'Used',
Limit: 'Limit',
Usage: 'Usage',
DiskSpaceUsage: 'DiskSpaceUsage',
DiskSpace: 'DiskSpace',
Read: 'Read',
Write: 'Write',
Latency: 'Latency',
AllocationUnits: 'AllocationUnits',
VDisks: 'VDisks',
VDisksPDisks: 'VDisksPDisks',
Degraded: 'Degraded',
State: 'State',
} as const;
export type StorageGroupsColumnId = ValueOf<typeof STORAGE_GROUPS_COLUMNS_IDS>;
// Columns, that should displayed only for users with isMonitoringAllowed:true
const MONITORING_USER_COLUMNS_IDS: StorageGroupsColumnId[] = [
'DiskSpaceUsage',
'Latency',
'AllocationUnits',
'VDisksPDisks',
];
export function isMonitoringUserGroupsColumn(columnId: string): boolean {
return MONITORING_USER_COLUMNS_IDS.includes(columnId as StorageGroupsColumnId);
}
export const DEFAULT_STORAGE_GROUPS_COLUMNS: StorageGroupsColumnId[] = [
'GroupId',
'PoolName',
'Erasure',
'Used',
'VDisks',
];
export const REQUIRED_STORAGE_GROUPS_COLUMNS: StorageGroupsColumnId[] = ['GroupId'];
// This code is running when module is initialized and correct language may not be set yet
// get functions guarantee that i18n fields will be inited on render with current render language
export const STORAGE_GROUPS_COLUMNS_TITLES = {
get PoolName() {
return i18n('pool-name');
},
get MediaType() {
return i18n('type');
},
get Erasure() {
return i18n('erasure');
},
get GroupId() {
return i18n('group-id');
},
get Used() {
return i18n('used');
},
get Limit() {
return i18n('limit');
},
get Usage() {
return i18n('usage');
},
get DiskSpaceUsage() {
return i18n('disk-usage');
},
get DiskSpace() {
return i18n('space');
},
get Read() {
return i18n('read');
},
get Write() {
return i18n('write');
},
get Latency() {
return i18n('latency');
},
get AllocationUnits() {
return i18n('allocation-units');
},
get VDisks() {
return i18n('vdisks');
},
get VDisksPDisks() {
return i18n('vdisks-pdisks');
},
get Degraded() {
return i18n('missing-disks');
},
get State() {
return i18n('state');
},
} as const satisfies Record<StorageGroupsColumnId, string>;
const STORAGE_GROUPS_COLUMNS_GROUP_BY_TITLES = {
get GroupId() {
return i18n('group-id');
},
get Erasure() {
return i18n('erasure');
},
get Usage() {
return i18n('usage');
},
get DiskSpaceUsage() {
return i18n('disk-usage');
},
get PoolName() {
return i18n('pool-name');
},
get Kind() {
return i18n('type');
},
get Encryption() {
return i18n('encryption');
},
get MediaType() {
return i18n('type');
},
get MissingDisks() {
return i18n('missing-disks');
},
get State() {
return i18n('state');
},
get Latency() {
return i18n('latency');
},
} as const satisfies Record<GroupsGroupByField, string>;
const STORAGE_GROUPS_GROUP_BY_PARAMS = [
'PoolName',
'MediaType',
'Encryption',
'Erasure',
'Usage',
'DiskSpaceUsage',
'State',
'MissingDisks',
'Latency',
] as const satisfies GroupsGroupByField[];
export const STORAGE_GROUPS_GROUP_BY_OPTIONS: SelectOption[] = STORAGE_GROUPS_GROUP_BY_PARAMS.map(
(param) => {
return {
value: param,
content: STORAGE_GROUPS_COLUMNS_GROUP_BY_TITLES[param],
};
},
);
export const storageGroupsGroupByParamSchema = z
.custom<
GroupsGroupByField | undefined
>((value) => STORAGE_GROUPS_GROUP_BY_PARAMS.includes(value))
.catch(undefined);
// Although columns ids mostly similar to backend fields, there might be some difference
// Also for some columns we may use more than one field
export const GROUPS_COLUMNS_TO_DATA_FIELDS: Record<StorageGroupsColumnId, GroupsRequiredField[]> = {
GroupId: ['GroupId'],
PoolName: ['PoolName'],
// We display MediaType and Encryption in one Type column
MediaType: ['MediaType', 'Encryption'],
Erasure: ['Erasure'],
Used: ['Used'],
Limit: ['Limit'],
Usage: ['Usage'],
DiskSpaceUsage: ['DiskSpaceUsage'],
DiskSpace: ['State'],
Read: ['Read'],
Write: ['Write'],
Latency: ['Latency'],
AllocationUnits: ['AllocationUnits'],
// Read and Write fields make backend to return Whiteboard data
VDisks: ['VDisk', 'PDisk', 'Read', 'Write'],
VDisksPDisks: ['VDisk', 'PDisk', 'Read', 'Write'],
Degraded: ['MissingDisks'],
State: ['State'],
};
const STORAGE_GROUPS_COLUMNS_TO_SORT_FIELDS: Record<
StorageGroupsColumnId,
StorageV2SortValue | undefined
> = {
GroupId: 'GroupId',
PoolName: 'PoolName',
MediaType: 'MediaType',
Erasure: 'Erasure',
Used: 'Used',
Limit: 'Limit',
Usage: 'Usage',
DiskSpaceUsage: 'DiskSpaceUsage',
DiskSpace: undefined,
Read: 'Read',
Write: 'Write',
Latency: 'Latency',
AllocationUnits: 'AllocationUnits',
VDisks: undefined,
VDisksPDisks: undefined,
Degraded: 'Degraded',
State: 'State',
};
export function getStorageGroupsColumnSortField(columnId?: string) {
return STORAGE_GROUPS_COLUMNS_TO_SORT_FIELDS[columnId as StorageGroupsColumnId];
}
export function isSortableStorageGroupsColumn(columnId: string) {
return Boolean(getStorageGroupsColumnSortField(columnId));
}