Skip to content

Commit 742c58a

Browse files
committed
fix: code-review
1 parent 3ba4c25 commit 742c58a

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed

src/containers/Tenant/Diagnostics/HotKeys/HotKeys.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import Icon from '../../../../components/Icon/Icon';
88

99
import {AutoFetcher} from '../../../../utils/autofetcher';
1010
import {getHotKeys, setHotKeysOptions} from '../../../../store/reducers/hotKeys';
11+
import {TABLE_TYPE} from '../../Tenant';
12+
import {prepareQueryError} from '../../../../utils';
1113

1214
import './HotKeys.scss';
13-
import {TABLE_TYPE} from '../../Tenant';
1415

1516
const b = cn('hot-keys');
1617

@@ -105,7 +106,7 @@ function HotKeys({
105106

106107
const renderContent = () => {
107108
if (error) {
108-
return error.data?.error?.message || error.data || error;
109+
return prepareQueryError(error);
109110
}
110111
return data !== null ? (
111112
<div className={b('table-content')}>

src/containers/Tenant/Diagnostics/TopQueries/TopQueries.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import PropTypes from 'prop-types';
33
import cn from 'bem-cn-lite';
44
import {connect} from 'react-redux';
55
import DataTable from '@yandex-cloud/react-data-table';
6+
import {Loader} from '@yandex-cloud/uikit';
67

78
import {changeUserInput} from '../../../../store/reducers/executeQuery';
89
import {sendQuery, setQueryOptions} from '../../../../store/reducers/executeTopQueries';
910
import TruncatedQuery from '../../../../components/TruncatedQuery/TruncatedQuery';
1011
import {AutoFetcher} from '../../../../utils/autofetcher';
1112
import {OLAP_STORE_TYPE, OLAP_TABLE_TYPE} from '../../Tenant';
1213

13-
import './TopQueries.scss';
1414
import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants';
1515
import {TenantGeneralTabsIds} from '../../TenantPages';
16-
import {Loader} from '@yandex-cloud/uikit';
16+
import {prepareQueryError} from '../../../../utils';
1717

18+
import './TopQueries.scss';
1819

1920
const b = cn('kv-top-queries');
2021

@@ -151,7 +152,7 @@ class TopQueries extends React.Component {
151152
if (type === OLAP_STORE_TYPE || type === OLAP_TABLE_TYPE) {
152153
message = 'No data';
153154
} else if (error && !error.isCancelled) {
154-
message = (error.data?.error?.message || error.data || error).slice(0, 300);
155+
message = prepareQueryError(error).slice(0, 300);
155156
} else if (!loading && !data) {
156157
message = 'No data';
157158
}

src/containers/Tenant/Diagnostics/TopShards/TopShards.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import {useContext, useEffect, useMemo} from 'react';
22
import cn from 'bem-cn-lite';
33
import {connect} from 'react-redux';
4-
import InternalLink from '../../../../components/InternalLink/InternalLink';
4+
import {Loader} from '@yandex-cloud/uikit';
55
import DataTable from '@yandex-cloud/react-data-table';
6-
import routes, {createHref} from '../../../../routes';
76

7+
import InternalLink from '../../../../components/InternalLink/InternalLink';
8+
9+
import routes, {createHref} from '../../../../routes';
810
import {sendShardQuery, setShardQueryOptions} from '../../../../store/reducers/shardsWorkload';
911
import {setCurrentSchemaPath, getSchema} from '../../../../store/reducers/schema';
1012
import {AutoFetcher} from '../../../../utils/autofetcher';
11-
1213
import HistoryContext from '../../../../contexts/HistoryContext';
13-
14-
import './TopShards.scss';
1514
import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants';
16-
import {Loader} from '@yandex-cloud/uikit';
1715
import {OLAP_STORE_TYPE, OLAP_TABLE_TYPE} from '../../Tenant';
16+
import {prepareQueryError} from '../../../../utils';
17+
18+
import './TopShards.scss';
1819

1920
const b = cn('top-shards');
2021
const bLink = cn('yc-link');
@@ -123,7 +124,7 @@ function TopShards({
123124
return 'No data';
124125
}
125126
if (error) {
126-
return error.data?.error?.message || error.data || error;
127+
return prepareQueryError(error);
127128
}
128129

129130
return data && data.length > 0 ? (

src/containers/Tenant/Preview/Preview.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Fullscreen from '../../../components/Fullscreen/Fullscreen';
1111

1212
import {sendQuery, setQueryOptions} from '../../../store/reducers/preview';
1313
import {showTooltip, hideTooltip} from '../../../store/reducers/tooltip';
14-
import {prepareQueryResponse} from '../../../utils/index';
14+
import {prepareQueryError, prepareQueryResponse} from '../../../utils/index';
1515

1616
import {OLAP_TABLE_TYPE, TABLE_TYPE} from '../Tenant';
1717
import {AutoFetcher} from '../../../utils/autofetcher';
@@ -163,11 +163,7 @@ class Preview extends React.Component {
163163
}
164164

165165
if (error) {
166-
message = (
167-
<div className={b('message-container')}>
168-
{error.data?.error?.message || error.data || error}
169-
</div>
170-
);
166+
message = <div className={b('message-container')}>{prepareQueryError(error)}</div>;
171167
}
172168

173169
if (!loading && data.length === 0) {

src/containers/Tenant/QueryEditor/Issues/Issues.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export default function ResultIssues({data, className}: ResultIssuesProps) {
4040
const severity = getSeverity(data?.error?.severity);
4141
content = (
4242
<React.Fragment>
43-
<IssueSeverity severity={severity} /> <span className={blockWrapper('error-message-text')}>{data?.error?.message}</span>
43+
<IssueSeverity severity={severity} />{' '}
44+
<span className={blockWrapper('error-message-text')}>
45+
{data?.error?.message}
46+
</span>
4447
</React.Fragment>
4548
);
4649
}
@@ -71,9 +74,9 @@ interface IssuesProps {
7174
}
7275
export function Issues({issues, className}: IssuesProps) {
7376
const mostSevereIssue = issues.reduce((result, issue) => {
74-
const severity = issue.severity ? issue.severity : 10;
75-
return result < severity ? result : severity;
76-
}, issues[0].severity ?? 10);
77+
const severity = issue.severity ?? 10;
78+
return Math.min(result, severity);
79+
}, 10);
7780
return (
7881
<div className={blockIssues(null, className)}>
7982
{issues.map((issue, index) => (

src/utils/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,7 @@ export const prepareQueryResponse = (data) => {
138138
return formattedData;
139139
});
140140
};
141+
142+
export function prepareQueryError(error) {
143+
return error.data?.error?.message || error.data || error
144+
}

0 commit comments

Comments
 (0)