Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lhvy committed Sep 12, 2024
1 parent 5e37b2e commit 13c6711
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
23 changes: 12 additions & 11 deletions frontend/src/pages/DegreeWizard/DegreeStep/DegreeStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const DegreeStep = ({ incrementStep, setDegreeInfo }: Props) => {
queryKey: ['programs'],
queryFn: fetchAllDegrees,
select: (data) =>
Object.keys(data.programs).map((code) => {
return { label: `${code} ${data.programs[code]}`, value: `${code} ${data.programs[code]}` };
})
Object.keys(data.programs).map((code) => ({
label: `${code} ${data.programs[code]}`,
value: `${code} ${data.programs[code]}`
}))
});
const allDegrees = allDegreesQuery.data ?? [];

Expand All @@ -50,15 +51,15 @@ const DegreeStep = ({ incrementStep, setDegreeInfo }: Props) => {
return;
}

let fuzzedDegrees = allDegrees.map((item) => {
return {
score: fuzzy(newInput, item.label),
...item
};
});

// score is a number between 0 and 1 where 1 is a perfect match
fuzzedDegrees = fuzzedDegrees.filter((pair) => pair.score > 0.5);
const fuzzedDegrees = allDegrees
.map((item) => {
return {
score: fuzzy(newInput, item.label),
...item
};
})
.filter((pair) => pair.score > 0.5);

// Shorter name with greater or equal score means better match
fuzzedDegrees.sort((a, b) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@ const SpecialisationStep = ({
});
const options = specsQuery.data;

const selectGroups:
| {
label: string;
note: string | undefined;
children: { label: string; value: string }[];
}[]
| undefined = options
? Object.keys(options).map((program) => {
const group = {
label: `${type.replace(/^\w/, (c) => c.toUpperCase())} for ${program}`,
note: options[program].notes,
children: Object.keys(options[program].specs)
.sort()
.map((spec) => ({
label: `${spec} ${options[program].specs[spec]}`,
value: spec
}))
};
return group;
})
type SelectGroup = {
label: string;
note: string | undefined;
children: {
label: string;
value: string;
}[];
};

const selectGroups: SelectGroup[] | undefined = options
? Object.keys(options).map((program) => ({
label: `${type.replace(/^\w/, (c) => c.toUpperCase())} for ${program}`,
note: options[program].notes,
children: Object.keys(options[program].specs)
.sort()
.map((spec) => ({
label: `${spec} ${options[program].specs[spec]}`,
value: spec
}))
}))
: undefined;

// check if step is optional and can be skipped
Expand Down Expand Up @@ -132,9 +132,6 @@ const SpecialisationStep = ({
allowClear
placeholder={`Select ${type.substring(0, type.length - 1)}s`}
defaultValue={[]}
// value={degreeInfo.specs.filter((spec) =>
// group.children.some((child) => child.value === spec)
// )}
options={group.children}
onSelect={(value) => handleAddSpecialisation(value)}
onDeselect={(value) => handleRemoveSpecialisation(value)}
Expand Down

0 comments on commit 13c6711

Please sign in to comment.