From c848e26e3a7ea2d360caba9b9ecd746d4b21548c Mon Sep 17 00:00:00 2001 From: yoution Date: Fri, 26 Feb 2021 07:37:02 +0800 Subject: [PATCH 1/4] fix: issue #120 --- src/constants/index.js | 11 +++++++++++ src/routes/JobForm/utils.js | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/constants/index.js b/src/constants/index.js index 359d223c..1bd80127 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -266,6 +266,17 @@ export const WORKLOAD_OPTIONS = [ { value: "fractional", label: "fractional" }, ]; +/** + * resourceType options + */ +export const RESOURCE_TYPE_OPTIONS = [ + { value: null, label: "" }, + { value: "designer", label: "designer" }, + { value: "software-developer", label: "software developer" }, + { value: "data-scientist", label: "data scientist" }, + { value: "data-engineer", label: "data engineer" }, +]; + /** * status options */ diff --git a/src/routes/JobForm/utils.js b/src/routes/JobForm/utils.js index 7b0ed80b..2c58ab8d 100644 --- a/src/routes/JobForm/utils.js +++ b/src/routes/JobForm/utils.js @@ -7,6 +7,7 @@ import { RATE_TYPE_OPTIONS, STATUS_OPTIONS, WORKLOAD_OPTIONS, + RESOURCE_TYPE_OPTIONS, FORM_ROW_TYPE, FORM_FIELD_TYPE, } from "../../constants"; @@ -79,10 +80,9 @@ export const getEditJobConfig = (skillOptions, onSubmit) => { }, { label: "Resource Type", - type: FORM_FIELD_TYPE.TEXT, + type: FORM_FIELD_TYPE.SELECT, name: "resourceType", - maxLength: 255, - placeholder: "Resource Type", + selectOptions: RESOURCE_TYPE_OPTIONS, }, { label: "Resource Rate Frequency", From 7c885d7b68bf01a92eb34cfb771cc6755f37c23b Mon Sep 17 00:00:00 2001 From: yoution Date: Tue, 2 Mar 2021 20:37:39 +0800 Subject: [PATCH 2/4] fix: issue #120 --- src/constants/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constants/index.js b/src/constants/index.js index 1bd80127..980cfc12 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -271,10 +271,10 @@ export const WORKLOAD_OPTIONS = [ */ export const RESOURCE_TYPE_OPTIONS = [ { value: null, label: "" }, - { value: "designer", label: "designer" }, - { value: "software-developer", label: "software developer" }, - { value: "data-scientist", label: "data scientist" }, - { value: "data-engineer", label: "data engineer" }, + { value: "designer", label: "Designer" }, + { value: "software-developer", label: "Software Developer" }, + { value: "data-scientist", label: "Data Scientist" }, + { value: "data-engineer", label: "Data Engineer" }, ]; /** From 57e25c618b79c85b82b88865015a067e3ed37d2e Mon Sep 17 00:00:00 2001 From: yoution Date: Tue, 2 Mar 2021 20:56:11 +0800 Subject: [PATCH 3/4] fix: issue #120 --- src/routes/JobDetails/index.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/routes/JobDetails/index.jsx b/src/routes/JobDetails/index.jsx index 707f9db8..35de4fe6 100644 --- a/src/routes/JobDetails/index.jsx +++ b/src/routes/JobDetails/index.jsx @@ -6,6 +6,7 @@ */ import React, { useEffect, useState } from "react"; import PT from "prop-types"; +import _ from "lodash"; import Page from "../../components/Page"; import PageHeader from "../../components/PageHeader"; import { useData } from "hooks/useData"; @@ -20,6 +21,7 @@ import IconComputer from "../../assets/images/icon-computer.svg"; import IconDescription from "../../assets/images/icon-description.svg"; import IconOpenings from "../../assets/images/icon-openings.svg"; import Button from "../../components/Button"; +import { RESOURCE_TYPE_OPTIONS } from "../../constants"; import { formatDate } from "utils/format"; import "./styles.module.scss"; import { hasPermission } from "utils/permissions"; @@ -82,7 +84,13 @@ const JobDetails = ({ teamId, jobId }) => { {job.duration || "TBD"} }> - {job.resourceType} + {_.get( + _.find( + RESOURCE_TYPE_OPTIONS, + (t) => t.value === job.resourceType + ), + "label" + )} Date: Wed, 3 Mar 2021 07:51:59 +0800 Subject: [PATCH 4/4] fix: issue #120 --- src/components/TCForm/utils.js | 22 +--------------------- src/routes/JobDetails/index.jsx | 7 ++++--- src/utils/helpers.js | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/components/TCForm/utils.js b/src/components/TCForm/utils.js index 2c5fbcce..bdb33703 100644 --- a/src/components/TCForm/utils.js +++ b/src/components/TCForm/utils.js @@ -2,29 +2,9 @@ * TC Form utilty */ import _ from "lodash"; +import { getSelectOptionByValue } from "utils/helpers"; import { FORM_FIELD_TYPE } from "../../constants"; -/** - * Returns the option from list of option by value - * - * @param {any} value value of option - * @param {[{ label: string, value: any }]} selectOptions list of option - * - * @returns {{ label: string, value: any }} select option - */ -const getSelectOptionByValue = (value, selectOptions) => { - const option = _.find(selectOptions, { value }); - - if (!option) { - return { - label: `Unsuppored value: ${value}`, - value, - }; - } - - return option; -}; - /** * Extract value from field by type * @param {any} value value diff --git a/src/routes/JobDetails/index.jsx b/src/routes/JobDetails/index.jsx index 35de4fe6..908432f8 100644 --- a/src/routes/JobDetails/index.jsx +++ b/src/routes/JobDetails/index.jsx @@ -12,6 +12,7 @@ import PageHeader from "../../components/PageHeader"; import { useData } from "hooks/useData"; import { getJobById } from "services/jobs"; import { getSkills } from "services/skills"; +import { getSelectOptionByValue } from "utils/helpers"; import LoadingIndicator from "../../components/LoadingIndicator"; import MarkdownEditorViewer from "../../components/MarkdownEditorViewer"; import withAuthentication from "../../hoc/withAuthentication"; @@ -85,9 +86,9 @@ const JobDetails = ({ teamId, jobId }) => { }> {_.get( - _.find( - RESOURCE_TYPE_OPTIONS, - (t) => t.value === job.resourceType + getSelectOptionByValue( + job.resourceType, + RESOURCE_TYPE_OPTIONS ), "label" )} diff --git a/src/utils/helpers.js b/src/utils/helpers.js index 2a3dcf73..53f24cd2 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -17,3 +17,24 @@ export const delay = (duration) => new Promise((resolve) => { setTimeout(resolve, duration); }); + +/** + * Returns the option from list of option by value + * + * @param {any} value value of option + * @param {[{ label: string, value: any }]} selectOptions list of option + * + * @returns {{ label: string, value: any }} select option + */ +export const getSelectOptionByValue = (value, selectOptions) => { + const option = _.find(selectOptions, { value }); + + if (!option) { + return { + label: `Unsuppored value: ${value}`, + value, + }; + } + + return option; +};