Skip to content

fix(Tenant): fix tabs reset on schema object change #1881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +110 to +115
Copy link
Member Author

@artemmufazalov artemmufazalov Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use type and sub type from object parent's Children field.

On initial load there will be loader and tabs will be rendered with full data. Further preloaded data from schema tree will be used to correctly render tabs


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];
},
);
Loading