Skip to content
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

Merged
merged 12 commits into from
Mar 29, 2018
Merged

Conversation

sunmorgus
Copy link
Contributor

Updated code from #372 to still allow the invalid resources to be listed along with the valid ones.

Copy link
Contributor

@ejizba ejizba left a 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

@sunmorgus
Copy link
Contributor Author

Here's what I've got so far...

image

  1. Converted to "InvalidWebAppTreeItem" with no children
  2. Added grayscale webapp icon

Couple of questions/input needed...

  1. Can't decide whether to keep the "(invalid)" tag at the end of the label... I'd say having no children and the gray icon would be enough to indicate that there was some sort of problem, but I do like the extra little bit of info.
    1. I did attempt to add a child item using the "InvalidTreeItem", but that won't work without having to build the fake Site object like I did before.
  2. Considering attempting to include one or two context menu items for the invalid WebApps...
    1. "Open WebApps Portal" (since I can't do "Open In Portal" without a valid id). Not even sure I could do that though, without having full site info
    2. A static string item that says "App service configuration is invalid"

Copy link
Contributor

@ejizba ejizba left a 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)

@@ -126,3 +127,20 @@ export class WebAppTreeItem extends SiteTreeItem {
return await fs.readFile(templatePath, 'utf8');
}
}

export class InvalidWebAppTreeItem implements IAzureTreeItem {
Copy link
Contributor

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"

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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).

@@ -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';
Copy link
Contributor

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'

Copy link
Contributor Author

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).

export class InvalidWebAppTreeItem implements IAzureTreeItem {
public static contextValue: string = 'file';
public readonly contextValue: string = InvalidWebAppTreeItem.contextValue;
public readonly commandId: string = 'appService.showFile';
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -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;
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

} catch (err) {
return false;
const siteClient: SiteClient = new SiteClient(s, node);
const appServicePlan: AppServicePlan = await siteClient.getAppServicePlan();
Copy link
Contributor

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

Copy link
Contributor Author

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.

const appServicePlan: AppServicePlan = await siteClient.getAppServicePlan();
treeItems.push(new WebAppTreeItem(siteClient, appServicePlan));
} catch {
treeItems.push(new InvalidWebAppTreeItem(`${s.name} (invalid)`));
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description property added.

public readonly contextValue: string = InvalidWebAppTreeItem.contextValue;
public readonly commandId: string = 'appService.showFile';

constructor(readonly label: string) {
Copy link
Contributor

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)

Copy link
Contributor Author

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).

Copy link
Contributor

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)

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

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>) => {
Copy link
Contributor

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

Copy link
Contributor Author

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 :)

Copy link
Contributor

@ejizba ejizba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks!

@ejizba ejizba merged commit 27bcdd6 into microsoft:master Mar 29, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants