Skip to content
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

fix: if database pass name to query params and to backend handlers #1978

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
8 changes: 4 additions & 4 deletions src/components/NodeHostWrapper/NodeHostWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {getDefaultNodePath} from '../../containers/Node/NodePages';
import type {NodeAddress} from '../../types/additionalProps';
import type {TNodeInfo, TSystemStateInfo} from '../../types/api/nodes';
import {
createBaseDeveloperUILinkWithNodeId,
createDeveloperUIInternalPageHref,
createDeveloperUILinkWithNodeId,
} from '../../utils/developerUI/developerUI';
import {isUnavailableNode} from '../../utils/nodes';
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
Expand Down Expand Up @@ -46,11 +46,11 @@ export const NodeHostWrapper = ({
if (getNodeRef) {
const developerUIHref = getNodeRef(node);
developerUIInternalHref = developerUIHref
? createDeveloperUIInternalPageHref(developerUIHref)
? createDeveloperUIInternalPageHref(developerUIHref, database)
: undefined;
} else if (node.NodeId) {
const developerUIHref = createDeveloperUILinkWithNodeId(node.NodeId);
developerUIInternalHref = createDeveloperUIInternalPageHref(developerUIHref);
const developerUIHref = createBaseDeveloperUILinkWithNodeId(node.NodeId);
developerUIInternalHref = createDeveloperUIInternalPageHref(developerUIHref, database);
}

const nodePath = isNodeAvailable
Expand Down
8 changes: 7 additions & 1 deletion src/components/PDiskInfo/PDiskInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {cn} from '../../utils/cn';
import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters';
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import type {PreparedPDisk} from '../../utils/disks/types';
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import type {InfoViewerItem} from '../InfoViewer';
import {InfoViewer} from '../InfoViewer/InfoViewer';
Expand All @@ -25,6 +26,7 @@ interface GetPDiskInfoOptions<T extends PreparedPDisk> {
nodeId?: number | string | null;
withPDiskPageLink?: boolean;
isUserAllowedToMakeChanges?: boolean;
database?: string;
}

// eslint-disable-next-line complexity
Expand All @@ -33,6 +35,7 @@ function getPDiskInfo<T extends PreparedPDisk>({
nodeId,
withPDiskPageLink,
isUserAllowedToMakeChanges,
database,
}: GetPDiskInfoOptions<T>) {
const {
PDiskId,
Expand Down Expand Up @@ -147,10 +150,11 @@ function getPDiskInfo<T extends PreparedPDisk>({
valueIsDefined(nodeId);

if (shouldDisplayLinks) {
const pDiskPagePath = getPDiskPagePath(PDiskId, nodeId);
const pDiskPagePath = getPDiskPagePath(PDiskId, nodeId, {database});
const pDiskInternalViewerPath = createPDiskDeveloperUILink({
nodeId,
pDiskId: PDiskId,
database,
});

additionalInfo.push({
Expand Down Expand Up @@ -189,12 +193,14 @@ export function PDiskInfo<T extends PreparedPDisk>({
className,
}: PDiskInfoProps<T>) {
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const database = useDatabaseFromQuery();

const [generalInfo, statusInfo, spaceInfo, additionalInfo] = getPDiskInfo({
pDisk,
nodeId,
withPDiskPageLink,
isUserAllowedToMakeChanges,
database,
});

return (
Expand Down
8 changes: 6 additions & 2 deletions src/components/PDiskPopup/PDiskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import type {PreparedPDisk} from '../../utils/disks/types';
import {useTypedSelector} from '../../utils/hooks';
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {bytesToGB, isNumeric} from '../../utils/utils';
import {InfoViewer} from '../InfoViewer';
Expand All @@ -19,6 +20,7 @@ export const preparePDiskData = (
data: PreparedPDisk,
nodeData?: {Host?: string; DC?: string},
withDeveloperUILink?: boolean,
database?: string,
) => {
const {
AvailableSize,
Expand Down Expand Up @@ -76,6 +78,7 @@ export const preparePDiskData = (
const pDiskInternalViewerPath = createPDiskDeveloperUILink({
nodeId: NodeId,
pDiskId: PDiskId,
database,
});

pdiskData.push({
Expand All @@ -92,12 +95,13 @@ interface PDiskPopupProps {
}

export const PDiskPopup = ({data}: PDiskPopupProps) => {
const database = useDatabaseFromQuery();
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const nodesMap = useTypedSelector(selectNodesMap);
const nodeData = valueIsDefined(data.NodeId) ? nodesMap?.get(data.NodeId) : undefined;
const info = React.useMemo(
() => preparePDiskData(data, nodeData, isUserAllowedToMakeChanges),
[data, nodeData, isUserAllowedToMakeChanges],
() => preparePDiskData(data, nodeData, isUserAllowedToMakeChanges, database),
[data, nodeData, isUserAllowedToMakeChanges, database],
);

return <InfoViewer title="PDisk" info={info} size="s" />;
Expand Down
7 changes: 4 additions & 3 deletions src/components/TabletNameWrapper/TabletNameWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {DefinitionList, PopoverBehavior} from '@gravity-ui/uikit';

import {getTabletPagePath} from '../../routes';
import {createTabletDeveloperUIHref} from '../../utils/developerUI/developerUI';
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {CellWithPopover} from '../CellWithPopover/CellWithPopover';
import {EntityStatus} from '../EntityStatus/EntityStatus';
Expand All @@ -11,11 +12,11 @@ import i18n from './i18n';

interface TabletNameWrapperProps {
tabletId: string | number;
database?: string;
}

export function TabletNameWrapper({tabletId, database}: TabletNameWrapperProps) {
export function TabletNameWrapper({tabletId}: TabletNameWrapperProps) {
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const database = useDatabaseFromQuery();

const tabletPath = getTabletPagePath(tabletId, {database});

Expand All @@ -28,7 +29,7 @@ export function TabletNameWrapper({tabletId, database}: TabletNameWrapperProps)
<DefinitionList.Item name={i18n('field_links')}>
<LinkWithIcon
title={i18n('context_developer-ui')}
url={createTabletDeveloperUIHref(tabletId)}
url={createTabletDeveloperUIHref(tabletId, database)}
/>
</DefinitionList.Item>
</DefinitionList>
Expand Down
4 changes: 3 additions & 1 deletion src/components/VDisk/VDisk.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {cn} from '../../utils/cn';
import type {PreparedVDisk} from '../../utils/disks/types';
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
import {DiskStateProgressBar} from '../DiskStateProgressBar/DiskStateProgressBar';
import {HoverPopup} from '../HoverPopup/HoverPopup';
import {InternalLink} from '../InternalLink';
Expand Down Expand Up @@ -34,7 +35,8 @@ export const VDisk = ({
delayClose,
delayOpen,
}: VDiskProps) => {
const vDiskPath = getVDiskLink(data);
const database = useDatabaseFromQuery();
const vDiskPath = getVDiskLink(data, database);

return (
<HoverPopup
Expand Down
5 changes: 3 additions & 2 deletions src/components/VDisk/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {valueIsDefined} from '../../utils';
import {stringifyVdiskId} from '../../utils/dataFormatters/dataFormatters';
import {isFullVDiskData} from '../../utils/disks/helpers';

export function getVDiskLink(data: TVDiskStateInfo | TVSlotId) {
export function getVDiskLink(data: TVDiskStateInfo | TVSlotId, database?: string) {
let vDiskPath: string | undefined;

const isFullData = isFullVDiskData(data);
Expand All @@ -16,13 +16,14 @@ export function getVDiskLink(data: TVDiskStateInfo | TVSlotId) {
valueIsDefined(data.PDiskId) &&
valueIsDefined(data.NodeId)
) {
vDiskPath = getVDiskPagePath(VDiskSlotId, data.PDiskId, data.NodeId);
vDiskPath = getVDiskPagePath(VDiskSlotId, data.PDiskId, data.NodeId, {database});
} else if (valueIsDefined(data.NodeId) && isFullVDiskData(data)) {
vDiskPath = getDefaultNodePath(
data.NodeId,
{
pdiskId: data.PDiskId?.toString(),
vdiskId: stringifyVdiskId(data.VDiskId),
database,
},
'structure',
);
Expand Down
5 changes: 4 additions & 1 deletion src/components/VDiskInfo/VDiskInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters
import {createVDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import {getSeverityColor} from '../../utils/disks/helpers';
import type {PreparedVDisk} from '../../utils/disks/types';
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {bytesToSpeed} from '../../utils/utils';
import {InfoViewer} from '../InfoViewer';
Expand Down Expand Up @@ -35,6 +36,7 @@ export function VDiskInfo<T extends PreparedVDisk>({
...infoViewerProps
}: VDiskInfoProps<T>) {
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const database = useDatabaseFromQuery();

const {
AllocatedSize,
Expand Down Expand Up @@ -152,7 +154,7 @@ export function VDiskInfo<T extends PreparedVDisk>({
const links: React.ReactNode[] = [];

if (withVDiskPageLink) {
const vDiskPagePath = getVDiskPagePath(VDiskSlotId, PDiskId, NodeId);
const vDiskPagePath = getVDiskPagePath(VDiskSlotId, PDiskId, NodeId, {database});
links.push(
<LinkWithIcon
key={vDiskPagePath}
Expand All @@ -168,6 +170,7 @@ export function VDiskInfo<T extends PreparedVDisk>({
nodeId: NodeId,
pDiskId: PDiskId,
vDiskSlotId: VDiskSlotId,
database,
});

links.push(
Expand Down
32 changes: 24 additions & 8 deletions src/components/VDiskPopup/VDiskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {createVDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
import {isFullVDiskData} from '../../utils/disks/helpers';
import type {PreparedVDisk, UnavailableDonor} from '../../utils/disks/types';
import {useTypedSelector} from '../../utils/hooks';
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {bytesToGB, bytesToSpeed} from '../../utils/utils';
import type {InfoViewerItem} from '../InfoViewer';
Expand All @@ -24,7 +25,11 @@ import './VDiskPopup.scss';

const b = cn('vdisk-storage-popup');

const prepareUnavailableVDiskData = (data: UnavailableDonor, withDeveloperUILink?: boolean) => {
const prepareUnavailableVDiskData = (
data: UnavailableDonor,
withDeveloperUILink?: boolean,
database?: string,
) => {
const {NodeId, PDiskId, VSlotId, StoragePoolName} = data;

const vdiskData: InfoViewerItem[] = [{label: 'State', value: 'not available'}];
Expand All @@ -49,6 +54,7 @@ const prepareUnavailableVDiskData = (data: UnavailableDonor, withDeveloperUILink
nodeId: NodeId,
pDiskId: PDiskId,
vDiskSlotId: VSlotId,
database,
});

vdiskData.push({
Expand All @@ -61,7 +67,11 @@ const prepareUnavailableVDiskData = (data: UnavailableDonor, withDeveloperUILink
};

// eslint-disable-next-line complexity
const prepareVDiskData = (data: PreparedVDisk, withDeveloperUILink?: boolean) => {
const prepareVDiskData = (
data: PreparedVDisk,
withDeveloperUILink?: boolean,
database?: string,
) => {
const {
NodeId,
PDiskId,
Expand Down Expand Up @@ -160,6 +170,7 @@ const prepareVDiskData = (data: PreparedVDisk, withDeveloperUILink?: boolean) =>
nodeId: NodeId,
pDiskId: PDiskId,
vDiskSlotId: VDiskSlotId,
database,
});

vdiskData.push({
Expand All @@ -176,16 +187,17 @@ interface VDiskPopupProps {
}

export const VDiskPopup = ({data}: VDiskPopupProps) => {
const database = useDatabaseFromQuery();
const isFullData = isFullVDiskData(data);

const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();

const vdiskInfo = React.useMemo(
() =>
isFullData
? prepareVDiskData(data, isUserAllowedToMakeChanges)
: prepareUnavailableVDiskData(data, isUserAllowedToMakeChanges),
[data, isFullData, isUserAllowedToMakeChanges],
? prepareVDiskData(data, isUserAllowedToMakeChanges, database)
: prepareUnavailableVDiskData(data, isUserAllowedToMakeChanges, database),
[data, isFullData, isUserAllowedToMakeChanges, database],
);

const nodesMap = useTypedSelector(selectNodesMap);
Expand All @@ -194,8 +206,8 @@ export const VDiskPopup = ({data}: VDiskPopupProps) => {
() =>
isFullData &&
data.PDisk &&
preparePDiskData(data.PDisk, nodeData, isUserAllowedToMakeChanges),
[data, nodeData, isFullData, isUserAllowedToMakeChanges],
preparePDiskData(data.PDisk, nodeData, isUserAllowedToMakeChanges, database),
[data, nodeData, isFullData, isUserAllowedToMakeChanges, database],
);

const donorsInfo: InfoViewerItem[] = [];
Expand All @@ -204,7 +216,11 @@ export const VDiskPopup = ({data}: VDiskPopupProps) => {
for (const donor of donors) {
donorsInfo.push({
label: 'VDisk',
value: <InternalLink to={getVDiskLink(donor)}>{donor.StringifiedId}</InternalLink>,
value: (
<InternalLink to={getVDiskLink(donor, database)}>
{donor.StringifiedId}
</InternalLink>
),
});
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/containers/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ function Header({mainPage}: HeaderProps) {

if (isUserAllowedToMakeChanges) {
elements.push(
<Button view="flat" href={createDeveloperUIInternalPageHref()} target="_blank">
<Button
view="flat"
href={createDeveloperUIInternalPageHref(undefined, database)}
target="_blank"
>
{DEVELOPER_UI_TITLE}
<Icon data={ArrowUpRightFromSquare} />
</Button>,
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function Node() {

const [autoRefreshInterval] = useAutoRefreshInterval();

const params = nodeId ? {nodeId} : skipToken;
const params = nodeId ? {nodeId, database: tenantNameFromQuery?.toString()} : skipToken;
const {
currentData: node,
isLoading,
Expand Down
10 changes: 7 additions & 3 deletions src/containers/PDiskPage/PDiskPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {valueIsDefined} from '../../utils';
import {cn} from '../../utils/cn';
import {getPDiskId, getSeverityColor} from '../../utils/disks/helpers';
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {PaginatedStorage} from '../Storage/PaginatedStorage';

Expand Down Expand Up @@ -65,6 +66,8 @@ export function PDiskPage() {
const newDiskApiAvailable = useDiskPagesAvailable();
const containerRef = React.useRef<HTMLDivElement>(null);

const database = useDatabaseFromQuery();

const [{nodeId, pDiskId, activeTab}] = useQueryParams({
activeTab: StringParam,
nodeId: StringParam,
Expand All @@ -80,7 +83,7 @@ export function PDiskPage() {
}, [dispatch, nodeId, pDiskId]);

const [autoRefreshInterval] = useAutoRefreshInterval();
const params = pDiskParamsDefined ? {nodeId, pDiskId} : skipToken;
const params = pDiskParamsDefined ? {nodeId, pDiskId, database} : skipToken;
const pdiskDataQuery = pDiskApi.useGetPdiskInfoQuery(params, {
pollingInterval: autoRefreshInterval,
});
Expand Down Expand Up @@ -222,7 +225,7 @@ export function PDiskPage() {
activeTab={pDiskTab}
wrapTo={({id}, tabNode) => {
const path = pDiskParamsDefined
? getPDiskPagePath(pDiskId, nodeId, {activeTab: id})
? getPDiskPagePath(pDiskId, nodeId, {activeTab: id, database})
: undefined;
return (
<InternalLink to={path} key={id}>
Expand All @@ -240,13 +243,14 @@ export function PDiskPage() {
case 'spaceDistribution': {
return pDiskData ? (
<div className={pdiskPageCn('disk-distribution')}>
<PDiskSpaceDistribution data={pDiskData} />
<PDiskSpaceDistribution data={pDiskData} database={database} />
</div>
) : null;
}
case 'storage': {
return pDiskParamsDefined ? (
<PaginatedStorage
database={database}
nodeId={nodeId}
pDiskId={pDiskId}
parentRef={containerRef}
Expand Down
Loading