Skip to content

Commit

Permalink
fix(Tenant): fix tabs reset on schema object change (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov authored Jan 30, 2025
1 parent a0ba20f commit 4dd053d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/containers/Tenant/Tenant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
import SplitPane from '../../components/SplitPane';
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
import {overviewApi} from '../../store/reducers/overview/overview';
import {selectSchemaObjectData} from '../../store/reducers/schema/schema';
import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../types/additionalProps';
import {cn} from '../../utils/cn';
import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../../utils/constants';
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks';
import {isAccessError} from '../../utils/response';

import ObjectGeneral from './ObjectGeneral/ObjectGeneral';
Expand Down Expand Up @@ -100,8 +101,18 @@ export function Tenant(props: TenantProps) {
pollingInterval: autoRefreshInterval,
},
);
const {PathType: currentPathType, PathSubType: currentPathSubType} =
currentItem?.PathDescription?.Self || {};

const preloadedData = useTypedSelector((state) =>
selectSchemaObjectData(state, path, tenantName),
);

// Use preloaded data if there is no current item data yet
const currentPathType =
currentItem?.PathDescription?.Self?.PathType ??
preloadedData?.PathDescription?.Self?.PathType;
const currentPathSubType =
currentItem?.PathDescription?.Self?.PathSubType ??
preloadedData?.PathDescription?.Self?.PathSubType;

const showBlockingError = isAccessError(error);

Expand Down
18 changes: 17 additions & 1 deletion src/store/reducers/schema/schema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';

import {createSlice} from '@reduxjs/toolkit';
import {createSelector, createSlice} from '@reduxjs/toolkit';
import type {PayloadAction} from '@reduxjs/toolkit';

import type {TEvDescribeSchemeResult} from '../../../types/api/schema';
import type {RootState} from '../../defaultStore';
import {api} from '../api';

const initialState = {
Expand Down Expand Up @@ -110,3 +111,18 @@ export function useGetSchemaQuery({path, database}: {path: string; database: str

return {data, isLoading, error: currentPathError};
}

const getSchemaSelector = createSelector(
(path: string) => path,
(_path: string, database: string) => database,
(path, database) => schemaApi.endpoints.getSchema.select({path, database}),
);

export const selectSchemaObjectData = createSelector(
(state: RootState) => state,
(_state: RootState, path: string) => path,
(_state: RootState, path: string, database: string) => getSchemaSelector(path, database),
(state, path, selectSchemaData) => {
return selectSchemaData(state).data?.[path];
},
);

0 comments on commit 4dd053d

Please sign in to comment.