From f264fd81909a05056cab7e7c68563b5f3c822254 Mon Sep 17 00:00:00 2001 From: Megan Mott <59709511+motm32@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:14:25 -0800 Subject: [PATCH] fix subscription filter (#975) Co-authored-by: alexweininger --- src/commands/accounts/selectSubscriptions.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/commands/accounts/selectSubscriptions.ts b/src/commands/accounts/selectSubscriptions.ts index aabea766..2d3157c7 100644 --- a/src/commands/accounts/selectSubscriptions.ts +++ b/src/commands/accounts/selectSubscriptions.ts @@ -38,11 +38,17 @@ export async function selectSubscriptions(context: IActionContext, options?: Sel const subscriptionQuickPickItems: () => Promise[]> = async () => { // If there are no tenants selected by default all subscriptions will be shown. let subscriptions = await provider.getSubscriptions(false); - if (options?.account) { - subscriptions = subscriptions.filter(subscription => subscription.account.id === options.account?.id); - } - if (options?.tenantId) { - subscriptions = subscriptions.filter(subscription => subscription.tenantId === options.tenantId); + + if (options?.account || options?.tenantId) { + + if (options?.account) { + subscriptions = subscriptions.filter(subscription => subscription.account.id === options.account?.id); + } + if (options?.tenantId) { + subscriptions = subscriptions.filter(subscription => subscription.tenantId === options.tenantId); + } + } else { + subscriptions = getTenantFilteredSubscriptions(subscriptions); } const duplicates = getDuplicateSubscriptions(subscriptions); @@ -110,7 +116,7 @@ async function setSelectedTenantAndSubscriptionIds(tenantAndSubscriptionIds: str } // This function is also used to filter subscription tree items in AzureResourceTreeDataProvider -export function getTenantFilteredSubscriptions(allSubscriptions: AzureSubscription[]): AzureSubscription[] | undefined { +export function getTenantFilteredSubscriptions(allSubscriptions: AzureSubscription[]): AzureSubscription[] { const filteredSubscriptions = allSubscriptions.filter(subscription => !isTenantFilteredOut(subscription.tenantId, subscription.account.id)); return filteredSubscriptions.length > 0 ? filteredSubscriptions : allSubscriptions; }