@@ -2,24 +2,23 @@ import {createSelector, Selector} from 'reselect';
22import { Reducer } from 'redux' ;
33
44import '../../services/api' ;
5- import { TEvDescribeSchemeResult } from '../../types/api/schema' ;
65import { IConsumer } from '../../types/api/consumers' ;
7- import { IDescribeRootStateSlice , IDescribeState } from '../../types/store/describe' ;
8- import { IResponseError } from '../../types/api/error' ;
9- import { createRequestActionTypes , createApiRequest , ApiRequestAction } from '../utils' ;
6+ import { IDescribeRootStateSlice , IDescribeState , IDescribeAction } from '../../types/store/describe' ;
7+ import { createRequestActionTypes , createApiRequest } from '../utils' ;
108
11- const FETCH_DESCRIBE = createRequestActionTypes ( 'describe' , 'FETCH_DESCRIBE' ) ;
9+ export const FETCH_DESCRIBE = createRequestActionTypes ( 'describe' , 'FETCH_DESCRIBE' ) ;
10+ const SET_CURRENT_DESCRIBE_PATH = 'describe/SET_CURRENT_DESCRIBE_PATH' ;
11+ const SET_DATA_WAS_NOT_LOADED = 'describe/SET_DATA_WAS_NOT_LOADED' ;
1212
1313const initialState = {
1414 loading : false ,
1515 wasLoaded : false ,
1616 data : { } ,
17+ currentDescribe : undefined ,
18+ currentDescribePath : undefined ,
1719} ;
1820
19- const describe : Reducer <
20- IDescribeState ,
21- ApiRequestAction < typeof FETCH_DESCRIBE , TEvDescribeSchemeResult , IResponseError >
22- > = ( state = initialState , action ) => {
21+ const describe : Reducer < IDescribeState , IDescribeAction > = ( state = initialState , action ) => {
2322 switch ( action . type ) {
2423 case FETCH_DESCRIBE . REQUEST : {
2524 return {
@@ -28,53 +27,79 @@ const describe: Reducer<
2827 } ;
2928 }
3029 case FETCH_DESCRIBE . SUCCESS : {
31- let newData ;
30+ const data = action . data ;
3231
33- if ( action . data . Path ) {
32+ const isCurrentDescribePath = data . Path === state . currentDescribePath ;
33+
34+ let newData = state . data ;
35+
36+ if ( data . Path ) {
3437 newData = JSON . parse ( JSON . stringify ( state . data ) ) ;
35- newData [ action . data . Path ] = action . data ;
36- } else {
37- newData = state . data ;
38+ newData [ data . Path ] = data ;
39+ }
40+
41+ if ( ! isCurrentDescribePath ) {
42+ return {
43+ ...state ,
44+ data : newData ,
45+ } ;
3846 }
3947
4048 return {
4149 ...state ,
4250 data : newData ,
43- currentDescribe : action . data ,
51+ currentDescribe : data ,
4452 loading : false ,
4553 wasLoaded : true ,
4654 error : undefined ,
4755 } ;
4856 }
57+
4958 case FETCH_DESCRIBE . FAILURE : {
5059 return {
5160 ...state ,
5261 error : action . error ,
5362 loading : false ,
54- wasLoaded : true ,
63+ } ;
64+ }
65+ case SET_CURRENT_DESCRIBE_PATH : {
66+ return {
67+ ...state ,
68+ currentDescribePath : action . data ,
69+ } ;
70+ }
71+ case SET_DATA_WAS_NOT_LOADED : {
72+ return {
73+ ...state ,
74+ wasLoaded : false ,
5575 } ;
5676 }
5777 default :
5878 return state ;
5979 }
6080} ;
6181
82+ export const setCurrentDescribePath = ( path : string ) => {
83+ return {
84+ type : SET_CURRENT_DESCRIBE_PATH ,
85+ data : path ,
86+ } as const ;
87+ } ;
88+
89+ export const setDataWasNotLoaded = ( ) => {
90+ return {
91+ type : SET_DATA_WAS_NOT_LOADED ,
92+ } as const ;
93+ } ;
94+
6295// Consumers selectors
63- const selectConsumersNames : Selector < IDescribeRootStateSlice , string [ ] | undefined , [ string ] > = (
64- state ,
65- path ,
66- ) => state . describe . data [ path ] ?. PathDescription ?. PersQueueGroup ?. PQTabletConfig ?. ReadRules ;
67-
68- export const selectConsumers : Selector < IDescribeRootStateSlice , IConsumer [ ] > = createSelector (
69- selectConsumersNames ,
70- ( names = [ ] ) => {
71- const consumers = names . map ( ( name ) => {
72- return { name} ;
73- } ) ;
74-
75- return consumers ;
76- } ,
77- ) ;
96+ const selectConsumersNames = ( state : IDescribeRootStateSlice , path : string | undefined ) =>
97+ path
98+ ? state . describe . data [ path ] ?. PathDescription ?. PersQueueGroup ?. PQTabletConfig ?. ReadRules
99+ : undefined ;
100+
101+ export const selectConsumers : Selector < IDescribeRootStateSlice , IConsumer [ ] , [ string | undefined ] > =
102+ createSelector ( selectConsumersNames , ( names = [ ] ) => names . map ( ( name ) => ( { name} ) ) ) ;
78103
79104export function getDescribe ( { path} : { path : string } ) {
80105 return createApiRequest ( {
0 commit comments