@@ -4,7 +4,7 @@ import SkillsCheckboxGroup from './SkillsCheckboxGroup'
44import Select from '../../../../components/Select/Select'
55import './SkillsQuestion.scss'
66import { axiosInstance as axios } from '../../../../api/requestInterceptor'
7- import { TC_API_URL } from '../../../../config/constants'
7+ import { TC_API_URL , SKILL_PROVIDER_ID } from '../../../../config/constants'
88import { createFilter } from 'react-select'
99
1010let cachedOptions
@@ -21,6 +21,9 @@ let cachedOptions
2121 * @returns {Array } available options
2222 */
2323const getAvailableOptions = ( categoriesMapping , selectedCategories , skillsCategories , options ) => {
24+ // NOTE:
25+ // Disable filtering skills by categories for now, because V5 Skills API doesn't have categories for now.
26+ /*
2427 let mappedCategories
2528 if (categoriesMapping) {
2629 mappedCategories = _.map(selectedCategories, (category) => categoriesMapping[category] ? categoriesMapping[category].toLowerCase() : null)
@@ -31,6 +34,7 @@ const getAvailableOptions = (categoriesMapping, selectedCategories, skillsCatego
3134 if (mappedCategories) {
3235 return options.filter(option => _.intersection((option.categories || []).map(c => c.toLowerCase()), mappedCategories).length > 0)
3336 }
37+ */
3438 return options
3539}
3640
@@ -48,12 +52,15 @@ class SkillsQuestion extends React.PureComponent {
4852
4953 componentWillMount ( ) {
5054 if ( ! cachedOptions ) {
51- axios . get ( `${ TC_API_URL } /v3/tags/?domain=SKILLS&status=APPROVED ` )
55+ axios . get ( `${ TC_API_URL } /v5/skills?skillProviderId= ${ SKILL_PROVIDER_ID } &perPage=100 ` )
5256 . then ( resp => {
53- const options = _ . get ( resp . data , 'result.content ' , { } )
57+ const options = _ . get ( resp , 'data ' , [ ] )
5458
55- cachedOptions = options
56- this . updateOptions ( options )
59+ cachedOptions = options . map ( ( option ) => ( {
60+ skillId : option . id ,
61+ name : option . name
62+ } ) )
63+ this . updateOptions ( cachedOptions )
5764 } )
5865 } else {
5966 this . updateOptions ( cachedOptions )
@@ -77,7 +84,7 @@ class SkillsQuestion extends React.PureComponent {
7784 this . setState ( { options } )
7885 this . updateAvailableOptions ( this . props , options )
7986 if ( onSkillsLoaded ) {
80- onSkillsLoaded ( options . map ( ( option ) => _ . pick ( option , [ 'id' , 'name' ] ) ) )
87+ onSkillsLoaded ( options )
8188 }
8289 }
8390
@@ -93,7 +100,6 @@ class SkillsQuestion extends React.PureComponent {
93100
94101 // if have a mapping for categories, then filter options, otherwise use all options
95102 const availableOptions = getAvailableOptions ( categoriesMapping , selectedCategories , skillsCategories , options )
96- . map ( option => _ . pick ( option , [ 'id' , 'name' ] ) )
97103 this . setState ( { availableOptions } )
98104 }
99105
@@ -182,17 +188,17 @@ class SkillsQuestion extends React.PureComponent {
182188 const selectedCategories = _ . get ( currentProjectData , categoriesField , [ ] )
183189
184190 let currentValues = getValue ( ) || [ ]
185- // remove from currentValues not available options but still keep created custom options without id
186- currentValues = currentValues . filter ( skill => _ . some ( availableOptions , skill ) || ! skill . id )
191+ // remove from currentValues not available options but still keep created custom options without 'skillId'
192+ currentValues = currentValues . filter ( skill => _ . some ( availableOptions , skill ) || ! skill . skillId )
187193
188194 const questionDisabled = isFormDisabled ( ) || disabled || ( selectedCategories . length === 0 && _ . isUndefined ( skillsCategories ) )
189195 const hasError = ! isPristine ( ) && ! isValid ( )
190196 const errorMessage = getErrorMessage ( ) || validationError
191197
192- const checkboxGroupOptions = availableOptions . filter ( option => frequentSkills . indexOf ( option . id ) > - 1 )
193- const checkboxGroupValues = currentValues . filter ( val => _ . some ( checkboxGroupOptions , option => option . id === val . id ) )
198+ const checkboxGroupOptions = availableOptions . filter ( option => frequentSkills . indexOf ( option . skillId ) > - 1 )
199+ const checkboxGroupValues = currentValues . filter ( val => _ . some ( checkboxGroupOptions , option => option . skillId === val . skillId ) )
194200
195- const selectGroupOptions = availableOptions . filter ( option => frequentSkills . indexOf ( option . id ) === - 1 )
201+ const selectGroupOptions = availableOptions . filter ( option => frequentSkills . indexOf ( option . skillId ) === - 1 )
196202 if ( customOptionValue ) {
197203 selectGroupOptions . unshift ( { name : customOptionValue } )
198204 }
0 commit comments