Always allow user to select group

Summary: This diff always allows user to select the group irrespective of the validation error. We will show the validation error at the bottom before letting them submit.

Reviewed By: passy

Differential Revision: D19816805

fbshipit-source-id: ff576a2101a5ed548c56a2f08da8d27457ebf332
This commit is contained in:
Pritesh Nandgaonkar
2020-02-11 05:47:24 -08:00
committed by Facebook Github Bot
parent 17e6e454f5
commit c8548e8063

View File

@@ -25,6 +25,7 @@ import {State as PluginStatesState} from './pluginStates';
import {State as PluginsState} from '../reducers/plugins'; import {State as PluginsState} from '../reducers/plugins';
import {State as PluginMessageQueueState} from '../reducers/pluginMessageQueue'; import {State as PluginMessageQueueState} from '../reducers/pluginMessageQueue';
import Client from '../Client'; import Client from '../Client';
import {OS} from '../devices/BaseDevice';
const { const {
GRAPHQL_IOS_SUPPORT_GROUP_ID, GRAPHQL_IOS_SUPPORT_GROUP_ID,
@@ -39,41 +40,67 @@ type MediaObject = SubmediaType & {
path: string; path: string;
}; };
export type GroupValidationErrors = {
plugins: string | null;
os: string | null;
};
export class Group { export class Group {
constructor( constructor(
name: GroupNames, name: GroupNames,
workplaceGroupID: number, workplaceGroupID: number,
requiredPlugins: Array<string>, requiredPlugins: Array<string>,
defaultPlugins: Array<string>, defaultPlugins: Array<string>,
supportedOS: Array<OS>,
) { ) {
this.name = name; this.name = name;
this.requiredPlugins = requiredPlugins; this.requiredPlugins = requiredPlugins;
this.defaultPlugins = defaultPlugins; this.defaultPlugins = defaultPlugins;
this.workplaceGroupID = workplaceGroupID; this.workplaceGroupID = workplaceGroupID;
this.supportedOS = supportedOS;
} }
readonly name: GroupNames; readonly name: GroupNames;
requiredPlugins: Array<string>; requiredPlugins: Array<string>;
defaultPlugins: Array<string>; defaultPlugins: Array<string>;
workplaceGroupID: number; workplaceGroupID: number;
supportedOS: Array<OS>;
getValidationMessage(selectedPlugins: Array<string>): string | null { getValidationMessage(
selectedPlugins: Array<string>,
selectedOS: OS | null,
): GroupValidationErrors {
const nonSelectedPlugin: Array<string> = []; const nonSelectedPlugin: Array<string> = [];
for (const plugin of this.requiredPlugins) { for (const plugin of this.requiredPlugins) {
if (!selectedPlugins.includes(plugin)) { if (!selectedPlugins.includes(plugin)) {
nonSelectedPlugin.push(plugin); nonSelectedPlugin.push(plugin);
} }
} }
if (nonSelectedPlugin.length <= 0) {
return null; // Plugin validation
} let str: string | null =
let str = 'should be exported if you want to submit to this group.'; 'should be exported if you want to submit to this group. Make sure, if your selected app supports those plugins, if so then enable it and select it from the plugin selection.';
if (nonSelectedPlugin.length == 1) { if (nonSelectedPlugin.length == 1) {
str = `the ${nonSelectedPlugin.pop()} plugin ${str}`; str = `the ${nonSelectedPlugin.pop()} plugin ${str}`;
} else { } else if (nonSelectedPlugin.length > 1) {
const lastPlugin = nonSelectedPlugin.pop(); const lastPlugin = nonSelectedPlugin.pop();
str = `the ${nonSelectedPlugin.join(',')} and ${lastPlugin} ${str}`; str = `the ${nonSelectedPlugin.join(',')} and ${lastPlugin} ${str}`;
} else {
// nonSelectedPlugin is empty
str = null;
} }
return str;
// OS validation
let osError: string | null = null;
if (!selectedOS) {
osError = 'Please select an app from the drop down.';
} else if (!this.supportedOS.includes(selectedOS)) {
osError = `The group ${
this.name
} supports exports from ${this.supportedOS.join(
', ',
)}. But your selected device's OS is ${selectedOS}, which is unsupported.`;
}
return {plugins: str, os: osError};
} }
handleSupportFormDeeplinks(store: Store) { handleSupportFormDeeplinks(store: Store) {
@@ -227,6 +254,7 @@ export const LITHO_GROUP = new Group(
LITHO_SUPPORT_GROUP_ID, LITHO_SUPPORT_GROUP_ID,
['Inspector'], ['Inspector'],
['Inspector', 'Sections', 'DeviceLogs'], ['Inspector', 'Sections', 'DeviceLogs'],
['Android'],
); );
export const GRAPHQL_ANDROID_GROUP = new Group( export const GRAPHQL_ANDROID_GROUP = new Group(
@@ -234,6 +262,7 @@ export const GRAPHQL_ANDROID_GROUP = new Group(
GRAPHQL_ANDROID_SUPPORT_GROUP_ID, GRAPHQL_ANDROID_SUPPORT_GROUP_ID,
['GraphQL'], ['GraphQL'],
['GraphQL', 'DeviceLogs'], ['GraphQL', 'DeviceLogs'],
['Android'],
); );
export const GRAPHQL_IOS_GROUP = new Group( export const GRAPHQL_IOS_GROUP = new Group(
@@ -241,6 +270,7 @@ export const GRAPHQL_IOS_GROUP = new Group(
GRAPHQL_IOS_SUPPORT_GROUP_ID, GRAPHQL_IOS_SUPPORT_GROUP_ID,
['GraphQL'], ['GraphQL'],
['GraphQL', 'DeviceLogs'], ['GraphQL', 'DeviceLogs'],
['iOS'],
); );
export const SUPPORTED_GROUPS: Array<Group> = [ export const SUPPORTED_GROUPS: Array<Group> = [