diff --git a/src/containers/Tenant/Diagnostics/TopQueries/getTopQueriesColumns.tsx b/src/containers/Tenant/Diagnostics/TopQueries/getTopQueriesColumns.tsx index c1124bf8a..64b8386c8 100644 --- a/src/containers/Tenant/Diagnostics/TopQueries/getTopQueriesColumns.tsx +++ b/src/containers/Tenant/Diagnostics/TopQueries/getTopQueriesColumns.tsx @@ -1,10 +1,10 @@ -import crc32 from 'crc-32'; import cn from 'bem-cn-lite'; 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 {generateHash} from '../../../../utils/generateHash'; import { TruncatedQuery, OneLineQueryWithPopover, @@ -81,10 +81,7 @@ const oneLineQueryTextColumn: Column = { const queryHashColumn: Column = { name: TOP_QUERIES_COLUMNS_IDS.QueryHash, - render: ({row}) => - // We use unsigned right shift operator (>>>) to avoid negative values - // eslint-disable-next-line no-bitwise - (crc32.str(String(row.QueryText)) >>> 0).toString(16).toUpperCase().padStart(8, '0'), + render: ({row}) => generateHash(String(row.QueryText)), width: 130, sortable: false, }; diff --git a/src/utils/generateHash.ts b/src/utils/generateHash.ts new file mode 100644 index 000000000..cf20d6e5b --- /dev/null +++ b/src/utils/generateHash.ts @@ -0,0 +1,11 @@ +import crc32 from 'crc-32'; + +export const generateHash = (value: string) => { + // 1. crc32.str(value) - generate crc32 hash + // 2. (>>>) - use unsigned right shift operator (>>>) to avoid negative values + // 3. toString(16) - convert hash to hex format + // 4. toUpperCase() - convert hash to uppercase + // 5. padStart(8, '0') - fill hash with leading zeros if hash length < 8 + // eslint-disable-next-line no-bitwise + return (crc32.str(value) >>> 0).toString(16).toUpperCase().padStart(8, '0'); +};