Skip to content

Commit ddd4ecc

Browse files
committed
fix: review
1 parent f3c93ea commit ddd4ecc

File tree

7 files changed

+63
-20
lines changed

7 files changed

+63
-20
lines changed

src/components/JsonViewer/unipika/unipika.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export const defaultUnipikaSettings = {
1616
};
1717

1818
export function unipikaConvert(value: unknown) {
19+
if (!value) {
20+
return value;
21+
}
1922
let result;
2023
try {
2124
result = unipika.converters.yson(value, defaultUnipikaSettings);

src/containers/Configs/Configs.tsx

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
import React from 'react';
2+
13
import {SegmentedRadioGroup} from '@gravity-ui/uikit';
24

35
import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout';
6+
import {
7+
useConfigAvailable,
8+
useFeatureFlagsAvailable,
9+
} from '../../store/reducers/capabilities/hooks';
410
import {cn} from '../../utils/cn';
511

612
import {Config} from './components/Config/Config';
713
import {FeatureFlags} from './components/FeatureFlags/FeatureFlags';
814
import {Startup} from './components/Startup/Startup';
15+
import type {ConfigType} from './types';
916
import {ConfigTypeTitles, ConfigTypes} from './types';
1017
import {useConfigQueryParams} from './useConfigsQueryParams';
1118

1219
import './Configs.scss';
20+
1321
interface ConfigsProps {
1422
database?: string;
1523
className?: string;
@@ -21,6 +29,21 @@ const b = cn('ydb-configs');
2129
export function Configs({database, className, scrollContainerRef}: ConfigsProps) {
2230
const {configType} = useConfigQueryParams();
2331

32+
const isFeaturesAvailable = useFeatureFlagsAvailable();
33+
const isConfigsAvailable = useConfigAvailable();
34+
35+
const options = React.useMemo(() => {
36+
const options: ConfigType[] = [];
37+
if (isFeaturesAvailable) {
38+
options.push(ConfigTypes.features);
39+
}
40+
if (isConfigsAvailable) {
41+
options.push(ConfigTypes.current);
42+
options.push(ConfigTypes.startup);
43+
}
44+
return options;
45+
}, [isFeaturesAvailable, isConfigsAvailable]);
46+
2447
const renderContent = () => {
2548
switch (configType) {
2649
case ConfigTypes.current:
@@ -35,7 +58,7 @@ export function Configs({database, className, scrollContainerRef}: ConfigsProps)
3558
return (
3659
<TableWithControlsLayout fullHeight className={b(null, className)}>
3760
<TableWithControlsLayout.Controls>
38-
<ConfigSelector />
61+
<ConfigSelector options={options} />
3962
</TableWithControlsLayout.Controls>
4063
<TableWithControlsLayout.Table scrollContainerRef={scrollContainerRef}>
4164
{renderContent()}
@@ -44,20 +67,20 @@ export function Configs({database, className, scrollContainerRef}: ConfigsProps)
4467
);
4568
}
4669

47-
function ConfigSelector() {
70+
function ConfigSelector({options}: {options: ConfigType[]}) {
4871
const {configType, handleConfigTypeChange} = useConfigQueryParams();
4972

73+
if (!options.length) {
74+
return null;
75+
}
76+
5077
return (
5178
<SegmentedRadioGroup value={configType} onUpdate={handleConfigTypeChange}>
52-
<SegmentedRadioGroup.Option value={ConfigTypes.current}>
53-
{ConfigTypeTitles[ConfigTypes.current]}
54-
</SegmentedRadioGroup.Option>
55-
<SegmentedRadioGroup.Option value={ConfigTypes.startup}>
56-
{ConfigTypeTitles[ConfigTypes.startup]}
57-
</SegmentedRadioGroup.Option>
58-
<SegmentedRadioGroup.Option value={ConfigTypes.features}>
59-
{ConfigTypeTitles[ConfigTypes.features]}
60-
</SegmentedRadioGroup.Option>
79+
{options.map((option) => (
80+
<SegmentedRadioGroup.Option key={option} value={option}>
81+
{ConfigTypeTitles[option]}
82+
</SegmentedRadioGroup.Option>
83+
))}
6184
</SegmentedRadioGroup>
6285
);
6386
}

src/containers/Configs/useConfigsQueryParams.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import React from 'react';
22

33
import {StringParam, createEnumParam, useQueryParams, withDefault} from 'use-query-params';
44

5+
import {
6+
useConfigAvailable,
7+
useFeatureFlagsAvailable,
8+
} from '../../store/reducers/capabilities/hooks';
9+
510
import type {ConfigType} from './types';
611
import {ConfigTypes} from './types';
712

@@ -18,6 +23,8 @@ export const ConfigTypeValueParam = withDefault<ConfigType | undefined | null, '
1823
);
1924

2025
export function useConfigQueryParams() {
26+
const isFeaturesAvailable = useFeatureFlagsAvailable();
27+
const isConfigsAvailable = useConfigAvailable();
2128
const [{configType, search}, setQueryParams] = useQueryParams({
2229
configType: ConfigTypeValueParam,
2330
search: StringParam,
@@ -35,6 +42,16 @@ export function useConfigQueryParams() {
3542
[setQueryParams],
3643
);
3744

45+
React.useEffect(() => {
46+
if (!isConfigsAvailable && !isFeaturesAvailable) {
47+
handleConfigTypeChange(undefined);
48+
} else if (!isFeaturesAvailable && configType === ConfigTypes.features) {
49+
handleConfigTypeChange(ConfigTypes.current);
50+
} else {
51+
handleConfigTypeChange(ConfigTypes.features);
52+
}
53+
}, [isFeaturesAvailable, isConfigsAvailable]);
54+
3855
return {
3956
configType,
4057
handleConfigTypeChange,

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {AutoRefreshControl} from '../../../components/AutoRefreshControl/AutoRef
77
import {DrawerContextProvider} from '../../../components/Drawer/DrawerContext';
88
import {InternalLink} from '../../../components/InternalLink';
99
import {
10+
useConfigAvailable,
1011
useFeatureFlagsAvailable,
1112
useTopicDataAvailable,
1213
} from '../../../store/reducers/capabilities/hooks';
@@ -64,14 +65,15 @@ function Diagnostics(props: DiagnosticsProps) {
6465
);
6566

6667
const hasFeatureFlags = useFeatureFlagsAvailable();
68+
const hasConfigs = useConfigAvailable();
69+
const configsAvailable = hasFeatureFlags || hasConfigs;
6770
const hasTopicData = useTopicDataAvailable();
6871
const isViewerUser = useIsViewerUser();
6972
const pages = getPagesByType(type, subType, {
70-
hasFeatureFlags,
7173
hasTopicData,
7274
isTopLevel: path === database,
7375
hasBackups: typeof uiFactory.renderBackups === 'function' && Boolean(controlPlane),
74-
hasConfigs: isViewerUser,
76+
hasConfigs: isViewerUser && configsAvailable,
7577
hasAccess: uiFactory.hasAccess,
7678
databaseType,
7779
});

src/containers/Tenant/Diagnostics/DiagnosticsPages.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ type Page = {
1616
};
1717

1818
interface GetPagesOptions {
19-
hasFeatureFlags?: boolean;
2019
hasTopicData?: boolean;
2120
isTopLevel?: boolean;
2221
hasBackups?: boolean;
@@ -231,12 +230,7 @@ export const getPagesByType = (
231230
const dbContext = isDatabaseEntityType(type) || options?.isTopLevel;
232231
const seeded = dbContext ? getDatabasePages(options?.databaseType) : base;
233232

234-
let withFlags = seeded;
235-
if (!options?.hasFeatureFlags) {
236-
withFlags = seeded.filter((p) => p.id !== TENANT_DIAGNOSTICS_TABS_IDS.configs);
237-
}
238-
239-
return applyFilters(withFlags, type, options);
233+
return applyFilters(seeded, type, options);
240234
};
241235

242236
export const useDiagnosticsPageLinkGetter = () => {

src/store/reducers/capabilities/hooks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ export const useClusterDashboardAvailable = () => {
8787
export const useStreamingAvailable = () => {
8888
return useGetFeatureVersion('/viewer/query') >= 8;
8989
};
90+
export const useConfigAvailable = () => {
91+
return useGetFeatureVersion('/viewer/config') >= 1;
92+
};
9093
export const useEditAccessAvailable = () => {
9194
return useGetFeatureVersion('/viewer/acl') >= 2 && !uiFactory.hideGrantAccess;
9295
};

src/types/api/capabilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type Capability =
2121
| '/storage/groups'
2222
| '/viewer/query'
2323
| '/viewer/feature_flags'
24+
| '/viewer/config'
2425
| '/viewer/cluster'
2526
| '/viewer/nodes'
2627
| '/viewer/acl'

0 commit comments

Comments
 (0)