Skip to content

Commit

Permalink
Merge pull request #550 from MetaPhase-Consulting/update/skill-ap-filter
Browse files Browse the repository at this point in the history
Use mapping for AP skill codes
  • Loading branch information
mjoyce91 committed Nov 15, 2019
2 parents 91232cc + 5846c9f commit b744004
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/actions/filters/filters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, isArray, union } from 'lodash';
import { get, isArray, orderBy, union } from 'lodash';
import Q from 'q';
import api from '../../api';
import { ASYNC_PARAMS, ENDPOINT_PARAMS } from '../../Constants/EndpointParams';
Expand Down Expand Up @@ -255,7 +255,6 @@ export function filtersFetchData(items = { filters: [] }, queryParams = {}, save
} else {
// our static filters
const staticFilters = items.filters.slice().filter(item => (!item.item.endpoint));
responses.filters.push(...staticFilters);

// our dynamic filters
let dynamicFilters = items.filters.slice().filter(item => (item.item.endpoint));
Expand All @@ -279,6 +278,7 @@ export function filtersFetchData(items = { filters: [] }, queryParams = {}, save
},
}));
}

// We have a mix of server-supplied and hard-coded data, so we combine them with union.
// Also determine whether the results array exists,
// or if the array is passed at the top-level.
Expand All @@ -287,6 +287,25 @@ export function filtersFetchData(items = { filters: [] }, queryParams = {}, save
} else if (isArray(response.data)) {
itemFilter.data = union(response.data, data$);
}

// We handle skills differently depending on whether getUseAP === true,
// and we override what ever was done in the union prior to this block.
// Here we map the AP cone/code model to the old model so that it plays nice
// with our existing components.
if (item.item.description === 'skillCone' && getUseAP()) {
const skills = [];
itemFilter.data = response.data.map(m => ({ name: m.category, id: m.category }));
itemFilter.data = orderBy(itemFilter.data, 'name');
response.data.forEach((m) => {
m.skills.forEach(s => skills.push({
...s,
cone: m.category,
}));
});
const skillObject = staticFilters.find(f => f.item.description === 'skill');
skillObject.data = [...skills];
}

return itemFilter;
})
));
Expand All @@ -301,6 +320,7 @@ export function filtersFetchData(items = { filters: [] }, queryParams = {}, save
// Else, return the correct structure, but with no data. Include hasErrored prop.
responses.filters.push({ data: [], item: {}, hasErrored: true });
}
responses.filters.push(...staticFilters);
dispatchSuccess();
dispatch(filtersHasErrored(false));
dispatch(filtersIsLoading(false));
Expand Down
3 changes: 2 additions & 1 deletion src/reducers/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const items =
sort: 200,
description: 'skill',
endpoint: 'skill/',
endpointAP: 'fsbid/reference/codes/',
endpointAP: null, // because we check for 'has' in filterAPFilters()
selectionRef: ENDPOINT_PARAMS.skill,
text: 'Choose Skills',
},
Expand All @@ -87,6 +87,7 @@ const items =
title: 'Skill Cone',
description: 'skillCone',
endpoint: 'skill/cone/',
endpointAP: 'fsbid/reference/cones/',
},
data: [
],
Expand Down

0 comments on commit b744004

Please sign in to comment.