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

Respect some ITreeItemPickerContext options in compatibility pick tree item step #1337

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface CompatibilityRecursiveQuickPickOptions extends ContextValueFilterQuick
/**
* Recursive step which is compatible which adds create picks based if the node has {@link types.CompatibleQuickPickOptions.createChild quickPickOptions.createChild} defined.
*/
export class CompatibilityRecursiveQuickPickStep<TContext extends types.QuickPickWizardContext> extends CompatibilityContextValueQuickPickStep<TContext, CompatibilityRecursiveQuickPickOptions> {
export class CompatibilityRecursiveQuickPickStep<TContext extends types.QuickPickWizardContext & types.ITreeItemPickerContext> extends CompatibilityContextValueQuickPickStep<TContext, CompatibilityRecursiveQuickPickOptions> {

protected override async promptInternal(wizardContext: TContext): Promise<unknown> {
const picks = await this.getPicks(wizardContext) as types.IAzureQuickPickItem<unknown>[];
Expand Down Expand Up @@ -77,19 +77,23 @@ export class CompatibilityRecursiveQuickPickStep<TContext extends types.QuickPic
} else {
const lastPickedItemTi = isWrapper(lastPickedItem) ? lastPickedItem.unwrap<AzExtTreeItem>() : lastPickedItem;

const promptOptions = isAzExtParentTreeItem(lastPickedItemTi) ? {
const promptOptions: types.IAzureQuickPickOptions = isAzExtParentTreeItem(lastPickedItemTi) ? {
placeHolder: localize('selectTreeItem', 'Select {0}', lastPickedItemTi.childTypeLabel),
stepName: `treeItemPicker|${lastPickedItemTi.contextValue}`,
noPicksMessage: wizardContext.noItemFoundErrorMessage,
ignoreFocusOut: wizardContext.ignoreFocusOut,
} : {};

const shouldAddCreatePick = isAzExtParentTreeItem(lastPickedItemTi) && !!lastPickedItemTi.createChildImpl;

// Need to keep going because the last picked node is not a match
return {
hideStepCount: true,
promptSteps: [
new CompatibilityRecursiveQuickPickStep(this.treeDataProvider, {
...this.pickOptions,
skipIfOne: isAzExtParentTreeItem(lastPickedItemTi) && !!lastPickedItemTi.createChildImpl,
create: (isAzExtParentTreeItem(lastPickedItemTi) && !!lastPickedItemTi.createChildImpl) ? {
skipIfOne: !shouldAddCreatePick, // don't skip if we're adding a create pick
create: shouldAddCreatePick ? {
callback: lastPickedItemTi.createChild.bind(lastPickedItemTi) as typeof lastPickedItemTi.createChild,
label: lastPickedItemTi.createNewLabel ?? localize('createNewItem', '$(plus) Create new {0}', lastPickedItemTi.childTypeLabel)
} : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export namespace PickTreeItemWithCompatibility {
* Helper to provide compatibility for `AzExtParentTreeItem.showTreeItemPicker`.
*/
export async function showTreeItemPicker<TPick extends types.AzExtTreeItem>(context: types.ITreeItemPickerContext, tdp: vscode.TreeDataProvider<ResourceGroupsItem>, expectedContextValues: string | RegExp | (string | RegExp)[], startingTreeItem?: AzExtTreeItem): Promise<TPick> {
const promptSteps: AzureWizardPromptStep<types.QuickPickWizardContext>[] = [
const promptSteps: AzureWizardPromptStep<types.QuickPickWizardContext & types.ITreeItemPickerContext>[] = [
new CompatibilityRecursiveQuickPickStep(tdp, {
contextValueFilter: {
include: expectedContextValues,
Expand All @@ -49,9 +49,10 @@ export namespace PickTreeItemWithCompatibility {
}),
];

// Fill in the `pickedNodes` property
const wizardContext = { ...context } as types.QuickPickWizardContext;
wizardContext.pickedNodes = startingTreeItem ? [startingTreeItem] : [];
const wizardContext: types.QuickPickWizardContext & types.ITreeItemPickerContext = {
...context,
pickedNodes: startingTreeItem ? [startingTreeItem] : [],
};

const wizard = new AzureWizard(wizardContext, {
hideStepCount: true,
Expand Down