Skip to content

Commit a458c8f

Browse files
authored
feat: restrictions for not IsViewerUser (#2684)
1 parent 633b184 commit a458c8f

File tree

42 files changed

+451
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+451
-325
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export default [
4646
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
4747
curly: ['error', 'all'],
4848
'react-hooks/exhaustive-deps': 'warn',
49+
'react-hooks/rules-of-hooks': 'error',
4950
},
5051
},
5152
// TypeScript-specific rules that require type information

src/components/ErrorBoundary/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function getBackendVersion() {
2424
// node_id=. returns data about node that fullfills request
2525
// normally this request should be fast (200-300ms with good connection)
2626
// timeout=1000 in order not to wait too much in case everything is broken
27-
const data = await window.api.viewer.getNodeInfo('.', {timeout: 1000});
27+
const data = await window.api.viewer.getNodeInfo({nodeId: '.'}, {timeout: 1000});
2828
return data?.SystemStateInfo?.[0]?.Version;
2929
} catch (error) {
3030
return {error: prepareErrorMessage(error)};

src/components/NodeId/NodeId.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {getDefaultNodePath} from '../../containers/Node/NodePages';
2+
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
3+
import {InternalLink} from '../InternalLink';
4+
5+
interface NodeIdProps {
6+
id: string | number;
7+
}
8+
9+
export function NodeId({id}: NodeIdProps) {
10+
const database = useDatabaseFromQuery();
11+
return <InternalLink to={getDefaultNodePath(id, {database})}>{id}</InternalLink>;
12+
}

src/components/PDiskPopup/PDiskPopup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
1010
import {createPDiskDeveloperUILink} from '../../utils/developerUI/developerUI';
1111
import type {PreparedPDisk} from '../../utils/disks/types';
1212
import {useTypedSelector} from '../../utils/hooks';
13+
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
1314
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
1415
import {bytesToGB, isNumeric} from '../../utils/utils';
1516
import {InfoViewer} from '../InfoViewer';
@@ -109,8 +110,9 @@ interface PDiskPopupProps {
109110
}
110111

111112
export const PDiskPopup = ({data}: PDiskPopupProps) => {
113+
const database = useDatabaseFromQuery();
112114
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
113-
const nodesMap = useTypedSelector(selectNodesMap);
115+
const nodesMap = useTypedSelector((state) => selectNodesMap(state, database));
114116
const nodeData = valueIsDefined(data.NodeId) ? nodesMap?.get(data.NodeId) : undefined;
115117
const info = React.useMemo(
116118
() => preparePDiskData(data, nodeData, isUserAllowedToMakeChanges),

src/components/ProgressWrapper/SingleProgress.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ export function SingleProgress({
2525
size = PROGRESS_SIZE,
2626
withCapacityUsage = false,
2727
}: ProgressWrapperSingleProps) {
28-
if (!isValidValue(value)) {
29-
return <div className={className}>{i18n('alert_no-data')}</div>;
30-
}
31-
3228
const numericValue = safeParseNumber(value);
3329
const numericCapacity = safeParseNumber(capacity);
3430
const clampedFillWidth = calculateProgressWidth(numericValue, numericCapacity);
@@ -41,6 +37,10 @@ export function SingleProgress({
4137
return formatProgressText(valueText, capacityText, numericCapacity);
4238
}, [valueText, capacityText, numericCapacity]);
4339

40+
if (!isValidValue(value)) {
41+
return <div className={className}>{i18n('alert_no-data')}</div>;
42+
}
43+
4444
return (
4545
<ProgressContainer
4646
displayText={displayText}

src/components/ProgressWrapper/StackProgress.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ export function StackProgress({
2929
return stack.filter((segment) => !segment.isInfo && segment.value > 0);
3030
}, [stack]);
3131

32-
if (displaySegments.length === 0) {
33-
return <div className={className}>{i18n('alert_no-data')}</div>;
34-
}
35-
3632
const totalValue = React.useMemo(() => {
3733
return displaySegments.reduce((sum, segment) => sum + segment.value, 0);
3834
}, [displaySegments]);
@@ -59,6 +55,10 @@ export function StackProgress({
5955
return formatProgressText(totalValueText, totalCapacityText, numericTotalCapacity || 0);
6056
}, [totalValueText, totalCapacityText, numericTotalCapacity]);
6157

58+
if (displaySegments.length === 0) {
59+
return <div className={className}>{i18n('alert_no-data')}</div>;
60+
}
61+
6262
return (
6363
<ProgressContainer
6464
displayText={displayText}

src/components/QueriesActivityBar/QueriesActivityCharts.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ export function QueriesActivityCharts({
3838
const queriesChartConfig = getChartByTarget('queries.requests');
3939
const latenciesChartConfig = getChartByTarget('queries.latencies.p99');
4040

41-
// Early return if required charts are not found
42-
if (!queriesChartConfig || !latenciesChartConfig) {
43-
console.warn('Required chart configurations not found in defaultDashboardConfig');
44-
return null;
45-
}
46-
4741
// Refetch data only if charts have successfully loaded at least once
4842
const shouldRefresh = hasChartsLoaded ? autoRefreshInterval : 0;
4943

@@ -58,6 +52,12 @@ export function QueriesActivityCharts({
5852
[onChartDataStatusChange],
5953
);
6054

55+
// Early return if required charts are not found
56+
if (!queriesChartConfig || !latenciesChartConfig) {
57+
console.warn('Required chart configurations not found in defaultDashboardConfig');
58+
return null;
59+
}
60+
6161
// WORKAROUND: Charts are rendered outside Disclosure component due to YAGR tooltip bug
6262
// Issue: https://github.com/gravity-ui/yagr/issues/262
6363

src/components/ShardsTable/columns.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import DataTable from '@gravity-ui/react-data-table';
22

3-
import {getDefaultNodePath} from '../../containers/Node/NodePages';
43
import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants';
54
import {formatNumber, roundToPrecision} from '../../utils/dataFormatters/dataFormatters';
65
import {getUsageSeverity} from '../../utils/generateEvaluator';
7-
import {InternalLink} from '../InternalLink';
86
import {LinkToSchemaObject} from '../LinkToSchemaObject/LinkToSchemaObject';
7+
import {NodeId} from '../NodeId/NodeId';
98
import {TabletNameWrapper} from '../TabletNameWrapper/TabletNameWrapper';
109
import {UsageLabel} from '../UsageLabel/UsageLabel';
1110

@@ -39,7 +38,7 @@ export const getDataSizeColumn: GetShardsColumn = () => {
3938
align: DataTable.RIGHT,
4039
};
4140
};
42-
export const getTabletIdColumn: GetShardsColumn = () => {
41+
export const getTabletIdColumn: GetShardsColumn = ({database}) => {
4342
return {
4443
name: TOP_SHARDS_COLUMNS_IDS.TabletId,
4544
header: TOP_SHARDS_COLUMNS_TITLES.TabletId,
@@ -51,6 +50,7 @@ export const getTabletIdColumn: GetShardsColumn = () => {
5150
<TabletNameWrapper
5251
tabletId={row.TabletId}
5352
followerId={row.FollowerId || undefined}
53+
database={database}
5454
/>
5555
);
5656
},
@@ -65,7 +65,7 @@ export const getNodeIdColumn: GetShardsColumn = () => {
6565
if (!row.NodeId) {
6666
return EMPTY_DATA_PLACEHOLDER;
6767
}
68-
return <InternalLink to={getDefaultNodePath(row.NodeId)}>{row.NodeId}</InternalLink>;
68+
return <NodeId id={row.NodeId} />;
6969
},
7070
align: DataTable.RIGHT,
7171
};

src/components/VDisk/VDisk.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {cn} from '../../utils/cn';
22
import type {PreparedVDisk} from '../../utils/disks/types';
3+
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
34
import {DiskStateProgressBar} from '../DiskStateProgressBar/DiskStateProgressBar';
45
import {HoverPopup} from '../HoverPopup/HoverPopup';
56
import {InternalLink} from '../InternalLink';
@@ -34,7 +35,10 @@ export const VDisk = ({
3435
delayClose,
3536
delayOpen,
3637
}: VDiskProps) => {
37-
const vDiskPath = getVDiskLink(data);
38+
const database = useDatabaseFromQuery();
39+
const vDiskPath = getVDiskLink(data, {
40+
database: database,
41+
});
3842

3943
return (
4044
<HoverPopup

src/components/VDisk/utils.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
import {getVDiskPagePath} from '../../routes';
2-
import {valueIsDefined} from '../../utils';
32
import type {PreparedVDisk} from '../../utils/disks/types';
43

5-
export function getVDiskLink(data: PreparedVDisk) {
6-
let vDiskPath: string | undefined;
7-
8-
if (
9-
valueIsDefined(data.VDiskSlotId) &&
10-
valueIsDefined(data.PDiskId) &&
11-
valueIsDefined(data.NodeId)
12-
) {
13-
vDiskPath = getVDiskPagePath({
14-
vDiskSlotId: data.VDiskSlotId,
15-
pDiskId: data.PDiskId,
4+
export function getVDiskLink(data: PreparedVDisk, query: {database: string | undefined}) {
5+
if (!data.StringifiedId) {
6+
return undefined;
7+
}
8+
return getVDiskPagePath(
9+
{
1610
nodeId: data.NodeId,
1711
vDiskId: data.StringifiedId,
18-
});
19-
} else if (valueIsDefined(data.StringifiedId)) {
20-
vDiskPath = getVDiskPagePath({
21-
vDiskId: data.StringifiedId,
22-
pDiskId: data.PDiskId,
23-
nodeId: data.NodeId,
24-
});
25-
}
26-
27-
return vDiskPath;
12+
},
13+
query,
14+
);
2815
}

0 commit comments

Comments
 (0)