From b5c485b03463b0460dc980177c7c5bda05b203c6 Mon Sep 17 00:00:00 2001 From: Anna Kocheshkova Date: Thu, 3 May 2018 11:35:29 +0300 Subject: [PATCH] Got rid of MenuHelper (#57) --- src/appcenter/commands/createAppCommand.ts | 6 +- .../commands/reactNativeAppCommand.ts | 6 +- src/helpers/menuHelper.ts | 73 ------------------- src/menu/menu.ts | 68 ++++++++++++++++- 4 files changed, 73 insertions(+), 80 deletions(-) delete mode 100644 src/helpers/menuHelper.ts diff --git a/src/appcenter/commands/createAppCommand.ts b/src/appcenter/commands/createAppCommand.ts index 92ac53b..ab18260 100644 --- a/src/appcenter/commands/createAppCommand.ts +++ b/src/appcenter/commands/createAppCommand.ts @@ -3,10 +3,10 @@ import AppCenterAppBuilder from "../../appCenterAppBuilder"; import { Constants } from "../../constants"; import { AppCenterUrlBuilder } from "../../helpers/appCenterUrlBuilder"; import { CreatedAppFromAppCenter, Profile, QuickPickAppItem, UserOrOrganizationItem } from '../../helpers/interfaces'; -import { MenuHelper } from "../../helpers/menuHelper"; import { Utils } from "../../helpers/utils"; import { Validators } from "../../helpers/validators"; import { CustomQuickPickItem, IButtonMessageItem, VsCodeUtils } from '../../helpers/vsCodeUtils'; +import * as Menu from "../../menu/menu"; import { Strings } from '../../strings'; import { models } from '../apis'; import { Command } from './command'; @@ -48,7 +48,7 @@ export class CreateAppCommand extends Command { }); }).then(async (orgList: models.ListOKResponseItem[]) => { const myself: Profile | null = await this.appCenterProfile; - items = MenuHelper.getQuickPickItemsForOrgList(orgList, myself); + items = Menu.getQuickPickItemsForOrgList(orgList, myself); }); return items; } @@ -97,7 +97,7 @@ export class CreateAppCommand extends Command { return vscode.window.showQuickPick(userOrOrgQuickPickItems, { placeHolder: Strings.PleaseSelectCurrentAppOrgMsg, ignoreFocusOut: true }) .then(async (selectedQuickPickItem: CustomQuickPickItem) => { if (selectedQuickPickItem) { - const userOrOrgItem: UserOrOrganizationItem | null = MenuHelper.getSelectedUserOrOrgItem(selectedQuickPickItem, userOrOrgQuickPickItems); + const userOrOrgItem: UserOrOrganizationItem | null = Menu.getSelectedUserOrOrgItem(selectedQuickPickItem, userOrOrgQuickPickItems); if (!userOrOrgItem) { VsCodeUtils.ShowErrorMessage(Strings.FailedToGetSelectedUserOrOrganizationMsg); return null; diff --git a/src/appcenter/commands/reactNativeAppCommand.ts b/src/appcenter/commands/reactNativeAppCommand.ts index bd60fab..c8a1ef8 100644 --- a/src/appcenter/commands/reactNativeAppCommand.ts +++ b/src/appcenter/commands/reactNativeAppCommand.ts @@ -2,9 +2,9 @@ import { Md5 } from "ts-md5/dist/md5"; import * as vscode from "vscode"; import { CommandNames, Constants } from '../../constants'; import { AppCenterProfile, CommandParams, CurrentApp, QuickPickAppItem } from '../../helpers/interfaces'; -import { MenuHelper } from "../../helpers/menuHelper"; import { Utils } from '../../helpers/utils'; import { VsCodeUtils } from '../../helpers/vsCodeUtils'; +import * as Menu from "../../menu/menu"; import { Strings } from '../../strings'; import { models } from '../apis'; import { Command } from './command'; @@ -86,7 +86,7 @@ export class ReactNativeAppCommand extends Command { if (!force) { ReactNativeAppCommand.cachedApps = rnApps; } - const options: QuickPickAppItem[] = MenuHelper.getQuickPickItemsForAppsList(rnApps); + const options: QuickPickAppItem[] = Menu.getQuickPickItemsForAppsList(rnApps); if (includeCreateNew) { const createNewAppItem = { label: Strings.CreateNewAppMenuLabel, @@ -166,7 +166,7 @@ export class ReactNativeAppCommand extends Command { } protected showCreateAppOptions() { - const appCenterPortalTabOptions: vscode.QuickPickItem[] = MenuHelper.getCreateAppOptions(); + const appCenterPortalTabOptions: vscode.QuickPickItem[] = Menu.getCreateAppOptions(); return vscode.window.showQuickPick(appCenterPortalTabOptions, { placeHolder: Strings.CreateAppPlaceholder }) .then(async (selected: QuickPickAppItem) => { diff --git a/src/helpers/menuHelper.ts b/src/helpers/menuHelper.ts deleted file mode 100644 index ad38e45..0000000 --- a/src/helpers/menuHelper.ts +++ /dev/null @@ -1,73 +0,0 @@ -import * as vscode from "vscode"; -import { models } from "../appcenter/apis"; -import { CommandNames } from "../constants"; -import { Strings } from "../strings"; -import { Profile, UserOrOrganizationItem } from "./interfaces"; -import { CustomQuickPickItem } from "./vsCodeUtils"; - -export class MenuHelper { - - public static getSelectedUserOrOrgItem(selected: CustomQuickPickItem, allItems: CustomQuickPickItem[]): UserOrOrganizationItem | null { - let userOrOrgItem: UserOrOrganizationItem; - const selectedUserOrOrgs: CustomQuickPickItem[] = allItems.filter(item => item.target === selected.target); - if (selectedUserOrOrgs && selectedUserOrOrgs.length === 1) { - userOrOrgItem = { - name: selectedUserOrOrgs[0].target, - displayName: selectedUserOrOrgs[0].label, - isOrganization: selectedUserOrOrgs[0].description !== Strings.UserMenuDescriptionLabel - }; - return userOrOrgItem; - } else { - return null; - } - } - - public static getCreateAppOptions(): vscode.QuickPickItem[] { - const createAppOptions: vscode.QuickPickItem[] = []; - createAppOptions.push({ - label: Strings.CreateNewAndroidAppMenuLabel, - description: "", - target: CommandNames.CreateApp.Android - }); - createAppOptions.push({ - label: Strings.CreateNewIOSAppMenuLabel, - description: "", - target: CommandNames.CreateApp.IOS - }); - createAppOptions.push({ - label: Strings.CreateNewAppsForBothMenuLabel, - description: "", - target: CommandNames.CreateApp.Both - }); - return createAppOptions; - } - - public static getQuickPickItemsForAppsList(appsList: models.AppResponse[]) { - return appsList.map((app: models.AppResponse) => { - return { - label: `${app.name} (${app.os})`, - description: app.owner.type, - target: `${app.name}` - }; - }); - } - - public static getQuickPickItemsForOrgList(orgList: models.ListOKResponseItem[], myself: Profile | null): CustomQuickPickItem[] { - const options: CustomQuickPickItem[] = orgList.map(item => { - return { - label: `${item.displayName} (${item.name})`, - description: Strings.OrganizationMenuDescriptionLabel, - target: item.name - }; - }); - if (myself) { - // Insert user at the very 1st position - options.splice(0, 0, { - label: `${myself.displayName}`, - description: Strings.UserMenuDescriptionLabel, - target: myself.userName - }); - } - return options; - } -} diff --git a/src/menu/menu.ts b/src/menu/menu.ts index 6c8bc8a..4515f89 100644 --- a/src/menu/menu.ts +++ b/src/menu/menu.ts @@ -1,8 +1,10 @@ import * as vscode from "vscode"; +import { models } from "../appcenter/apis"; import { AppCenterBeacons, AppCenterCrashesTabs, AppCenterDistributionTabs, CommandNames } from "../constants"; import { FSUtils } from "../helpers/fsUtils"; -import { CommandParams, CurrentApp, MenuQuickPickItem } from "../helpers/interfaces"; +import { CommandParams, CurrentApp, MenuQuickPickItem, Profile, UserOrOrganizationItem } from "../helpers/interfaces"; import { Utils } from "../helpers/utils"; +import { CustomQuickPickItem } from "../helpers/vsCodeUtils"; import { ILogger } from "../log/logHelper"; import { Strings } from "../strings"; @@ -235,3 +237,67 @@ export class MenuItems { command: CommandNames.Settings.HideStatusBar }; } + +export function getSelectedUserOrOrgItem(selected: CustomQuickPickItem, allItems: CustomQuickPickItem[]): UserOrOrganizationItem | null { + let userOrOrgItem: UserOrOrganizationItem; + const selectedUserOrOrgs: CustomQuickPickItem[] = allItems.filter(item => item.target === selected.target); + if (selectedUserOrOrgs && selectedUserOrOrgs.length === 1) { + userOrOrgItem = { + name: selectedUserOrOrgs[0].target, + displayName: selectedUserOrOrgs[0].label, + isOrganization: selectedUserOrOrgs[0].description !== Strings.UserMenuDescriptionLabel + }; + return userOrOrgItem; + } else { + return null; + } +} + +export function getCreateAppOptions(): vscode.QuickPickItem[] { + const createAppOptions: vscode.QuickPickItem[] = []; + createAppOptions.push({ + label: Strings.CreateNewAndroidAppMenuLabel, + description: "", + target: CommandNames.CreateApp.Android + }); + createAppOptions.push({ + label: Strings.CreateNewIOSAppMenuLabel, + description: "", + target: CommandNames.CreateApp.IOS + }); + createAppOptions.push({ + label: Strings.CreateNewAppsForBothMenuLabel, + description: "", + target: CommandNames.CreateApp.Both + }); + return createAppOptions; +} + +export function getQuickPickItemsForAppsList(appsList: models.AppResponse[]) { + return appsList.map((app: models.AppResponse) => { + return { + label: `${app.name} (${app.os})`, + description: app.owner.type, + target: `${app.name}` + }; + }); +} + +export function getQuickPickItemsForOrgList(orgList: models.ListOKResponseItem[], myself: Profile | null): CustomQuickPickItem[] { + const options: CustomQuickPickItem[] = orgList.map(item => { + return { + label: `${item.displayName} (${item.name})`, + description: Strings.OrganizationMenuDescriptionLabel, + target: item.name + }; + }); + if (myself) { + // Insert user at the very 1st position + options.splice(0, 0, { + label: `${myself.displayName}`, + description: Strings.UserMenuDescriptionLabel, + target: myself.userName + }); + } + return options; +}