Skip to content

Commit 79882b7

Browse files
Fix displaying Logic Apps as Function Apps (#332)
Co-authored-by: Brandon Waterloo [MSFT] <36966225+bwateratmsft@users.noreply.github.com>
1 parent fb5da95 commit 79882b7

File tree

5 files changed

+52
-21
lines changed

5 files changed

+52
-21
lines changed
Lines changed: 17 additions & 0 deletions
Loading

src/azureExtensions.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { GenericResource } from "@azure/arm-resources";
7+
import { isAppServiceApp, isFunctionApp } from "./utils/azureUtils";
78
import { localize } from "./utils/localize";
89

910
export const azureExtensions: IAzExtMetadata[] = [
@@ -28,7 +29,7 @@ export const azureExtensions: IAzExtMetadata[] = [
2829
resourceTypes: [
2930
{
3031
name: 'microsoft.web/sites',
31-
matchesResource: r => !isFunctionApp(r)
32+
matchesResource: isAppServiceApp
3233
}
3334
],
3435
tutorial: {
@@ -114,7 +115,3 @@ export interface IAzExtTutorial {
114115
label: string;
115116
url: string;
116117
}
117-
118-
function isFunctionApp(resource: GenericResource): boolean {
119-
return !!resource.kind?.toLowerCase().includes('functionapp');
120-
}

src/tree/AppResourceTreeItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class AppResourceTreeItem extends ResolvableTreeItemBase implements Group
5656
ext.resourceTypes.some((type) => {
5757
return typeof type === 'string' ?
5858
type.toLowerCase() === this.type?.toLowerCase() :
59-
type.name.toLowerCase() === this.type?.toLowerCase()
59+
type.name.toLowerCase() === this.type?.toLowerCase() && type.matchesResource(this.data)
6060
}));
6161
}
6262

src/tree/ResourceCache.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ResourceGroup } from "@azure/arm-resources";
77
import { IActionContext, nonNullProp } from "@microsoft/vscode-azext-utils";
88
import { AppResource } from "@microsoft/vscode-azext-utils/hostapi";
99
import { ThemeIcon } from "vscode";
10+
import { azureExtensions } from "../azureExtensions";
1011
import { GroupBySettings } from "../commands/explorer/groupBy";
1112
import { ungroupedId } from "../constants";
1213
import { createAzureExtensionsGroupConfig } from "../utils/azureUtils";
@@ -82,7 +83,7 @@ export class ResourceCache {
8283
break;
8384
case GroupBySettings.ResourceType:
8485
// always create the groups for extensions that we support
85-
const azExtGroupConfigs = createAzureExtensionsGroupConfig(nonNullProp(this._subscriptionTreeItem, 'id'));
86+
const azExtGroupConfigs = createAzureExtensionsGroupConfig(azureExtensions, nonNullProp(this._subscriptionTreeItem, 'id'));
8687
for (const azExtGroupConfig of azExtGroupConfigs) {
8788
if (!treeMap[azExtGroupConfig.id]) {
8889
const groupTreeItem = new GroupTreeItemBase(this._subscriptionTreeItem, azExtGroupConfig);

src/utils/azureUtils.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { uiUtils } from '@microsoft/vscode-azext-azureutils';
88
import { IActionContext, nonNullProp, TreeItemIconPath } from '@microsoft/vscode-azext-utils';
99
import { GroupingConfig, GroupNodeConfiguration } from '@microsoft/vscode-azext-utils/hostapi';
1010
import { ThemeIcon } from 'vscode';
11-
import { azureExtensions } from '../azureExtensions';
11+
import type { IAzExtMetadata } from '../azureExtensions';
1212
import { ext } from '../extensionVariables';
1313
import { createResourceClient } from './azureClients';
1414
import { localize } from './localize';
@@ -67,9 +67,9 @@ export function createGroupConfigFromResource(resource: GenericResource, subscri
6767
return groupConfig;
6868
}
6969

70-
export function createAzureExtensionsGroupConfig(subscriptionId: string): GroupNodeConfiguration[] {
70+
export function createAzureExtensionsGroupConfig(extensions: IAzExtMetadata[], subscriptionId: string): GroupNodeConfiguration[] {
7171
const azExtGroupConfigs: GroupNodeConfiguration[] = [];
72-
for (const azExt of azureExtensions) {
72+
for (const azExt of extensions) {
7373
for (const resourceType of azExt.resourceTypes) {
7474
const type = typeof resourceType === 'string' ? resourceType : resourceType.name;
7575
const kind = azExt.name === 'vscode-azurefunctions' ? 'functionapp' : undefined;
@@ -118,6 +118,7 @@ export async function getArmTagKeys(context: IActionContext): Promise<Set<string
118118
// Execute `npm run listIcons` from root of repo to re-generate this list after adding an icon
119119
export const supportedIconTypes = [
120120
'microsoft.web/functionapp',
121+
'microsoft.web/logicapp',
121122
'microsoft.web/hostingenvironments',
122123
'microsoft.web/kubeenvironments',
123124
'microsoft.web/serverfarms',
@@ -183,14 +184,8 @@ interface SupportedType {
183184
}
184185

185186
function getName(type?: string, kind?: string): string | undefined {
186-
type = type?.toLowerCase();
187-
if (isFunctionApp(type, kind)) {
188-
type = 'microsoft.web/functionapp';
189-
}
190-
if (type) {
191-
return supportedTypes[type as SupportedTypes]?.displayName;
192-
}
193-
return undefined;
187+
const rType: string = getResourceType(type, kind).toLowerCase();
188+
return supportedTypes[rType as SupportedTypes]?.displayName;
194189
}
195190

196191
// intersect with Record<stirng, SupportedType> so we can add info for resources we don't have icons for
@@ -200,6 +195,7 @@ const supportedTypes: SupportedTypeMap = {
200195
'microsoft.web/sites': { displayName: localize('webApp', 'App Services') },
201196
'microsoft.web/staticsites': { displayName: localize('staticWebApp', 'Static Web Apps') },
202197
'microsoft.web/functionapp': { displayName: localize('functionApp', 'Function App') },
198+
'microsoft.web/logicapp': { displayName: localize('logicApp', 'Logic App') },
203199
'microsoft.compute/virtualmachines': { displayName: localize('virtualMachines', 'Virtual machines') },
204200
'microsoft.storage/storageaccounts': { displayName: localize('storageAccounts', 'Storage accounts') },
205201
'microsoft.network/networksecuritygroups': { displayName: localize('networkSecurityGroups', 'Network security groups') },
@@ -230,19 +226,39 @@ const supportedTypes: SupportedTypeMap = {
230226
'microsoft.app/containerapps': { displayName: localize('containerApp', 'Container Apps') },
231227
}
232228

233-
export function isFunctionApp(type?: string, kind?: string): boolean {
229+
export function isFunctionApp(resource: GenericResource): boolean {
230+
const { type, kind } = resource;
231+
if (type?.toLowerCase() === 'microsoft.web/sites') {
232+
if (kind?.toLowerCase().includes('functionapp') && !kind?.toLowerCase().includes('workflowapp')) {
233+
return true;
234+
}
235+
}
236+
return false;
237+
}
238+
239+
export function isLogicApp(resource: GenericResource): boolean {
240+
const { type, kind } = resource;
234241
if (type?.toLowerCase() === 'microsoft.web/sites') {
235-
if (kind?.toLowerCase().includes('functionapp')) {
242+
if (kind?.toLowerCase().includes('functionapp') && kind?.toLowerCase().includes('workflowapp')) {
236243
return true;
237244
}
238245
}
239246
return false;
240247
}
241248

249+
export function isAppServiceApp(resource: GenericResource): boolean {
250+
return resource.type?.toLowerCase() === 'microsoft.web/sites'
251+
&& !isFunctionApp(resource)
252+
&& !isLogicApp(resource);
253+
}
254+
242255
function getRelevantKind(type?: string, kind?: string): string | undefined {
243-
if (isFunctionApp(type, kind)) {
256+
if (isFunctionApp({ type, kind })) {
244257
return 'functionapp';
245258
}
259+
if (isLogicApp({ type, kind })) {
260+
return 'logicapp';
261+
}
246262
return undefined;
247263
}
248264

0 commit comments

Comments
 (0)