-
Notifications
You must be signed in to change notification settings - Fork 94
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
Show labels for invalid app services #373
Conversation
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.
I'd prefer if you didn't change WebAppTreeItem. That should only be used if the site is valid.
Instead, can you change InvalidTreeItem to be InvalidWebAppTreeItem and have it at the same level as WebAppTreeItem? I also think the code would be clearer if we shifted from several 'filter' and 'map' calls to just a single 'map' call. Here's some pseudo-code:
const treeItems: IAzureTreeItem[] = [];
await Promise.all(webAppCollection
.map(async (s: Site) => {
try {
const siteClient: SiteClient = new SiteClient(s, node);
// check isFunctionApp and get appServicePlan
treeItems.push(new WebAppTreeItem(s, appServicePlan));
} catch {
treeItems.push(new InvalidWebAppTreeItem(s.name));
}
});
return treeItems;
Hopefully then you also won't have to create the fake Site
Here's what I've got so far...
Couple of questions/input needed...
|
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.
Looks much better! Just a few minor comments. I think you can do openInPortal pretty easily - just check if site.id is defined on your invalid web apps (If its not, then I just wouldn't do that feature)
src/explorer/WebAppTreeItem.ts
Outdated
@@ -126,3 +127,20 @@ export class WebAppTreeItem extends SiteTreeItem { | |||
return await fs.readFile(templatePath, 'utf8'); | |||
} | |||
} | |||
|
|||
export class InvalidWebAppTreeItem implements IAzureTreeItem { |
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.
Please move this to a separate file "InvalidWebAppTreeItem.ts"
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.
I included it here, as that's the same way the DeploymentSlotsNATreeItem
is defined in the DeploymentSlotsTreeItem.js
... there's a precedent for doing it like so... should I still move it to a different file?
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.
Yeah @nturinski did that, not me 😊 I generally prefer one exported class per file, since you never know how much a class will grow as time goes on
That being said - this is kind of a stylistic preference and I wouldn't block a PR just for this
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.
Went ahead and moved it to it's own file (I prefer it that way as well, lol).
src/explorer/WebAppTreeItem.ts
Outdated
@@ -126,3 +127,20 @@ export class WebAppTreeItem extends SiteTreeItem { | |||
return await fs.readFile(templatePath, 'utf8'); | |||
} | |||
} | |||
|
|||
export class InvalidWebAppTreeItem implements IAzureTreeItem { | |||
public static contextValue: string = 'file'; |
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.
I assume you copied this from the FileTreeItem haha? Please make the context value something like 'invalidWebApp' or 'invalidAppService'
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.
Lol, yeah, my bad... copy/paste got me. Renamed to 'invalidAppService' (matches the WebAppTreeItem better).
src/explorer/WebAppTreeItem.ts
Outdated
export class InvalidWebAppTreeItem implements IAzureTreeItem { | ||
public static contextValue: string = 'file'; | ||
public readonly contextValue: string = InvalidWebAppTreeItem.contextValue; | ||
public readonly commandId: string = 'appService.showFile'; |
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.
Remove the commandId property - it was only used in the FileTreeItem
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.
Fixed.
src/explorer/WebAppTreeItem.ts
Outdated
@@ -24,6 +24,7 @@ export class WebAppTreeItem extends SiteTreeItem { | |||
public readonly appSettingsNode: IAzureTreeItem; | |||
public readonly webJobsNode: IAzureTreeItem; | |||
public readonly folderNode: IAzureTreeItem; | |||
public readonly invalidAppServiceNode: IAzureTreeItem; |
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.
Remove this property - its never used
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.
Fixed
src/explorer/WebAppProvider.ts
Outdated
} catch (err) { | ||
return false; | ||
const siteClient: SiteClient = new SiteClient(s, node); | ||
const appServicePlan: AppServicePlan = await siteClient.getAppServicePlan(); |
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.
Wrap getAppServicePlan
and treeItems.push
in if (!siteClient.isFunctionApp)
We have a completely separate extension that handles function apps: https://github.com/Microsoft/vscode-azurefunctions
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.
Ugh, fixed... forgot about that.
src/explorer/WebAppProvider.ts
Outdated
const appServicePlan: AppServicePlan = await siteClient.getAppServicePlan(); | ||
treeItems.push(new WebAppTreeItem(siteClient, appServicePlan)); | ||
} catch { | ||
treeItems.push(new InvalidWebAppTreeItem(`${s.name} (invalid)`)); |
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.
I like 'invalid'. However, rather than doing the formatting yourself, please specify s.name
as the label
property and Invalid
as the description
property
That will ensure its displayed in the same format as our other description properties (which as of today is the same format that you did, but could change in the future)
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.
Description property added.
src/explorer/WebAppTreeItem.ts
Outdated
public readonly contextValue: string = InvalidWebAppTreeItem.contextValue; | ||
public readonly commandId: string = 'appService.showFile'; | ||
|
||
constructor(readonly label: string) { |
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.
If you didn't know, the contextValue is used to determine which commands are shown in the context menu. See the 'viewItem' property in package.json:
https://github.com/Microsoft/vscode-azureappservice/blob/master/package.json#L294
If you want to support OpenInPortal, just do the same thing in package.json except use this treeItem's contextValue as the viewItem instead of 'appService'. You also have to specify the id
property on this treeItem, which is used under the covers here for openInPortal. I don't think you'll have to completely construct the fake Site object - it should just be Site.id (which should probably exist even if serverFarmId does not - but idk)
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.
Yeah, site.id doesn't exist for these either, so that's not going to work. I'd love for it to just open to the "WebApps" blade in the portal, but I'm not sure how to get a direct link for that (when I go there in the portal, my tenant id is in the URL).
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.
I wouldn't worry about it then. Judging by these screenshots, the Portal wasn't that helpful anyways: #370 (comment)
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.
Roger that!
- Moved InvalideWebAppTreeItem to it's own file; - Added desciption property; - Cleaned up unused vars;
@@ -0,0 +1,25 @@ | |||
import * as path from 'path'; |
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.
Please add the Microsoft copyright header - I'm not an expert on the legalese but you can check out this section for more info: https://github.com/Microsoft/vscode-azureappservice#contributing
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.
Fixed.
import { } from 'vscode-azureappservice'; | ||
import { IAzureTreeItem } from 'vscode-azureextensionui'; | ||
import { } from '../constants'; | ||
import { } from './DeploymentSlotsTreeItem'; |
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.
Just remove the import lines without any variables
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.
Fixed.
src/extension.ts
Outdated
@@ -214,6 +215,13 @@ export function activate(context: vscode.ExtensionContext): void { | |||
|
|||
node.treeItem.openCdInPortal(node); | |||
}); | |||
actionHandler.registerCommand('invalidAppService.Invalid', async (node?: IAzureNode<InvalidWebAppTreeItem>) => { |
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.
What's the purpose of this command? Is it just to show the message? I think this would be confusing for users - a context menu command isn't the best place to show messages. Users expect context menu commands to actually do something
I don't think the message is necessary, but I can help you show the message as a child of the invalidAppService if you want
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.
Yeah, I get what you mean. Went ahead and removed it... I don't think any further indicator is necessary :)
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.
Awesome thanks!
Updated code from #372 to still allow the invalid resources to be listed along with the valid ones.