Skip to content

Commit

Permalink
fix: fix top queries table row height
Browse files Browse the repository at this point in the history
  • Loading branch information
krosy1337 committed Oct 19, 2023
1 parent 3048f84 commit 152aad3
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 16 deletions.
13 changes: 13 additions & 0 deletions src/components/CellWithPopover/CellWithPopover.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.ydb-cell-with-popover {
display: inline-block;
overflow: hidden;

max-width: 100%;

white-space: nowrap;
text-overflow: ellipsis;

&__wrapper {
display: flex;
}
}
17 changes: 17 additions & 0 deletions src/components/CellWithPopover/CellWithPopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import cn from 'bem-cn-lite';

import {Popover, type PopoverProps} from '@gravity-ui/uikit';

import './CellWithPopover.scss';

const b = cn('ydb-cell-with-popover');

export function CellWithPopover({children, className, ...props}: PopoverProps) {
return (
<div className={b('wrapper')}>
<Popover className={b(null, className)} {...props}>
{children}
</Popover>
</div>
);
}
20 changes: 20 additions & 0 deletions src/components/TruncatedQuery/TopQueriesTruncatedQuery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import cn from 'bem-cn-lite';

import {CellWithPopover} from '../CellWithPopover/CellWithPopover';

import './TruncatedQuery.scss';

const b = cn('kv-truncated-query');

interface TopQueriesTruncatedQueryProps {
value: string | undefined;
}

export const TopQueriesTruncatedQuery = ({value = ''}: TopQueriesTruncatedQueryProps) => {
const content = value.split('\n').slice(0, 5).join('\n');
return (
<CellWithPopover contentClassName={b('popover-content')} content={content}>
{value}
</CellWithPopover>
);
};
8 changes: 8 additions & 0 deletions src/components/TruncatedQuery/TruncatedQuery.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@
}
}
}

&__popover-content {
overflow: hidden;

max-width: 600px;

white-space: pre;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import qs from 'qs';
import {useDispatch} from 'react-redux';
import {useHistory, useLocation} from 'react-router';
import {useCallback} from 'react';
Expand All @@ -14,6 +13,7 @@ import {
} from '../../../../../store/reducers/tenantOverview/topQueries/tenantOverviewTopQueries';
import {changeUserInput} from '../../../../../store/reducers/executeQuery';
import {useAutofetcher, useTypedSelector} from '../../../../../utils/hooks';
import {parseQuery} from '../../../../../routes';
import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
import {getTenantOverviewTopQueriesColumns} from '../../TopQueries/getTopQueriesColumns';
import {TenantOverviewTableLayout} from '../TenantOverviewTableLayout';
Expand Down Expand Up @@ -55,9 +55,7 @@ export function TopQueries({path}: TopQueriesProps) {

dispatch(changeUserInput({input}));

const queryParams = qs.parse(location.search, {
ignoreQueryPrefix: true,
});
const queryParams = parseQuery(location);

const queryPath = getTenantPath({
...queryParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {useDispatch} from 'react-redux';
import cn from 'bem-cn-lite';

import DataTable, {Column} from '@gravity-ui/react-data-table';
import {Popover} from '@gravity-ui/uikit';

import {useAutofetcher, useTypedSelector} from '../../../../../utils/hooks';
import {
Expand All @@ -17,6 +16,7 @@ import type {KeyValueRow} from '../../../../../types/api/query';
import {formatBytes, getSizeWithSignificantDigits} from '../../../../../utils/bytesParsers';
import {TableSkeleton} from '../../../../../components/TableSkeleton/TableSkeleton';
import {ResponseError} from '../../../../../components/Errors/ResponseError';
import {CellWithPopover} from '../../../../../components/CellWithPopover/CellWithPopover';

import './TenantStorage.scss';

Expand Down Expand Up @@ -67,13 +67,7 @@ export function TopTables({path}: TopTablesProps) {
{
name: 'Path',
sortable: false,
render: ({row}) => (
<div className={b('cell-with-popover-wrapper')}>
<Popover className={b('cell-with-popover')} content={row.Path}>
{row.Path}
</Popover>
</div>
),
render: ({row}) => <CellWithPopover content={row.Path}>{row.Path}</CellWithPopover>,
},
];

Expand Down
8 changes: 7 additions & 1 deletion src/containers/Tenant/Diagnostics/TopQueries/TopQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {useAutofetcher, useTypedSelector} from '../../../../utils/hooks';
import {prepareQueryError} from '../../../../utils/query';
import {parseQuery} from '../../../../routes';
import {QUERY_TABLE_SETTINGS} from '../../utils/constants';
import {isSortableTopQueriesProperty} from '../../../../utils/diagnostics';
import {isColumnEntityType} from '../../utils/schema';
import {TenantTabsGroups, getTenantPath} from '../../TenantPages';
import {getTopQueriesColumns} from './getTopQueriesColumns';
Expand Down Expand Up @@ -58,7 +59,7 @@ export const TopQueries = ({path, type}: TopQueriesProps) => {
data: {result: data = undefined} = {},
filters: storeFilters,
} = useTypedSelector((state) => state.executeTopQueries);
const columns = getTopQueriesColumns();
const rawColumns = getTopQueriesColumns();

const preventFetch = useRef(false);

Expand All @@ -71,6 +72,11 @@ export const TopQueries = ({path, type}: TopQueriesProps) => {
dispatch(setTopQueriesFilters(filters));
}, [dispatch, filters]);

const columns = rawColumns.map((column) => ({
...column,
sortable: isSortableTopQueriesProperty(column.name),
}));

const setDefaultFiltersFromResponse = (responseData?: IQueryResult) => {
const intervalEnd = responseData?.result?.[0]?.IntervalEnd;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DataTable, {type Column} from '@gravity-ui/react-data-table';
import type {KeyValueRow} from '../../../../types/api/query';
import {formatDateTime, formatNumber} from '../../../../utils/dataFormatters/dataFormatters';
import {TruncatedQuery} from '../../../../components/TruncatedQuery/TruncatedQuery';
import {TopQueriesTruncatedQuery} from '../../../../components/TruncatedQuery/TopQueriesTruncatedQuery';
import {MAX_QUERY_HEIGHT} from '../../utils/constants';

import './TopQueries.scss';
Expand All @@ -18,6 +19,7 @@ const TOP_QUERIES_COLUMNS_IDS = {
ReadRows: 'ReadRows',
ReadBytes: 'ReadBytes',
UserSID: 'UserSID',
TopQueriesQueryText: 'TopQueriesQueryText',
};

const cpuTimeUsColumn: Column<KeyValueRow> = {
Expand Down Expand Up @@ -66,6 +68,12 @@ const userSIDColumn: Column<KeyValueRow> = {
align: DataTable.LEFT,
};

const topQueriesQueryTextColumn: Column<KeyValueRow> = {
name: TOP_QUERIES_COLUMNS_IDS.TopQueriesQueryText,
render: ({row}) => <TopQueriesTruncatedQuery value={row.QueryText?.toString()} />,
sortable: false,
};

export const getTopQueriesColumns = (): Column<KeyValueRow>[] => {
return [
cpuTimeUsColumn,
Expand All @@ -78,5 +86,5 @@ export const getTopQueriesColumns = (): Column<KeyValueRow>[] => {
};

export const getTenantOverviewTopQueriesColumns = (): Column<KeyValueRow>[] => {
return [queryTextColumn, cpuTimeUsColumn];
return [topQueriesQueryTextColumn, cpuTimeUsColumn];
};
16 changes: 14 additions & 2 deletions src/utils/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import {ValueOf} from '../types/common';

export const TOP_SHARDS_SORT_VALUES = {
const TOP_SHARDS_SORT_VALUES = {
CPUCores: 'CPUCores',
DataSize: 'DataSize',
} as const;

export type TopShardsSortValue = ValueOf<typeof TOP_SHARDS_SORT_VALUES>;
const TOP_QUERIES_SORT_VALUES = {
CPUTimeUs: 'CPUTimeUs',
EndTime: 'EndTime',
ReadRows: 'ReadRows',
ReadBytes: 'ReadBytes',
UserSID: 'UserSID',
} as const;

type TopShardsSortValue = ValueOf<typeof TOP_SHARDS_SORT_VALUES>;
type TopQueriesSortValue = ValueOf<typeof TOP_QUERIES_SORT_VALUES>;

export const isSortableTopShardsProperty = (value: string): value is TopShardsSortValue =>
Object.values(TOP_SHARDS_SORT_VALUES).includes(value as TopShardsSortValue);

export const isSortableTopQueriesProperty = (value: string): value is TopQueriesSortValue =>
Object.values(TOP_QUERIES_SORT_VALUES).includes(value as TopQueriesSortValue);

0 comments on commit 152aad3

Please sign in to comment.