Skip to content

Commit

Permalink
Add matchOnDetail and matchOnDescription to all quick picks
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jul 19, 2023
1 parent 996c610 commit 5e97e92
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
6 changes: 2 additions & 4 deletions extension/src/experiments/model/quickPick.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ describe('pickExperimentsToPlot', () => {
}
],
MAX_SELECTED_EXPERIMENTS,
Title.SELECT_EXPERIMENTS_TO_PLOT,
{ matchOnDescription: true, matchOnDetail: true }
{ title: Title.SELECT_EXPERIMENTS_TO_PLOT }
)
})

Expand Down Expand Up @@ -192,8 +191,7 @@ describe('pickExperimentsToPlot', () => {
],
[],
MAX_SELECTED_EXPERIMENTS,
Title.SELECT_EXPERIMENTS_TO_PLOT,
{ matchOnDescription: true, matchOnDetail: true }
{ title: Title.SELECT_EXPERIMENTS_TO_PLOT }
)
})
})
Expand Down
3 changes: 1 addition & 2 deletions extension/src/experiments/model/quickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export const pickExperimentsToPlot = (
items,
selectedItems,
MAX_SELECTED_EXPERIMENTS,
Title.SELECT_EXPERIMENTS_TO_PLOT,
{ matchOnDescription: true, matchOnDetail: true }
{ title: Title.SELECT_EXPERIMENTS_TO_PLOT }
)
}

Expand Down
7 changes: 6 additions & 1 deletion extension/src/test/suite/experiments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,12 @@ suite('Experiments Test Suite', () => {
picked: column.selected,
value: column
})),
{ canPickMany: true, title: Title.SELECT_COLUMNS }
{
canPickMany: true,
matchOnDescription: true,
matchOnDetail: true,
title: Title.SELECT_COLUMNS
}
)

await tableChangePromise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ suite('Experiments Filter By Tree Test Suite', () => {
})
}
],
{ canPickMany: true, title: Title.SELECT_FILTERS_TO_REMOVE }
{
canPickMany: true,
matchOnDescription: true,
matchOnDetail: true,
title: Title.SELECT_FILTERS_TO_REMOVE
}
)

mockShowInputBox.resetHistory()
Expand Down
4 changes: 2 additions & 2 deletions extension/src/test/suite/vscode/quickPick.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ suite('Quick Pick Test Suite', () => {
items,
items.slice(0, maxSelectedItems),
maxSelectedItems,
'select up to 3 values' as Title
{ title: 'select up to 3 values' as Title }
)

expect(
Expand Down Expand Up @@ -130,7 +130,7 @@ suite('Quick Pick Test Suite', () => {
items,
items.slice(0, maxSelectedItems - 1),
maxSelectedItems,
'select up to 5 values' as Title
{ title: 'select up to 5 values' as Title }
)

expect(
Expand Down
8 changes: 8 additions & 0 deletions extension/src/vscode/quickPick.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe('quickPickValue', () => {
const probablyC = await quickPickValue(items, { placeHolder, title })
expect(mockedShowQuickPick).toHaveBeenCalledWith(items, {
canPickMany: false,
matchOnDescription: true,
matchOnDetail: true,
placeHolder,
title
})
Expand Down Expand Up @@ -93,6 +95,8 @@ describe('quickPickManyValues', () => {
const result = await quickPickManyValues(items, { placeHolder, title })
expect(mockedShowQuickPick).toHaveBeenCalledWith(items, {
canPickMany: true,
matchOnDescription: true,
matchOnDetail: true,
placeHolder,
title
})
Expand All @@ -109,6 +113,8 @@ describe('quickPickOne', () => {

expect(mockedShowQuickPick).toHaveBeenCalledWith(['a', 'b', 'c'], {
canPickMany: false,
matchOnDescription: true,
matchOnDetail: true,
title
})
expect(noResponse).toStrictEqual(undefined)
Expand Down Expand Up @@ -140,6 +146,8 @@ describe('quickPickYesOrNo', () => {
],
{
canPickMany: false,
matchOnDescription: true,
matchOnDetail: true,
placeHolder,
title
}
Expand Down
19 changes: 12 additions & 7 deletions extension/src/vscode/quickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { QuickPickOptions, QuickPickItem, window, QuickPick } from 'vscode'
import { Response } from './response'
import { Title } from './title'

const DEFAULT_OPTIONS = { matchOnDescription: true, matchOnDetail: true }

export interface QuickPickItemWithValue<T = string> extends QuickPickItem {
value: T
}
Expand All @@ -16,6 +18,7 @@ export const quickPickValue: <T = string>(
) => Thenable<T | undefined> = async (items, options) => {
const result = await window.showQuickPick(items, {
canPickMany: false,
...DEFAULT_OPTIONS,
...options
})
return result?.value
Expand All @@ -26,6 +29,7 @@ export const quickPickManyValues: <T = string>(
options: Omit<QuickPickOptionsWithTitle, 'canPickMany'>
) => Thenable<T[] | undefined> = async (items, options = {}) => {
const result = await window.showQuickPick(items, {
...DEFAULT_OPTIONS,
...options,
canPickMany: true
})
Expand All @@ -38,6 +42,7 @@ export const quickPickOne = (
title: string
): Thenable<string | undefined> =>
window.showQuickPick(items, {
...DEFAULT_OPTIONS,
canPickMany: false,
title
})
Expand All @@ -49,17 +54,17 @@ const createQuickPick = <T>(
canSelectMany: boolean
placeholder?: string
title: Title
matchOnDescription?: boolean
matchOnDetail?: boolean
matchOnDescription: boolean
matchOnDetail: boolean
}
): QuickPick<QuickPickItemWithValue<T>> => {
const quickPick = window.createQuickPick<QuickPickItemWithValue<T>>()

quickPick.canSelectMany = options.canSelectMany
quickPick.placeholder = options.placeholder
quickPick.title = options.title
quickPick.matchOnDescription = options.matchOnDescription || false
quickPick.matchOnDetail = options.matchOnDetail || false
quickPick.matchOnDescription = options.matchOnDescription
quickPick.matchOnDetail = options.matchOnDetail

quickPick.items = items
if (selectedItems) {
Expand All @@ -75,6 +80,7 @@ export const quickPickOneOrInput = (
new Promise(resolve => {
const quickPick = createQuickPick<string>(items, undefined, {
canSelectMany: false,
...DEFAULT_OPTIONS,
...options
})

Expand Down Expand Up @@ -189,13 +195,12 @@ export const quickPickLimitedValues = <T>(
items: QuickPickItemWithValue<T>[],
selectedItems: readonly QuickPickItemWithValue<T>[],
maxSelectedItems: number,
title: Title,
options?: { matchOnDescription?: boolean; matchOnDetail?: boolean }
options: QuickPickOptions & { title: Title }
): Promise<Exclude<T, undefined>[] | undefined> =>
new Promise(resolve => {
const quickPick = createQuickPick(items, selectedItems, {
...DEFAULT_OPTIONS,
canSelectMany: true,
title,
...options
})

Expand Down

0 comments on commit 5e97e92

Please sign in to comment.