Skip to content

Commit 72ce541

Browse files
authored
fix(TEvDescribeSchemeResult): support null value (#762)
1 parent b6bcd68 commit 72ce541

File tree

10 files changed

+28
-20
lines changed

10 files changed

+28
-20
lines changed

src/containers/Tenant/Diagnostics/Overview/Overview.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function Overview({type, tenantName}: OverviewProps) {
4444

4545
const {autorefresh, currentSchemaPath} = useTypedSelector((state) => state.schema);
4646
const {
47-
data,
47+
data: rawData,
4848
additionalData,
4949
loading: overviewLoading,
5050
wasLoaded: overviewWasLoaded,
@@ -112,6 +112,7 @@ function Overview({type, tenantName}: OverviewProps) {
112112
useAutofetcher(fetchData, [fetchData], autorefresh);
113113

114114
const renderContent = () => {
115+
const data = rawData ?? undefined;
115116
// verbose mapping to guarantee a correct render for new path types
116117
// TS will error when a new type is added but not mapped here
117118
const pathTypeToComponent: Record<EPathType, (() => ReactNode) | undefined> = {
@@ -124,7 +125,7 @@ function Overview({type, tenantName}: OverviewProps) {
124125
[EPathType.EPathTypeColumnStore]: undefined,
125126
[EPathType.EPathTypeColumnTable]: undefined,
126127
[EPathType.EPathTypeCdcStream]: () => (
127-
<ChangefeedInfo data={data} topic={additionalData?.[0]} />
128+
<ChangefeedInfo data={data} topic={additionalData?.[0] ?? undefined} />
128129
),
129130
[EPathType.EPathTypePersQueueGroup]: () => <TopicInfo data={data} />,
130131
[EPathType.EPathTypeExternalTable]: () => <ExternalTableInfo data={data} />,

src/containers/Tenant/Schema/SchemaTree/SchemaTree.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export function SchemaTree(props: SchemaTreeProps) {
2828
window.api
2929
.getSchema({path}, {concurrentId: `NavigationTree.getSchema|${path}`})
3030
.then((data) => {
31+
if (!data) {
32+
throw new Error(`no describe data about path ${path}`);
33+
}
3134
const {PathDescription: {Children = []} = {}} = data;
3235

3336
const preloadedData: Record<string, TEvDescribeSchemeResult> = {

src/services/api.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {BINARY_DATA_IN_PLAIN_TEXT_DISPLAY} from '../utils/constants';
4242
import {parseMetaCluster} from './parsers/parseMetaCluster';
4343
import {parseMetaTenants} from './parsers/parseMetaTenants';
4444
import {settingsManager} from './settings';
45+
import {Nullable} from '../utils/typecheckers';
4546

4647
type AxiosOptions = {
4748
concurrentId?: string;
@@ -179,7 +180,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
179180
});
180181
}
181182
getSchema({path}: {path: string}, {concurrentId}: AxiosOptions = {}) {
182-
return this.get<TEvDescribeSchemeResult>(
183+
return this.get<Nullable<TEvDescribeSchemeResult>>(
183184
this.getPath('/viewer/json/describe'),
184185
{
185186
path,
@@ -195,7 +196,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
195196
);
196197
}
197198
getDescribe({path}: {path: string}, {concurrentId}: AxiosOptions = {}) {
198-
return this.get<TEvDescribeSchemeResult>(
199+
return this.get<Nullable<TEvDescribeSchemeResult>>(
199200
this.getPath('/viewer/json/describe'),
200201
{
201202
path,
@@ -216,7 +217,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
216217
);
217218
}
218219
getHeatmapData({path}: {path: string}) {
219-
return this.get<TEvDescribeSchemeResult>(this.getPath('/viewer/json/describe'), {
220+
return this.get<Nullable<TEvDescribeSchemeResult>>(this.getPath('/viewer/json/describe'), {
220221
path,
221222
enums: true,
222223
backup: false,
@@ -393,7 +394,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
393394
);
394395
}
395396
getTabletDescribe(tenantId: TDomainKey) {
396-
return this.get<TEvDescribeSchemeResult>(this.getPath('/viewer/json/describe'), {
397+
return this.get<Nullable<TEvDescribeSchemeResult>>(this.getPath('/viewer/json/describe'), {
397398
schemeshard_id: tenantId?.SchemeShard,
398399
path_id: tenantId?.PathId,
399400
});

src/store/reducers/describe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function getDescribe({path}: {path: string}) {
9696
request,
9797
actions: FETCH_DESCRIBE,
9898
dataHandler: (data): IDescribeHandledResponse => {
99-
const dataPath = data.Path;
99+
const dataPath = data?.Path;
100100
const currentDescribe: IDescribeData = {};
101101
const newData: IDescribeData = {};
102102

@@ -126,14 +126,14 @@ export function getDescribeBatched(paths: string[]) {
126126
const newData: IDescribeData = {};
127127

128128
data.forEach((dataItem) => {
129-
if (dataItem.Path) {
129+
if (dataItem?.Path) {
130130
newData[dataItem.Path] = dataItem;
131131
currentDescribe[dataItem.Path] = dataItem;
132132
}
133133
});
134134

135135
return {
136-
path: data[0].Path,
136+
path: data[0]?.Path,
137137
currentDescribe,
138138
data: newData,
139139
};

src/store/reducers/heatmap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export function getTabletsInfo({nodes, path}: IHeatmapApiRequestParams) {
6363
window.api.getHeatmapData({path}),
6464
]),
6565
actions: FETCH_HEATMAP,
66-
dataHandler: ([tabletsData = {}, describe = {}]) => {
66+
dataHandler: ([tabletsData = {}, describe]) => {
6767
const {TabletStateInfo: tablets = []} = tabletsData;
6868
const TabletsMap: Map<string, IHeatmapTabletData> = new Map();
69-
const {PathDescription = {}} = describe;
69+
const {PathDescription = {}} = describe ?? {};
7070
const {
7171
TablePartitions = [],
7272
TablePartitionStats = [],

src/store/reducers/overview/overview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const schema: Reducer<OverviewState, OverviewAction> = (state = initialState, ac
2222
};
2323
}
2424
case FETCH_OVERVIEW.SUCCESS: {
25-
if (action.data.data.Path !== state.currentOverviewPath) {
25+
if (action.data.data?.Path !== state.currentOverviewPath) {
2626
return state;
2727
}
2828

src/store/reducers/overview/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import type {IResponseError} from '../../../types/api/error';
33
import type {TEvDescribeSchemeResult} from '../../../types/api/schema';
44

55
import {FETCH_OVERVIEW, setDataWasNotLoaded, setCurrentOverviewPath} from './overview';
6+
import {Nullable} from '../../../utils/typecheckers';
67

78
export interface OverviewState {
89
loading: boolean;
910
wasLoaded: boolean;
1011
currentOverviewPath?: string;
11-
data?: TEvDescribeSchemeResult;
12-
additionalData?: TEvDescribeSchemeResult[];
12+
data?: Nullable<TEvDescribeSchemeResult>;
13+
additionalData?: Nullable<TEvDescribeSchemeResult>[];
1314
error?: IResponseError;
1415
}
1516

1617
export interface OverviewHandledResponse {
17-
data: TEvDescribeSchemeResult;
18-
additionalData?: TEvDescribeSchemeResult[];
18+
data: Nullable<TEvDescribeSchemeResult>;
19+
additionalData?: Nullable<TEvDescribeSchemeResult>[];
1920
}
2021

2122
export type OverviewAction =

src/store/reducers/schema/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ export function getSchema({path}: {path: string}) {
125125
actions: FETCH_SCHEMA,
126126
dataHandler: (data): SchemaHandledResponse => {
127127
const newData: SchemaData = {};
128-
if (data.Path) {
128+
if (data?.Path) {
129129
newData[data.Path] = data;
130130
}
131131
return {
132-
path: data.Path,
133-
currentSchema: data,
132+
path: data?.Path,
133+
currentSchema: data ?? undefined,
134134
data: newData,
135135
};
136136
},

src/store/reducers/tablet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const getTabletDescribe = (tenantId: TDomainKey = {}) => {
125125
actions: FETCH_TABLET_DESCRIBE,
126126
dataHandler: (tabletDescribe): ITabletDescribeHandledResponse => {
127127
const {SchemeShard, PathId} = tenantId;
128-
const tenantPath = tabletDescribe.Path || `${SchemeShard}:${PathId}`;
128+
const tenantPath = tabletDescribe?.Path || `${SchemeShard}:${PathId}`;
129129

130130
return {tenantPath};
131131
},

src/utils/typecheckers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*/
44
export const isEnumMember = <T extends Object>(object: T, value: any): value is T[keyof T] =>
55
Object.values(object).includes(value);
6+
7+
export type Nullable<T> = T | null;

0 commit comments

Comments
 (0)