Skip to content

Commit

Permalink
[ML] Fix ID generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Oct 16, 2020
1 parent bd22a43 commit ad1f94e
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { FC } from 'react';

import { htmlIdGenerator, EuiTabbedContent } from '@elastic/eui';
import { EuiTabbedContent } from '@elastic/eui';
import { Optional } from '@kbn/utility-types';
import { i18n } from '@kbn/i18n';

Expand All @@ -26,6 +26,23 @@ function getItemDescription(value: any) {
return value.toString();
}

/**
* Creates a deterministic number based hash out of a string.
*/
export function stringHash(str: string): number {
let hash = 0;
let chr = 0;
if (str.length === 0) {
return hash;
}
for (let i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
hash = (hash << 5) - hash + chr; // eslint-disable-line no-bitwise
hash |= 0; // eslint-disable-line no-bitwise
}
return hash < 0 ? hash * -2 : hash;
}

interface Item {
title: string;
description: any;
Expand Down Expand Up @@ -162,7 +179,7 @@ export const ExpandedRow: FC<Props> = ({ item }) => {
position: 'left',
};

const tabId = htmlIdGenerator()();
const tabId = stringHash(item.id);

const tabs = [
{
Expand Down

0 comments on commit ad1f94e

Please sign in to comment.