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

Truncate in middle for the dropdown of sorting columns in Experiment View #5022

Merged
merged 13 commits into from Nov 10, 2021
14 changes: 14 additions & 0 deletions mlflow/server/js/src/common/utils/StringUtils.js
Expand Up @@ -13,3 +13,17 @@ export const capitalizeFirstChar = (str) => {
}
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
};

export const middleTruncateKey = (str, maxLen) => {
WeichenXu123 marked this conversation as resolved.
Show resolved Hide resolved
if (str.length > maxLen) {
const firstPartLen = Math.floor((maxLen - 3) / 2);
const lastPartLen = maxLen - 3 - firstPartLen;
return (
str.substring(0, firstPartLen) +
'...' +
str.substring(str.length - lastPartLen, str.length)
);
} else {
return str;
}
};
15 changes: 14 additions & 1 deletion mlflow/server/js/src/common/utils/StringUtils.test.js
@@ -1,4 +1,8 @@
import { truncateToFirstLineWithMaxLength, capitalizeFirstChar } from './StringUtils';
import {
truncateToFirstLineWithMaxLength,
capitalizeFirstChar,
middleTruncateKey,
} from './StringUtils';

describe('truncateToFirstLineWithMaxLength', () => {
test('should truncate to first line if it exists', () => {
Expand Down Expand Up @@ -43,3 +47,12 @@ describe('capitalizeFirstChar', () => {
expect(capitalizeFirstChar(object)).toEqual(object);
});
});

describe('middleTruncateKey', () => {
test('test middleTruncateKey', () => {
expect(middleTruncateKey('abc', 10)).toEqual('abc');
expect(middleTruncateKey('abcdefghij', 10)).toEqual('abcdefghij');
expect(middleTruncateKey('abcdefghijk', 10)).toEqual('abc...hijk');
expect(middleTruncateKey('abcdefghijkl', 10)).toEqual('abc...ijkl');
});
});
Expand Up @@ -49,6 +49,7 @@ import { Spacer } from '../../shared/building_blocks/Spacer';
import { SearchBox } from '../../shared/building_blocks/SearchBox';
import { Radio } from '../../shared/building_blocks/Radio';
import syncSvg from '../../common/static/sync.svg';
import { middleTruncateKey } from '../../common/utils/StringUtils';
import {
COLUMN_TYPES,
LIFECYCLE_FILTER,
Expand Down Expand Up @@ -721,7 +722,7 @@ export class ExperimentView extends Component {
) : (
<Icon type='arrow-down' />
)}{' '}
{metricKey}
{middleTruncateKey(metricKey, 50)}
</Option>,
);
});
Expand All @@ -745,7 +746,7 @@ export class ExperimentView extends Component {
) : (
<Icon type='arrow-down' />
)}{' '}
{paramKey}
{middleTruncateKey(paramKey, 50)}
</Option>,
);
});
Expand Down