-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathConfigs.tsx
More file actions
131 lines (120 loc) · 4.28 KB
/
Configs.tsx
File metadata and controls
131 lines (120 loc) · 4.28 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
import {PersonPencil} from '@gravity-ui/icons';
import type {Column} from '@gravity-ui/react-data-table';
import {Icon, Popover, Switch} from '@gravity-ui/uikit';
import {StringParam, useQueryParam} from 'use-query-params';
import {ResponseError} from '../../../../components/Errors/ResponseError';
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
import {Search} from '../../../../components/Search';
import {TableWithControlsLayout} from '../../../../components/TableWithControlsLayout/TableWithControlsLayout';
import {tenantApi} from '../../../../store/reducers/tenant/tenant';
import type {FeatureFlagConfig} from '../../../../types/api/featureFlags';
import {cn} from '../../../../utils/cn';
import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants';
import {useAutoRefreshInterval} from '../../../../utils/hooks';
import i18n from './i18n';
import './Configs.scss';
const FEATURE_FLAGS_COLUMNS_WIDTH_LS_KEY = 'featureFlagsColumnsWidth';
const b = cn('ydb-diagnostics-configs');
const columns: Column<FeatureFlagConfig>[] = [
{
name: 'Touched',
header: '',
render: ({row}) =>
row.Current ? (
<Popover
content={i18n('flag-touched')}
className={b('icon-touched')}
placement="left"
>
<Icon data={PersonPencil} />
</Popover>
) : null,
width: 36,
sortable: false,
resizeable: false,
},
{
name: 'Name',
get header() {
return i18n('td-feature-flag');
},
render: ({row}) => (row.Current ? <b>{row.Name}</b> : row.Name),
width: 400,
sortable: true,
sortAccessor: ({Current, Name}) => {
return Number(!Current) + Name.toLowerCase();
},
},
{
name: 'Default',
get header() {
return i18n('td-default');
},
render: ({row}) => {
switch (row.Default) {
case true:
return i18n('enabled');
case false:
return i18n('disabled');
default:
return '-';
}
},
width: 100,
sortable: false,
resizeable: false,
},
{
name: 'Current',
get header() {
return i18n('td-current');
},
render: ({row}) => <Switch disabled checked={(row.Current ?? row.Default) || false} />,
width: 100,
sortable: false,
resizeable: false,
},
];
interface ConfigsProps {
database: string;
}
export const Configs = ({database}: ConfigsProps) => {
const [search, setSearch] = useQueryParam('search', StringParam);
const [autoRefreshInterval] = useAutoRefreshInterval();
const {
currentData = [],
isFetching,
error,
} = tenantApi.useGetClusterConfigQuery({database}, {pollingInterval: autoRefreshInterval});
const onChange = (value: string) => {
setSearch(value || undefined, 'replaceIn');
};
const featureFlagsFilter = search?.toLocaleLowerCase();
const featureFlags = featureFlagsFilter
? currentData.filter((item) => item.Name.toLocaleLowerCase().includes(featureFlagsFilter))
: currentData;
return (
<TableWithControlsLayout>
<TableWithControlsLayout.Controls>
<Search
value={featureFlagsFilter}
onChange={onChange}
placeholder={i18n('search-placeholder')}
/>
</TableWithControlsLayout.Controls>
<TableWithControlsLayout.Table loading={isFetching}>
{error ? (
<ResponseError error={error} />
) : (
<ResizeableDataTable
emptyDataMessage={i18n(featureFlagsFilter ? 'search-empty' : 'no-data')}
columnsWidthLSKey={FEATURE_FLAGS_COLUMNS_WIDTH_LS_KEY}
columns={columns}
data={featureFlags}
settings={DEFAULT_TABLE_SETTINGS}
/>
)}
</TableWithControlsLayout.Table>
</TableWithControlsLayout>
);
};