Skip to content

Commit 753e33c

Browse files
authored
Add shown/hidden indicator to select first column quick pick (#4314)
1 parent a5f5a9b commit 753e33c

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

extension/src/experiments/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { pickSortsToRemove, pickSortToAdd } from './model/sortBy/quickPick'
2727
import { ColumnsModel } from './columns/model'
2828
import { ExperimentsData } from './data'
2929
import { stopWorkspaceExperiment } from './processExecution'
30-
import { Experiment, ColumnType, TableData } from './webview/contract'
30+
import { Experiment, ColumnType, TableData, Column } from './webview/contract'
3131
import { WebviewMessages } from './webview/messages'
3232
import { DecorationProvider } from './model/decorationProvider'
3333
import { starredFilter } from './model/filterBy/constants'
@@ -369,9 +369,15 @@ export class Experiments extends BaseRepository<TableData> {
369369
public async selectFirstColumns() {
370370
const columns = this.columns.getTerminalNodes()
371371

372-
const selected = await pickPaths(
373-
columns.map(column => ({ ...column, selected: false })),
374-
Title.SELECT_FIRST_COLUMNS
372+
const selected = await pickPaths<Column>(
373+
columns,
374+
Title.SELECT_FIRST_COLUMNS,
375+
element => ({
376+
description: element.selected ? '$(eye)' : '$(eye-closed)',
377+
label: element.path,
378+
picked: false,
379+
value: element
380+
})
375381
)
376382
if (!definedAndNonEmpty(selected)) {
377383
return

extension/src/path/selection/quickPick.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,24 @@ type PathWithSelected<T extends PathType> = T & {
1414
selected: boolean
1515
}
1616

17-
const getItem = <T extends PathType>(element: PathWithSelected<T>) => ({
17+
const collectDefaultItem = <T extends PathType>(
18+
element: PathWithSelected<T>
19+
): QuickPickItemWithValue<PathWithSelected<T>> => ({
1820
label: element.path,
1921
picked: element.selected,
2022
value: element
2123
})
2224

2325
const collectItems = <T extends PathType>(
24-
paths: PathWithSelected<T>[]
26+
paths: PathWithSelected<T>[],
27+
collectItem: (
28+
element: PathWithSelected<T>
29+
) => QuickPickItemWithValue<PathWithSelected<T>>
2530
): QuickPickItemWithValue<PathWithSelected<T>>[] => {
2631
const acc: QuickPickItemWithValue<PathWithSelected<T>>[] = []
2732

2833
for (const path of paths) {
29-
acc.push(getItem(path))
34+
acc.push(collectItem(path))
3035
}
3136

3237
return acc
@@ -37,15 +42,18 @@ export const pickPaths = <T extends PathType>(
3742
title:
3843
| typeof Title.SELECT_PLOTS
3944
| typeof Title.SELECT_COLUMNS
40-
| typeof Title.SELECT_FIRST_COLUMNS
45+
| typeof Title.SELECT_FIRST_COLUMNS,
46+
collectItem: (
47+
element: PathWithSelected<T>
48+
) => QuickPickItemWithValue<PathWithSelected<T>> = collectDefaultItem
4149
): Thenable<PathWithSelected<T>[] | undefined> => {
4250
const type = Title.SELECT_PLOTS === title ? 'plots' : 'columns'
4351

4452
if (!definedAndNonEmpty(paths)) {
4553
return Toast.showError(`There are no ${type} to select.`)
4654
}
4755

48-
const items = collectItems(paths)
56+
const items = collectItems(paths, collectItem)
4957

5058
return quickPickManyValues<PathWithSelected<T>>(items, {
5159
title

extension/src/test/suite/experiments/columns/tree.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
QuickPickItemWithValue,
1818
QuickPickOptionsWithTitle
1919
} from '../../../../vscode/quickPick'
20+
import { Title } from '../../../../vscode/title'
2021

2122
suite('Experiments Columns Tree Test Suite', () => {
2223
const paramsFile = 'params.yaml'
@@ -379,7 +380,7 @@ suite('Experiments Columns Tree Test Suite', () => {
379380
otherColumns.push(column)
380381
}
381382

382-
;(
383+
const mockShowQuickPick = (
383384
stub(window, 'showQuickPick') as SinonStub<
384385
[items: readonly QuickPickItem[], options: QuickPickOptionsWithTitle],
385386
Thenable<QuickPickItemWithValue<{ path: string }>[] | undefined>
@@ -414,6 +415,21 @@ suite('Experiments Columns Tree Test Suite', () => {
414415
...firstColumns,
415416
...otherColumns
416417
])
418+
419+
expect(mockShowQuickPick).to.be.calledWithExactly(
420+
columnsModel.getTerminalNodes().map(column => ({
421+
description: '$(eye)',
422+
label: column.path,
423+
picked: false,
424+
value: column
425+
})),
426+
{
427+
canPickMany: true,
428+
matchOnDescription: true,
429+
matchOnDetail: true,
430+
title: Title.SELECT_FIRST_COLUMNS
431+
}
432+
)
417433
})
418434
})
419435
})

0 commit comments

Comments
 (0)