-
Notifications
You must be signed in to change notification settings - Fork 30
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
Refactor quick pick filters #333
Closed
alexweininger
wants to merge
23
commits into
bmw/philliphoff-resource-api-quickpick
from
alex/resource-api-qp-filters
Closed
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
36d411d
App Resource filter
alexweininger 3fba54d
Use encapsulation for filtering
alexweininger e9c7db3
Simplify options interface
alexweininger 3f8e498
Fix Workspace view loadMore (#357)
alexweininger 3aae964
Merge remote-tracking branch 'origin/bmw/philliphoff-resource-api-qui…
alexweininger 3126a0e
Fixes
alexweininger cc2030c
Merge remote-tracking branch 'origin/philliphoff-resource-api' into a…
alexweininger 17033f2
Use `AzExtResourceType` to simplify `azureUtils.ts` (#337)
alexweininger 8d185b9
Merge remote-tracking branch 'origin/philliphoff-resource-api' into a…
alexweininger 1211e02
working
alexweininger c16be00
Merge remote-tracking branch 'origin/main' into alex/resource-api-qp-…
alexweininger 5336aa6
wip
alexweininger f11cba9
Fixup
alexweininger 44f09c0
Fixup
alexweininger 586cbe7
Sketch getApi() with options.
philliphoff 0514154
Add telemetry for API calls.
philliphoff df89831
Merge main (#364)
alexweininger 6db86c3
Update dev package
alexweininger 6e9efec
Merge branch 'philliphoff-resource-api' into alex/resource-api-qp-fil…
alexweininger 63ab62b
throw UserCancelledError
alexweininger ae88a7d
Merge remote-tracking branch 'origin/bmw/philliphoff-resource-api-qui…
alexweininger 00fd216
Fixup
alexweininger 74fbf59
Merge remote-tracking branch 'origin/bmw/philliphoff-resource-api-qui…
alexweininger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AppResource, AppResourceFilter as AppResourceFilterOptions } from "@microsoft/vscode-azext-utils/hostapi"; | ||
import { Filter } from "../v2AzureResourcesApi"; | ||
|
||
export class AppResourceFilter implements Filter<AppResource> { | ||
|
||
constructor(private readonly options: AppResourceFilterOptions) { } | ||
|
||
public matches(resource: AppResource): boolean { | ||
if (this.options.type !== resource.type) { | ||
return false; | ||
} | ||
|
||
if (this.options.kind && this.options.kind !== resource.kind) { | ||
return false; | ||
} | ||
|
||
if (this.options.tags) { | ||
for (const tag of Object.keys(this.options.tags)) { | ||
if (this.options.tags[tag] !== resource.tags?.[tag]) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,34 @@ | |
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { AzureWizardPromptStep, IAzureQuickPickItem, IWizardOptions } from '@microsoft/vscode-azext-utils'; | ||
import { PickAppResourceOptions } from '@microsoft/vscode-azext-utils/hostapi'; | ||
import { AzureWizardPromptStep, IAzureQuickPickItem, IAzureQuickPickOptions, IWizardOptions } from '@microsoft/vscode-azext-utils'; | ||
import { AppResource } from '@microsoft/vscode-azext-utils/hostapi'; | ||
import { BranchDataProviderManager } from '../../../tree/v2/providers/BranchDataProviderManager'; | ||
import { ApplicationResourceProviderManager } from '../providers/ApplicationResourceProviderManager'; | ||
import { ApplicationResource, ResourceModelBase } from '../v2AzureResourcesApi'; | ||
import { matchesContextValueFilter } from './ContextValueFilter'; | ||
import { ApplicationResource, Filter, ResourceModelBase } from '../v2AzureResourcesApi'; | ||
import { QuickPickAppResourceWizardContext } from './QuickPickAppResourceWizardContext'; | ||
import { RecursiveQuickPickStep } from './RecursiveQuickPickStep'; | ||
|
||
export interface PickAppResourceOptions2 extends IAzureQuickPickOptions { | ||
/** | ||
* Set this to pick a child of the selected app resource | ||
*/ | ||
childFilter?: Filter<ResourceModelBase>; | ||
|
||
/** | ||
* Whether `AppResourceTreeItem`s should be resolved before displaying them as quick picks, or only once one has been selected | ||
* If a client extension needs to change label/description/something visible on the quick pick via `resolve`, set to true, | ||
* otherwise set to false. Default will be false. | ||
*/ | ||
resolveQuickPicksBeforeDisplay?: boolean; | ||
} | ||
|
||
export class QuickPickAppResourceStep<TModel extends ResourceModelBase> extends AzureWizardPromptStep<QuickPickAppResourceWizardContext<TModel>> { | ||
public constructor( | ||
private readonly resourceProviderManager: ApplicationResourceProviderManager, | ||
private readonly branchDataProviderManager: BranchDataProviderManager, | ||
private readonly options: PickAppResourceOptions | ||
private readonly filter?: Filter<AppResource> | Filter<AppResource>[], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I promoted |
||
private readonly options?: PickAppResourceOptions2 | ||
) { | ||
super(); | ||
} | ||
|
@@ -39,8 +53,8 @@ export class QuickPickAppResourceStep<TModel extends ResourceModelBase> extends | |
} | ||
|
||
public async getSubWizard(wizardContext: QuickPickAppResourceWizardContext<TModel>): Promise<IWizardOptions<QuickPickAppResourceWizardContext<TModel>> | undefined> { | ||
if (this.options.expectedChildContextValue) { | ||
if (matchesContextValueFilter(wizardContext.currentNode as TModel, this.options.expectedChildContextValue)) { | ||
if (this.options?.childFilter) { | ||
if (this.options.childFilter?.matches(wizardContext.currentNode as TModel)) { | ||
return undefined; | ||
} | ||
|
||
|
@@ -49,7 +63,7 @@ export class QuickPickAppResourceStep<TModel extends ResourceModelBase> extends | |
return { | ||
hideStepCount: true, | ||
promptSteps: [ | ||
new RecursiveQuickPickStep(bdp, this.options.expectedChildContextValue), | ||
new RecursiveQuickPickStep(bdp, this.options.childFilter), | ||
], | ||
}; | ||
} | ||
|
@@ -65,30 +79,11 @@ export class QuickPickAppResourceStep<TModel extends ResourceModelBase> extends | |
} | ||
|
||
private matchesAppResource(resource: ApplicationResource): boolean { | ||
if (!this.options.filter) { | ||
if (!this.filter) { | ||
return true; | ||
} | ||
|
||
const filterArray = Array.isArray(this.options.filter) ? this.options.filter : [this.options.filter]; | ||
|
||
return filterArray.some(filter => { | ||
if (filter.type !== resource.type) { | ||
return false; | ||
} | ||
|
||
if (filter.kind && filter.kind !== resource.kind) { | ||
return false; | ||
} | ||
|
||
if (filter.tags) { | ||
for (const tag of Object.keys(filter.tags)) { | ||
if (filter.tags[tag] !== resource.tags?.[tag]) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
}) | ||
const filterArray = Array.isArray(this.filter) ? this.filter : [this.filter]; | ||
return filterArray.some((filter) => filter.matches(resource)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once microsoft/vscode-azuretools#1191 is merged, we can change the body of this method to
without having to make changes elsewhere.