Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Transforms: Fix tab ids for expanded row. #80666

Merged
merged 4 commits into from
Oct 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,9 +179,11 @@ export const ExpandedRow: FC<Props> = ({ item }) => {
position: 'left',
};

const tabId = stringHash(item.id);

const tabs = [
{
id: `transform-details-tab-${item.id}`,
id: `transform-details-tab-${tabId}`,
'data-test-subj': 'transformDetailsTab',
name: i18n.translate(
'xpack.transform.transformList.transformDetails.tabs.transformDetailsLabel',
Expand All @@ -175,7 +194,7 @@ export const ExpandedRow: FC<Props> = ({ item }) => {
content: <ExpandedRowDetailsPane sections={[general, state, checkpointing]} />,
},
{
id: `transform-stats-tab-${item.id}`,
id: `transform-stats-tab-${tabId}`,
'data-test-subj': 'transformStatsTab',
name: i18n.translate(
'xpack.transform.transformList.transformDetails.tabs.transformStatsLabel',
Expand All @@ -186,13 +205,13 @@ export const ExpandedRow: FC<Props> = ({ item }) => {
content: <ExpandedRowDetailsPane sections={[stats]} />,
},
{
id: `transform-json-tab-${item.id}`,
id: `transform-json-tab-${tabId}`,
'data-test-subj': 'transformJsonTab',
name: 'JSON',
content: <ExpandedRowJsonPane json={item.config} />,
},
{
id: `transform-messages-tab-${item.id}`,
id: `transform-messages-tab-${tabId}`,
'data-test-subj': 'transformMessagesTab',
name: i18n.translate(
'xpack.transform.transformList.transformDetails.tabs.transformMessagesLabel',
Expand All @@ -203,7 +222,7 @@ export const ExpandedRow: FC<Props> = ({ item }) => {
content: <ExpandedRowMessagesPane transformId={item.id} />,
},
{
id: `transform-preview-tab-${item.id}`,
id: `transform-preview-tab-${tabId}`,
'data-test-subj': 'transformPreviewTab',
name: i18n.translate(
'xpack.transform.transformList.transformDetails.tabs.transformPreviewLabel',
Expand Down