Skip to content

Commit 7c61dc9

Browse files
fix(Topic): add reducer for describe_topic
1 parent 4240ca2 commit 7c61dc9

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

src/services/api.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ interface Window {
5555
getHeatmapData: (params: {
5656
path: string;
5757
}) => Promise<import('../types/api/schema').TEvDescribeSchemeResult>;
58+
getTopic: (params: {
59+
path?: string;
60+
}) => Promise<import('../types/api/topic').DescribeTopicResult>;
5861
[method: string]: Function;
5962
};
6063
}

src/services/api.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
129129
path,
130130
});
131131
}
132+
getTopic({path}) {
133+
return this.get(this.getPath('/viewer/json/describe_topic'), {
134+
enums: true,
135+
include_stats: true,
136+
path,
137+
});
138+
}
132139
getPoolInfo(poolName) {
133140
return this.get(this.getPath('/viewer/json/storage'), {
134141
pool: poolName,

src/store/reducers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import network from './network';
1717
import pool from './pool';
1818
import tenants from './tenants';
1919
import tablet from './tablet';
20+
import topic from './topic';
2021
import executeQuery from './executeQuery';
2122
import explainQuery from './explainQuery';
2223
import tabletsFilters from './tabletsFilters';
@@ -55,6 +56,7 @@ export const rootReducer = {
5556
pool,
5657
tenants,
5758
tablet,
59+
topic,
5860
executeQuery,
5961
explainQuery,
6062
tabletsFilters,

src/store/reducers/topic.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type {Reducer} from 'redux';
2+
3+
import type {ITopicAction, ITopicState} from '../../types/store/topic';
4+
import '../../services/api';
5+
6+
import {createRequestActionTypes, createApiRequest} from '../utils';
7+
8+
export const FETCH_TOPIC = createRequestActionTypes('topic', 'FETCH_TOPIC');
9+
10+
const initialState = {
11+
loading: true,
12+
wasLoaded: false,
13+
data: {},
14+
};
15+
16+
const topic: Reducer<ITopicState, ITopicAction> = (state = initialState, action) => {
17+
switch (action.type) {
18+
case FETCH_TOPIC.REQUEST: {
19+
return {
20+
...state,
21+
loading: true,
22+
};
23+
}
24+
case FETCH_TOPIC.SUCCESS: {
25+
return {
26+
...state,
27+
data: action.data,
28+
loading: false,
29+
wasLoaded: true,
30+
error: undefined,
31+
};
32+
}
33+
case FETCH_TOPIC.FAILURE: {
34+
return {
35+
...state,
36+
error: action.error,
37+
loading: false,
38+
};
39+
}
40+
default:
41+
return state;
42+
}
43+
};
44+
45+
export function getTopic(path?: string) {
46+
return createApiRequest({
47+
request: window.api.getTopic({path}),
48+
actions: FETCH_TOPIC,
49+
});
50+
}
51+
52+
export default topic;

src/types/store/topic.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {FETCH_TOPIC} from '../../store/reducers/topic';
2+
import type {ApiRequestAction} from '../../store/utils';
3+
import type {IResponseError} from '../api/error';
4+
import type {DescribeTopicResult} from '../api/topic';
5+
6+
export interface ITopicState {
7+
loading: boolean;
8+
wasLoaded: boolean;
9+
data?: DescribeTopicResult;
10+
error?: IResponseError;
11+
}
12+
13+
export type ITopicAction = ApiRequestAction<
14+
typeof FETCH_TOPIC,
15+
DescribeTopicResult,
16+
IResponseError
17+
>;
18+
19+
export interface ITopicRootStateSlice {
20+
topic: ITopicState;
21+
}

0 commit comments

Comments
 (0)