Got rid of MenuHelper (#57)
This commit is contained in:
Родитель
b3f5a4901e
Коммит
b5c485b034
|
@ -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;
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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(<vscode.QuickPickItem>{
|
||||
label: Strings.CreateNewAndroidAppMenuLabel,
|
||||
description: "",
|
||||
target: CommandNames.CreateApp.Android
|
||||
});
|
||||
createAppOptions.push(<vscode.QuickPickItem>{
|
||||
label: Strings.CreateNewIOSAppMenuLabel,
|
||||
description: "",
|
||||
target: CommandNames.CreateApp.IOS
|
||||
});
|
||||
createAppOptions.push(<vscode.QuickPickItem>{
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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(<vscode.QuickPickItem>{
|
||||
label: Strings.CreateNewAndroidAppMenuLabel,
|
||||
description: "",
|
||||
target: CommandNames.CreateApp.Android
|
||||
});
|
||||
createAppOptions.push(<vscode.QuickPickItem>{
|
||||
label: Strings.CreateNewIOSAppMenuLabel,
|
||||
description: "",
|
||||
target: CommandNames.CreateApp.IOS
|
||||
});
|
||||
createAppOptions.push(<vscode.QuickPickItem>{
|
||||
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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче