@microsoft/vscode-azext-utils
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -7,3 +7,3 @@ /*--------------------------------------------------------------------------------------------- | ||
import type * as vscode from 'vscode'; | ||
import type { AbstractAzExtTreeItem, AzExtParentTreeItem, AzExtTreeDataProvider, AzExtTreeItem, ISubscriptionContext, SealedAzExtTreeItem } from './index'; // This must remain `import type` or else a circular reference will result | ||
import type { AbstractAzExtTreeItem, AzExtParentTreeItem, AzExtTreeDataProvider, AzExtTreeItem, IActionContext, IAzureQuickPickOptions, ISubscriptionContext, ITreeItemPickerContext, SealedAzExtTreeItem } from './index'; // This must remain `import type` or else a circular reference will result | ||
@@ -46,2 +46,7 @@ /** | ||
/** | ||
* Show a quick picker of app resources. Set `options.type` to filter the picks. | ||
*/ | ||
pickAppResource<T extends AzExtTreeItem>(context: ITreeItemPickerContext, options?: PickAppResourceOptions): Promise<T> | ||
/** | ||
* Registers an app resource resolver | ||
@@ -86,2 +91,23 @@ * @param id The resolver ID. Must be unique. | ||
export interface PickAppResourceOptions extends IAzureQuickPickOptions { | ||
/** | ||
* Options to filter the picks | ||
*/ | ||
filter?: { | ||
/** | ||
* App resource type to filter the app resource picks | ||
*/ | ||
type: string; | ||
/** | ||
* App resource kind to filter the app resource picks | ||
*/ | ||
kind?: string; | ||
} | ||
/** | ||
* Set this to pick a child of the selected app resource | ||
*/ | ||
expectedChildContextValue?: string | RegExp | (string | RegExp)[]; | ||
} | ||
/** | ||
@@ -88,0 +114,0 @@ * An abstract interface for GenericResource |
@@ -933,2 +933,7 @@ /*--------------------------------------------------------------------------------------------- | ||
suppressPersistence?: boolean; | ||
/** | ||
* Optionally allows some items to be automatically sorted at the top of the list | ||
*/ | ||
priority?: 'highest' | 'normal'; // 'highest' items come before the recently used item | ||
} | ||
@@ -935,0 +940,0 @@ |
@@ -185,20 +185,42 @@ "use strict"; | ||
const recentlyUsedValue = extensionVariables_1.ext.context.globalState.get(recentlyUsedKey); | ||
let recentlyUsedIndex = -1; | ||
if (recentlyUsedValue) { | ||
const index = picks.findIndex(p => getRecentlyUsedValue(p) === recentlyUsedValue); | ||
// No need to do anything if "recently used" item is not found or already the first item | ||
if (index > 0) { | ||
const previousItem = picks.splice(index, 1)[0]; | ||
if (!previousItem.suppressPersistence) { | ||
recentlyUsedIndex = picks.findIndex(p => getRecentlyUsedValue(p) === recentlyUsedValue); | ||
// Update recently used item's description | ||
if (recentlyUsedIndex >= 0) { | ||
const recentlyUsedItem = picks[recentlyUsedIndex]; | ||
if (!recentlyUsedItem.suppressPersistence) { | ||
const recentlyUsed = (0, localize_1.localize)('recentlyUsed', '(recently used)'); | ||
if (!previousItem.description) { | ||
previousItem.description = recentlyUsed; | ||
if (!recentlyUsedItem.description) { | ||
recentlyUsedItem.description = recentlyUsed; | ||
} | ||
else if (!previousItem.description.includes(recentlyUsed)) { | ||
previousItem.description = `${previousItem.description} ${recentlyUsed}`; | ||
else if (!recentlyUsedItem.description.includes(recentlyUsed)) { | ||
recentlyUsedItem.description = `${recentlyUsedItem.description} ${recentlyUsed}`; | ||
} | ||
picks.unshift(previousItem); | ||
} | ||
else { | ||
recentlyUsedIndex = -1; | ||
} | ||
} | ||
} | ||
picks = stableSortPicks(picks, recentlyUsedIndex); | ||
} | ||
function stableSortPicks(picks, recentlyUsedIndex) { | ||
function getPriorityAsNumber(pick, index) { | ||
switch (pick.priority) { | ||
case 'highest': | ||
return recentlyUsedIndex === index ? 0 : 1; | ||
case 'normal': | ||
default: | ||
return recentlyUsedIndex === index ? 2 : 3; | ||
} | ||
} | ||
const sortableFacade = picks.map((pick, index) => [index, getPriorityAsNumber(pick, index)]); | ||
// Sort by priority | ||
// Note that since ES10, Array.sort is stable | ||
sortableFacade.sort((a, b) => b[1] - a[1]); | ||
// Reconstitute array by pulling out items by index | ||
const sortedPicks = sortableFacade.map(item => picks[item[0]]); | ||
return sortedPicks; | ||
} | ||
function getGroupedPicks(groups) { | ||
@@ -205,0 +227,0 @@ let picks = []; |
{ | ||
"name": "@microsoft/vscode-azext-utils", | ||
"author": "Microsoft Corporation", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Common UI tools for developing Azure extensions for VS Code", | ||
@@ -6,0 +6,0 @@ "tags": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
281361
5645