Skip to content

Commit 9ba6997

Browse files
committed
fix: fixup
1 parent 250661a commit 9ba6997

File tree

7 files changed

+54
-36
lines changed

7 files changed

+54
-36
lines changed

src/containers/Tenant/Diagnostics/TopQueries/RunningQueriesData.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ const RUNNING_QUERIES_COLUMNS_WIDTH_LS_KEY = 'runningQueriesColumnsWidth';
2323

2424
const columns: Column<KeyValueRow>[] = [
2525
{
26-
name: 'UserSID',
27-
header: 'User',
26+
name: 'user',
27+
header: i18n('col_user'),
2828
render: ({row}) => row.UserSID || '-',
2929
sortable: false,
3030
},
3131
{
32-
name: 'QueryStartAt',
33-
header: 'Start time',
32+
name: 'startTime',
33+
header: i18n('col_start-time'),
3434
render: ({row}) => formatDateTime(new Date(row.QueryStartAt as string).getTime()),
3535
sortable: false,
3636
},
3737
{
38-
name: 'Query',
39-
headerTitle: 'Query text',
38+
name: 'queryText',
39+
header: i18n('col_query-text'),
4040
render: ({row}) => (
4141
<div className={b('query')}>
4242
<TruncatedQuery value={row.Query?.toString()} maxQueryHeight={MAX_QUERY_HEIGHT} />
@@ -46,8 +46,8 @@ const columns: Column<KeyValueRow>[] = [
4646
sortable: false,
4747
},
4848
{
49-
name: 'ApplicationName',
50-
header: 'Application',
49+
name: 'app',
50+
header: i18n('col_app'),
5151
render: ({row}) => row.ApplicationName || '-',
5252
sortable: false,
5353
},
@@ -68,19 +68,16 @@ export const RunningQueriesData = ({database}: Props) => {
6868
{pollingInterval: autoRefreshInterval},
6969
);
7070

71-
console.log(data);
72-
console.log(error);
73-
7471
return (
7572
<TableWithControlsLayout.Table loading={isFetching}>
7673
{error ? (
77-
<ResponseError error={error?.error} />
74+
<ResponseError error={error} />
7875
) : (
7976
<ResizeableDataTable
8077
emptyDataMessage={i18n('no-data')}
8178
columnsWidthLSKey={RUNNING_QUERIES_COLUMNS_WIDTH_LS_KEY}
8279
columns={columns}
83-
data={data}
80+
data={data || []}
8481
settings={QUERY_TABLE_SETTINGS}
8582
/>
8683
)}

src/containers/Tenant/Diagnostics/TopQueries/TopQueries.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@include search();
1313
}
1414

15-
tr {
15+
&__row {
1616
cursor: pointer;
1717
}
1818

src/containers/Tenant/Diagnostics/TopQueries/TopQueries.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import './TopQueries.scss';
3030

3131
const b = cn('kv-top-queries');
3232

33+
const QUERY_MODE_OPTIONS: RadioButtonOption[] = [
34+
{value: 'top', content: i18n('mode_top')},
35+
{value: 'running', content: i18n('mode_running')},
36+
];
37+
3338
interface TopQueriesProps {
3439
tenantName: string;
3540
type?: EPathType;
@@ -45,10 +50,8 @@ export const TopQueries = ({tenantName, type}: TopQueriesProps) => {
4550

4651
const filters = useTypedSelector((state) => state.executeTopQueries);
4752

48-
const handleRowClick = React.useCallback(
49-
(row: any) => {
50-
const {QueryText: input} = row;
51-
53+
const onRowClick = React.useCallback(
54+
(input: string) => {
5255
dispatch(changeUserInput({input}));
5356

5457
const queryParams = parseQuery(location);
@@ -72,22 +75,21 @@ export const TopQueries = ({tenantName, type}: TopQueriesProps) => {
7275
dispatch(setTopQueriesFilters(value));
7376
};
7477

75-
const options: RadioButtonOption[] = [
76-
{value: 'top', content: 'Top'},
77-
{value: 'running', content: 'Running'},
78-
];
79-
8078
return (
8179
<TableWithControlsLayout>
8280
<TableWithControlsLayout.Controls>
83-
<RadioButton options={options} value={queryMode} onUpdate={setQueryMode} />
81+
<RadioButton
82+
options={QUERY_MODE_OPTIONS}
83+
value={queryMode}
84+
onUpdate={setQueryMode}
85+
/>
8486
<Search
8587
value={filters.text}
8688
onChange={handleTextSearchUpdate}
8789
placeholder={i18n('filter.text.placeholder')}
8890
className={b('search')}
8991
/>
90-
{queryMode === 'top' ? (
92+
{isTopQueries ? (
9193
<DateRange
9294
from={filters.from}
9395
to={filters.to}
@@ -96,7 +98,7 @@ export const TopQueries = ({tenantName, type}: TopQueriesProps) => {
9698
) : null}
9799
</TableWithControlsLayout.Controls>
98100
{isTopQueries ? (
99-
<TopQueriesData database={tenantName} type={type} onRowClick={handleRowClick} />
101+
<TopQueriesData database={tenantName} type={type} onRowClick={onRowClick} />
100102
) : (
101103
<RunningQueriesData database={tenantName} />
102104
)}

src/containers/Tenant/Diagnostics/TopQueries/TopQueriesData.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import {ResponseError} from '../../../../components/Errors/ResponseError';
22
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
33
import {TableWithControlsLayout} from '../../../../components/TableWithControlsLayout/TableWithControlsLayout';
44
import {topQueriesApi} from '../../../../store/reducers/executeTopQueries/executeTopQueries';
5+
import type {KeyValueRow} from '../../../../types/api/query';
56
import type {EPathType} from '../../../../types/api/schema';
7+
import {cn} from '../../../../utils/cn';
68
import {isSortableTopQueriesProperty} from '../../../../utils/diagnostics';
79
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
810
import {QUERY_TABLE_SETTINGS} from '../../utils/constants';
@@ -11,6 +13,8 @@ import {isColumnEntityType} from '../../utils/schema';
1113
import {TOP_QUERIES_COLUMNS, TOP_QUERIES_COLUMNS_WIDTH_LS_KEY} from './getTopQueriesColumns';
1214
import i18n from './i18n';
1315

16+
const b = cn('kv-top-queries');
17+
1418
interface Props {
1519
database: string;
1620
onRowClick: (row: any) => void;
@@ -36,6 +40,10 @@ export const TopQueriesData = ({database, onRowClick, type}: Props) => {
3640
sortable: isSortableTopQueriesProperty(column.name),
3741
}));
3842

43+
const handleRowClick = (row: KeyValueRow) => {
44+
return onRowClick(row.QueryText as string);
45+
};
46+
3947
if (error && !data) {
4048
return (
4149
<TableWithControlsLayout.Table>
@@ -55,7 +63,8 @@ export const TopQueriesData = ({database, onRowClick, type}: Props) => {
5563
columns={columns}
5664
data={data}
5765
settings={QUERY_TABLE_SETTINGS}
58-
onRowClick={onRowClick}
66+
onRowClick={handleRowClick}
67+
rowClassName={() => b('row')}
5968
/>
6069
</TableWithControlsLayout.Table>
6170
);
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
22
"no-data": "No data",
3-
"filter.text.placeholder": "Search by query text..."
3+
"filter.text.placeholder": "Search by query text...",
4+
"mode_top": "Top",
5+
"mode_running": "Running",
6+
"col_user": "User",
7+
"col_start-time": "Start time",
8+
"col_query-text": "Query text",
9+
"col_app": "Application"
410
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
22
"no-data": "Нет данных",
3-
"filter.text.placeholder": "Искать по тексту запроса..."
3+
"filter.text.placeholder": "Искать по тексту запроса...",
4+
"mode_top": "Top",
5+
"mode_running": "Running",
6+
"col_user": "User",
7+
"col_start-time": "Start time",
8+
"col_query-text": "Query text",
9+
"col_app": "Application"
410
}

src/store/reducers/executeTopQueries/executeTopQueries.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export const topQueriesApi = api.injectEndpoints({
7070
}
7171

7272
const data = parseQueryAPIExecuteResponse(response);
73-
console.log(data);
7473
return {data};
7574
} catch (error) {
7675
return {error};
@@ -95,14 +94,14 @@ export const topQueriesApi = api.injectEndpoints({
9594
{signal},
9695
) => {
9796
try {
98-
const filterConditions = filters?.text
99-
? `QueryText ILIKE '%${filters.text}%'`
100-
: '';
97+
const filterConditions = filters?.text ? `Query ILIKE '%${filters.text}%'` : '';
98+
const queryText = `SELECT * from \`.sys/query_sessions\` WHERE ${filterConditions || 'true'} limit 10`;
10199

102100
const response = await window.api.sendQuery(
103101
{
104-
query: `SELECT * from \`.sys/query_sessions\` WHERE ${filterConditions || 'true'} limit 10`,
102+
query: queryText,
105103
database,
104+
action: 'execute-query',
106105
},
107106
{signal, withRetries: true},
108107
);
@@ -111,8 +110,7 @@ export const topQueriesApi = api.injectEndpoints({
111110
throw response;
112111
}
113112

114-
console.log(response);
115-
return {data: response};
113+
return {data: response?.result?.filter((item) => item.Query !== queryText)};
116114
} catch (error) {
117115
return {error};
118116
}

0 commit comments

Comments
 (0)