Skip to content

Commit

Permalink
Merge pull request #35 from nulab/show-userfriendly-error-when-unsupp…
Browse files Browse the repository at this point in the history
…orted-custom-field-is-required

Show user-friendly error when unsupported custom field is required
  • Loading branch information
shomatan authored Sep 10, 2019
2 parents 8390052 + dd8b709 commit c9f8fee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/BacklogService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {BacklogClient, BacklogClientImpl, GoogleAppsScriptDateFormatter} from "./BacklogClient"
import {Key, Project, Issue, BacklogDefinition, Locale, UserProperty, CustomFieldDefinition, IssueType} from "./datas"
import {Key, Project, Issue, BacklogDefinition, Locale, UserProperty, CustomFieldDefinition, IssueType, isSupportedCustomField} from "./datas"
import {HttpClient} from "./Http"
import {Option, Some, None} from "./Option"
import {Either, Right, Left} from "./Either"
Expand Down Expand Up @@ -45,7 +45,14 @@ export const getProject = (client: BacklogClient, key: Key<Project>, locale: Loc
}

const validate = (issues: List<any>, issueTypes: List<IssueType>, customFieldDefinitions: List<CustomFieldDefinition>, client: BacklogClient, locale: Locale): Either<Error, boolean> => {
const definitions = customFieldDefinitions.filter(item => item.typeId < 6)
for (let i = 0; i < customFieldDefinitions.length; i++) {
const definition = customFieldDefinitions[i]

if (definition.required && !isSupportedCustomField(definition))
return Left(Error(Message.VALIDATE_CUSTOM_FIELD_VALUE_IS_REQUIRED_UNSUPPORTED(definition.name, locale)))
}

const definitions = customFieldDefinitions.filter(item => isSupportedCustomField(item))

for (let i = 0; i < issues.length; i++) {
const issue = issues[i]
Expand Down Expand Up @@ -353,7 +360,7 @@ export const BacklogService = (spreadSheetService: SpreadSheetService): BacklogS
*/
let customFieldName = ""

if (customField.typeId >= 6)
if (!isSupportedCustomField(customField))
continue
switch (customField.typeId) {
case 1:
Expand Down Expand Up @@ -395,7 +402,7 @@ export const BacklogService = (spreadSheetService: SpreadSheetService): BacklogS
let validationRuleIndex = 0
for (let i = 0; i < definition.customFields.length; i++) {
const customField = definition.customFields[i]
if (customField.typeId >= 6)
if (!isSupportedCustomField(customField))
continue
if (customField.typeId === 5) {
definition.customFieldItemNames(customField).map(itemNames => {
Expand Down
3 changes: 3 additions & 0 deletions src/datas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export interface CustomField extends WithId {
}
export const CustomField = (id: number, fieldTypeId: number, value: any) => ({id, fieldTypeId, value})

export const isSupportedCustomField = (definition: CustomFieldDefinition) =>
definition.typeId < 6

export interface BacklogDefinition {
readonly issueTypes: List<IssueType>
readonly categories: List<Category>
Expand Down
7 changes: 7 additions & 0 deletions src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ export const Message = {
}
return msg[locale]
},
VALIDATE_CUSTOM_FIELD_VALUE_IS_REQUIRED_UNSUPPORTED: (definitionName: string, locale: Locale): string => {
const msg = {
"en": `Custom field value '${definitionName}' is required but it isn't supported. Please cancel this setting.`,
"ja": `カスタム属性 '${definitionName}' は必須ですがサポートされていません。必須の設定を解除してください。`
}
return msg[locale]
},
VALIDATE_CUSTOM_FIELD_VALUE_IS_NUMBER: (definitionName: string, input: string, locale: Locale): string => {
const msg = {
"en": `Custom field value '${definitionName}' needs number. Row input: ${input}`,
Expand Down

0 comments on commit c9f8fee

Please sign in to comment.