Skip to content

Commit 7de2c6b

Browse files
authored
Fix exp tree tooltips and quick pick selection ignoring columns with falsy values (#2745)
1 parent 2cfd5ea commit 7de2c6b

File tree

5 files changed

+60
-23
lines changed

5 files changed

+60
-23
lines changed

extension/src/experiments/model/quickPick.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('pickExperiments', () => {
8383
label: '123fsf4',
8484
params: {
8585
'params.yaml': {
86-
prepare: { split: 0.1 }
86+
prepare: { split: 0 }
8787
}
8888
},
8989
selected: false
@@ -135,7 +135,7 @@ describe('pickExperiments', () => {
135135
[
136136
{
137137
description: '[exp-123]',
138-
detail: 'Created:Aug 19, 2022, split:0.1, data/data.xml:22a1a29',
138+
detail: 'Created:Aug 19, 2022, split:0, data/data.xml:22a1a29',
139139
label: '123fsf4',
140140
value: mockedExperiments[0]
141141
},

extension/src/experiments/model/quickPicks.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { Toast } from '../../vscode/toast'
1212
import { Experiment } from '../webview/contract'
1313
import { Title } from '../../vscode/title'
14-
import { truncate, truncateFromLeft } from '../../util/string'
14+
import { truncateFromLeft } from '../../util/string'
1515

1616
type QuickPickItemAccumulator = {
1717
items: QuickPickItemWithValue<Experiment | undefined>[]
@@ -32,10 +32,8 @@ const getItem = (experiment: Experiment, firstThreeColumnOrder: string[]) => ({
3232
splitUpPath[splitUpPath.length - 1],
3333
15
3434
)
35-
const truncatedVal =
36-
typeof value === 'number' ? truncate(String(value), 7) : value
3735

38-
return value ? `${truncatedKey}:${truncatedVal}` : ''
36+
return value !== null ? `${truncatedKey}:${value}` : ''
3937
})
4038
.filter(Boolean)
4139
.join(', '),

extension/src/experiments/model/tree.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ describe('ExperimentsTree', () => {
407407
label: 'a123',
408408
params: {
409409
'params.yaml': {
410-
featurize: { max_features: 200 }
410+
featurize: {
411+
random_value: undefined
412+
}
411413
}
412414
},
413415
selected: false,
@@ -424,7 +426,9 @@ describe('ExperimentsTree', () => {
424426
label: 'b456',
425427
params: {
426428
'params.yaml': {
427-
featurize: { max_features: 210 }
429+
featurize: {
430+
random_value: ['rbf', 'linear']
431+
}
428432
}
429433
},
430434
selected: true,
@@ -441,7 +445,9 @@ describe('ExperimentsTree', () => {
441445
label: 'c789',
442446
params: {
443447
'params.yaml': {
444-
featurize: { max_features: 190 }
448+
featurize: {
449+
random_value: false
450+
}
445451
}
446452
},
447453
selected: false,
@@ -458,8 +464,8 @@ describe('ExperimentsTree', () => {
458464
mockedGetDvcRoots.mockReturnValueOnce(['repo'])
459465
mockedGetFirstThreeColumnOrder.mockReturnValue([
460466
'Created',
461-
'params:params.yaml:featurize.max_features',
462-
'deps:data/data.xml'
467+
'deps:data/data.xml',
468+
'params:params.yaml:featurize.random_value'
463469
])
464470

465471
const children = await experimentsTree.getChildren()
@@ -478,7 +484,7 @@ describe('ExperimentsTree', () => {
478484
id: 'exp-123',
479485
label: 'a123',
480486
tooltip:
481-
'|||\n|:--|--|\n| Created | Aug 19, 2022 |\n| ...ms.yaml:featurize.max_features | 200 |\n| data/data.xml | 22a1a29 |\n',
487+
'|||\n|:--|--|\n| Created | Aug 19, 2022 |\n| data/data.xml | 22a1a29 |\n| ...ms.yaml:featurize.random_value | undefined |\n',
482488
type: ExperimentType.EXPERIMENT
483489
},
484490
{
@@ -494,7 +500,7 @@ describe('ExperimentsTree', () => {
494500
id: 'exp-456',
495501
label: 'b456',
496502
tooltip:
497-
'|||\n|:--|--|\n| Created | Sep 15, 2022 |\n| ...ms.yaml:featurize.max_features | 210 |\n| data/data.xml | 22a1a29 |\n',
503+
'|||\n|:--|--|\n| Created | Sep 15, 2022 |\n| data/data.xml | 22a1a29 |\n| ...ms.yaml:featurize.random_value | [rbf,linear] |\n',
498504
type: ExperimentType.EXPERIMENT
499505
},
500506
{
@@ -510,7 +516,7 @@ describe('ExperimentsTree', () => {
510516
id: 'exp-789',
511517
label: 'c789',
512518
tooltip:
513-
'|||\n|:--|--|\n| Created | Jul 3, 2022 |\n| ...ms.yaml:featurize.max_features | 190 |\n| data/data.xml | 22a1a29 |\n',
519+
'|||\n|:--|--|\n| Created | Jul 3, 2022 |\n| data/data.xml | 22a1a29 |\n| ...ms.yaml:featurize.random_value | false |\n',
514520
type: ExperimentType.EXPERIMENT
515521
}
516522
])

extension/src/experiments/model/tree.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { sum } from '../../util/math'
3333
import { Disposable } from '../../class/dispose'
3434
import { Experiment, ExperimentStatus, isRunning } from '../webview/contract'
3535
import { getMarkdownString } from '../../vscode/markdownString'
36-
import { truncate, truncateFromLeft } from '../../util/string'
36+
import { truncateFromLeft } from '../../util/string'
3737

3838
export class ExperimentsTree
3939
extends Disposable
@@ -355,9 +355,7 @@ export class ExperimentsTree
355355
path.slice(type.length + 1) || path,
356356
30
357357
)
358-
const truncatedVal =
359-
typeof value === 'number' ? truncate(String(value), 7) : value
360-
return value ? `| ${truncatedKey} | ${truncatedVal} |\n` : ''
358+
return value !== null ? `| ${truncatedKey} | ${value} |\n` : ''
361359
})
362360
.join('')
363361
return getMarkdownString(`|||\n|:--|--|\n${data}`)
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,55 @@
11
import get from 'lodash.get'
22
import { formatDate } from '../../util/date'
3+
import { truncate } from '../../util/string'
34
import { splitColumnPath } from '../columns/paths'
45
import { Experiment } from '../webview/contract'
56

7+
type Value = undefined | null | [] | string | number
8+
9+
const getValueType = (value: Value): string => {
10+
let type: string = typeof value
11+
if (Number.isNaN(value)) {
12+
type = 'NaN'
13+
} else if (typeof value === 'string' && Date.parse(value)) {
14+
type = 'date'
15+
} else if (Array.isArray(value)) {
16+
type = 'array'
17+
} else if (value === '') {
18+
type = 'empty'
19+
}
20+
return type
21+
}
22+
23+
const getStringifiedValue = (value: Value): string => {
24+
const type = getValueType(value)
25+
switch (type) {
26+
case 'date':
27+
return typeof value === 'string' ? formatDate(value) : ''
28+
case 'array':
29+
return `[${value?.toString()}]`
30+
case 'empty':
31+
case 'NaN':
32+
return type
33+
case 'number':
34+
return truncate(String(value), 7)
35+
default:
36+
return String(value)
37+
}
38+
}
39+
640
export const getDataFromColumnPath = (
741
experiment: Experiment,
842
columnPath: string
943
): { splitUpPath: string[]; value: string | null } => {
1044
const splitUpPath = splitColumnPath(columnPath)
1145
const collectedVal = get(experiment, splitUpPath)
12-
const value =
13-
columnPath === 'Created' && collectedVal
14-
? formatDate(collectedVal)
15-
: collectedVal?.value || collectedVal
46+
const value = collectedVal?.value || collectedVal
47+
1648
return {
1749
splitUpPath,
18-
value: value || null
50+
value:
51+
columnPath === 'Created' && typeof value === 'undefined'
52+
? null
53+
: getStringifiedValue(value)
1954
}
2055
}

0 commit comments

Comments
 (0)