Skip to content

Sort run names with leading numbers differently #6664

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

Merged
merged 6 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions tensorboard/webapp/runs/views/runs_table/sorting_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface SortOptions {
insertUndefined: UndefinedStrategy;
}

const POTENTIALLY_NUMERIC = new Set(['string', 'number']);
const POTENTIALLY_NUMERIC_TYPES = new Set(['string', 'number']);

const DEFAULT_SORT_OPTIONS: SortOptions = {
insertUndefined: UndefinedStrategy.AFTER,
Expand Down Expand Up @@ -73,12 +73,12 @@ export function sortTableDataItems(
}

if (aValue === undefined || bValue === undefined) {
return orderFromLocalComparison(aValue, bValue);
return compareValues(aValue, bValue);
}

if (
POTENTIALLY_NUMERIC.has(typeof aValue) &&
POTENTIALLY_NUMERIC.has(typeof bValue)
POTENTIALLY_NUMERIC_TYPES.has(typeof aValue) &&
POTENTIALLY_NUMERIC_TYPES.has(typeof bValue)
) {
const aPrefix = parseNumericPrefix(aValue as string | number);
const bPrefix = parseNumericPrefix(bValue as string | number);
Expand All @@ -87,7 +87,7 @@ export function sortTableDataItems(
(aPrefix === undefined || bPrefix === undefined) &&
aPrefix !== bPrefix
) {
return orderFromLocalComparison(aPrefix, bPrefix, {
return compareValues(aPrefix, bPrefix, {
insertUndefined: UndefinedStrategy.BEFORE,
});
}
Expand All @@ -97,20 +97,20 @@ export function sortTableDataItems(
aValue.toString().slice(aPrefix.toString().length) || undefined;
const bPostfix =
bValue.toString().slice(bPrefix.toString().length) || undefined;
return orderFromLocalComparison(aPostfix, bPostfix, {
return compareValues(aPostfix, bPostfix, {
insertUndefined: UndefinedStrategy.BEFORE,
});
}

return orderFromLocalComparison(aPrefix, bPrefix);
return compareValues(aPrefix, bPrefix);
}
}

return orderFromLocalComparison(aValue, bValue);
return compareValues(aValue, bValue);
});
return sortedItems;

function orderFromLocalComparison(
function compareValues(
a: TableData[string] | undefined,
b: TableData[string] | undefined,
{insertUndefined}: SortOptions = DEFAULT_SORT_OPTIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('sorting utils', () => {
expect(parseNumericPrefix('0')).toEqual(0);
expect(parseNumericPrefix('123')).toEqual(123);
expect(parseNumericPrefix('123/')).toEqual(123);
expect(parseNumericPrefix('123/foo')).toEqual(123);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still has a '/' after the number. I was thinking something like 123train. Still just a nit though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, okay. I'll add that case too

expect(parseNumericPrefix('123/foo/456')).toEqual(123);
});

Expand Down