Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 7cc6663

Browse files
committed
feat: Ordering of Skills in Skill Select list. Issue #498
1 parent 62902e4 commit 7cc6663

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

local/login-locally/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* useLoadSkills hook
3+
*/
4+
import { useEffect, useState } from "react";
5+
import { flatten, partition } from "lodash";
6+
import { useData } from "hooks/useData";
7+
import { getSkills } from "services/skills";
8+
import { getRoles } from "services/roles";
9+
10+
/**
11+
* Hook which loads all skills and roles, then partitions skills based
12+
* on whether any role requires the given skill.
13+
*
14+
* @returns [skills, error] tuple with `skills` array and `error` object
15+
*/
16+
export const useLoadSkills = () => {
17+
const [skills, skillsError] = useData(getSkills);
18+
const [roles, rolesError] = useData(getRoles);
19+
const [partedSkills, setPartedSkills] = useState();
20+
21+
useEffect(() => {
22+
if (skills && roles) {
23+
const requiredSkills = new Set();
24+
roles.forEach((role) => {
25+
role.listOfSkills.forEach((skill) => {
26+
requiredSkills.add(skill);
27+
});
28+
});
29+
setPartedSkills(() =>
30+
flatten(partition(skills, (skill) => requiredSkills.has(skill.name)))
31+
);
32+
}
33+
}, [skills, roles]);
34+
35+
return [partedSkills, skillsError || rolesError];
36+
};

src/routes/CreateNewTeam/pages/InputSkills/index.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
*/
88
import React, { useCallback, useState } from "react";
99
import { useDispatch } from "react-redux";
10-
import { useData } from "hooks/useData";
1110
import { setIsLoading } from "../../actions";
1211
import SkillsList from "./components/SkillsList";
13-
import { getSkills } from "services/skills";
1412
import LoadingIndicator from "components/LoadingIndicator";
1513
import SkillListPopup from "../../components/SkillListPopup";
1614
import SearchAndSubmit from "../../components/SearchAndSubmit";
15+
import { useLoadSkills } from "../../hooks/useLoadSkills";
1716

1817
function InputSkills() {
1918
const dispatch = useDispatch();
@@ -26,7 +25,7 @@ function InputSkills() {
2625
const [popupSelectedSkills, setPopupSelectedSkills] = useState([]);
2726
const [popupOpen, setPopupOpen] = useState(false);
2827
const [isPopupLoading, setIsPopupLoading] = useState(false);
29-
const [skills, loadingError] = useData(getSkills);
28+
const [skills, loadingError] = useLoadSkills();
3029

3130
const toggleSkill = useCallback(
3231
(skill) => {

0 commit comments

Comments
 (0)