in src/utils/multiSelectNodes.ts [20:64]
export async function multiSelectNodes<T extends AzExtTreeItem>(
context: ITreeItemPickerContext,
tree: AzExtTreeDataProvider,
expectedContextValue?: string | RegExp,
node?: T,
nodes?: T[]): Promise<T[]> {
// Ensure it's not undefined
nodes = nodes || [];
if (nodes.length === 0 && node) {
// If there's no multi-selected nodes but primary node is defined, use it as the only element
nodes = [node];
}
if (nodes.length === 0) {
// If still no selected nodes, need to prompt
await tree.refresh(context);
nodes = await tree.showTreeItemPicker<T>(expectedContextValue, { ...context, canPickMany: true });
} else if (expectedContextValue) {
// Otherwise if there's a filter, need to filter our selection to exclude ineligible nodes
// This uses the same logic as AzExtTreeItem.matchesContextValue()
const beforeLength = nodes.length;
nodes = nodes.filter(n => {
return expectedContextValue === n.contextValue || // For strings, exact match comparison
(expectedContextValue instanceof RegExp && expectedContextValue.test(n.contextValue)); // For regexs, RegExp.test()
});
if (beforeLength !== nodes.length) {
// Some things got filtered off because they were not valid choices
// eslint-disable-next-line @typescript-eslint/no-floating-promises
context.ui.showWarningMessage('This action is invalid for some selected items. These items will be ignored.');
}
}
// Filter off parent items (i.e. group items), as it doesn't make sense to perform actions on them, when we don't allow actions to be performed on *only* them
nodes = nodes.filter(n => ((<MultiSelectNode><unknown>n).canMultiSelect === true) || !(n instanceof AzExtParentTreeItem));
// If we end with no nodes, cancel
if (nodes.length === 0) {
throw new UserCancelledError();
}
return nodes;
}