Skip to content

Commit d2f445f

Browse files
committed
fix: review
1 parent b9465d2 commit d2f445f

File tree

3 files changed

+21
-42
lines changed

3 files changed

+21
-42
lines changed

src/containers/Tenant/Diagnostics/Describe/Describe.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import {shallowEqual} from 'react-redux';
55

66
import {ResponseError} from '../../../../components/Errors/ResponseError';
77
import {Loader} from '../../../../components/Loader';
8-
import {
9-
overviewApi,
10-
selectPreparedPathOverview,
11-
} from '../../../../store/reducers/overview/overview';
8+
import {overviewApi} from '../../../../store/reducers/overview/overview';
129
import {selectSchemaMergedChildrenPaths} from '../../../../store/reducers/schema/schema';
1310
import type {EPathType} from '../../../../types/api/schema';
11+
import type {IDescribeData} from '../../../../types/store/describe';
1412
import {cn} from '../../../../utils/cn';
1513
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
1614
import {isEntityWithMergedImplementation} from '../../utils/schema';
@@ -28,6 +26,8 @@ interface IDescribeProps {
2826
type?: EPathType;
2927
}
3028

29+
const emptyObject: IDescribeData = {};
30+
3131
const Describe = ({path, database, type}: IDescribeProps) => {
3232
const [autoRefreshInterval] = useAutoRefreshInterval();
3333

@@ -44,18 +44,30 @@ const Describe = ({path, database, type}: IDescribeProps) => {
4444
} else if (mergedChildrenPaths) {
4545
paths = [path, ...mergedChildrenPaths];
4646
}
47-
const {currentData, isFetching, error} = overviewApi.useGetOverviewQuery(
47+
const {currentDescribe, currentData, isFetching, error} = overviewApi.useGetOverviewQuery(
4848
paths.length ? {paths, database} : skipToken,
4949
{
5050
pollingInterval: autoRefreshInterval,
51+
selectFromResult: (props) => {
52+
const {currentData} = props;
53+
if (!currentData) {
54+
return {currentDescribe: emptyObject, ...props};
55+
}
56+
57+
const mergedData = Object.values(currentData).flat();
58+
59+
const data = mergedData.reduce<IDescribeData>((acc, item) => {
60+
if (item?.Path) {
61+
acc[item.Path] = item;
62+
}
63+
return acc;
64+
}, {});
65+
return {currentDescribe: data, ...props};
66+
},
5167
},
5268
);
5369
const loading = isFetching && currentData === undefined;
5470

55-
const data = useTypedSelector((state) => selectPreparedPathOverview(state, paths, database));
56-
57-
const currentDescribe = data;
58-
5971
let preparedDescribeData: Object | undefined;
6072
if (currentDescribe) {
6173
const paths = Object.keys(currentDescribe);
Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {createSelector} from '@reduxjs/toolkit';
2-
3-
import type {IDescribeData} from '../../../types/store/describe';
4-
import type {RootState} from '../../defaultStore';
51
import {api} from '../api';
62

73
export const overviewApi = api.injectEndpoints({
@@ -30,31 +26,3 @@ export const overviewApi = api.injectEndpoints({
3026
}),
3127
}),
3228
});
33-
34-
const createGetOverviewSelector = createSelector(
35-
(paths: string[], database: string) => ({paths, database}),
36-
(params) => overviewApi.endpoints.getOverview.select(params),
37-
);
38-
39-
const selectPathOverview = createSelector(
40-
(state: RootState) => state,
41-
(_state: RootState, paths: string[], database: string) =>
42-
createGetOverviewSelector(paths, database),
43-
(state, selectGetOverview) => selectGetOverview(state).data,
44-
);
45-
46-
export const selectPreparedPathOverview = createSelector(selectPathOverview, (rawData) => {
47-
if (!rawData) {
48-
return undefined;
49-
}
50-
51-
const mergedData = Object.values(rawData).flat();
52-
53-
const data = mergedData.reduce<IDescribeData>((acc, item) => {
54-
if (item?.Path) {
55-
acc[item.Path] = item;
56-
}
57-
return acc;
58-
}, {});
59-
return data;
60-
});

src/store/reducers/schema/schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export const selectSchemaMergedChildrenPaths = createSelector(
129129
);
130130

131131
export function useGetSchemaQuery({path, database}: {path: string; database: string}) {
132-
console.log('IS HERE', path);
133132
const {currentData, isFetching, error, refetch, originalArgs} = schemaApi.useGetSchemaQuery({
134133
path,
135134
database,

0 commit comments

Comments
 (0)