Skip to content

Commit

Permalink
Legg til erfaring som nytt søkefilter (#765)
Browse files Browse the repository at this point in the history
Legg til erfaring som nytt søkefilter
  • Loading branch information
kenove authored Aug 15, 2024
1 parent a848a9e commit 02088a9
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 13 deletions.
79 changes: 79 additions & 0 deletions src/app/(sok)/_components/filters/Experience.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import PropTypes from "prop-types";
import React from "react";
import { BodyShort, Checkbox, CheckboxGroup } from "@navikt/ds-react";
import { ADD_EXPERIENCE, REMOVE_EXPERIENCE } from "@/app/(sok)/_utils/queryReducer";
import mergeCount from "@/app/(sok)/_components/utils/mergeCount";
import { logFilterChanged } from "@/app/_common/monitoring/amplitude";

function Experience({ initialValues, updatedValues, query, dispatch }) {
const sortedValues = sortExperienceValues(initialValues);
const values = mergeCount(sortedValues, updatedValues);

function handleClick(e) {
const { value, checked } = e.target;
if (checked) {
dispatch({ type: ADD_EXPERIENCE, value });
} else {
dispatch({ type: REMOVE_EXPERIENCE, value });
}
logFilterChanged({ name: "Erfaring", value, checked });
}

return (
<CheckboxGroup
className="mb-4"
value={query.experience}
legend={
<>
<BodyShort as="span" visuallyHidden>
Filtrer etter erfaring
</BodyShort>
<span className="capitalize">Erfaring</span>
</>
}
>
{values.map((item) => (
<Checkbox key={item.key} name="experience[]" value={item.key} onChange={handleClick}>
{`${labelForExperience(item.key)} (${item.count})`}
</Checkbox>
))}
</CheckboxGroup>
);
}

export const labelForExperience = (key) => {
switch (key) {
case "Ingen":
return "Ingen krav til arbeidserfaring";
case "Noe":
return "Noe arbeidserfaring (1-3år)";
case "Mye":
return "Mye arbeidserfaring (4år+)";
default:
return key;
}
};

function sortExperienceValues(facets) {
if (!facets) {
return undefined;
}
const sortedPublishedValues = ["Ingen", "Noe", "Mye", "Ikke oppgitt"];
return facets.sort((a, b) => sortedPublishedValues.indexOf(a.key) - sortedPublishedValues.indexOf(b.key));
}

Experience.propTypes = {
initialValues: PropTypes.arrayOf(
PropTypes.shape({
key: PropTypes.string,
count: PropTypes.number,
}),
).isRequired,
updatedValues: PropTypes.arrayOf(PropTypes.shape({})),
query: PropTypes.shape({
experience: PropTypes.arrayOf(PropTypes.string),
}).isRequired,
dispatch: PropTypes.func.isRequired,
};

export default Experience;
17 changes: 11 additions & 6 deletions src/app/(sok)/_components/filters/FiltersDesktop.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from "react";
import PropTypes from "prop-types";
import { Accordion, Alert, Button, Link as AkselLink } from "@navikt/ds-react";
import { Accordion, Alert, Button } from "@navikt/ds-react";
import Remote from "@/app/(sok)/_components/filters/Remote";
import Education from "@/app/(sok)/_components/filters/Education";
import DriversLicense from "@/app/(sok)/_components/filters/DriversLicense";
import Experience from "@/app/(sok)/_components/filters/Experience";
import NewFiltersMessage from "@/app/(sok)/_components/filters/NewFiltersMessage";
import FilterAccordionItem from "./FilterAccordionItem";
import Published from "./Published";
import Counties from "./Locations";
Expand Down Expand Up @@ -54,19 +56,22 @@ function FiltersDesktop({ query, dispatchQuery, aggregations, locations, searchR
updatedValues={searchResult.aggregations.sector}
/>
</FilterAccordionItem>
<FilterAccordionItem title="Utdanning og førerkort" panelId="education">
<FilterAccordionItem title="Utdanning, erfaring og førerkort" panelId="education">
<Alert variant="info" className="mb-6">
Vi tester ut nye filtre og jobber med å gjøre dem mer nøyaktige. Har du noen tips?
<AkselLink href="https://surveys.hotjar.com/8eedca7e-3fae-4852-8d96-4c9c80424cdc">
Skriv en kort tilbakemelding
</AkselLink>
<NewFiltersMessage />
</Alert>
<Education
query={query}
dispatch={dispatchQuery}
initialValues={aggregations.education}
updatedValues={searchResult.aggregations.education}
/>
<Experience
query={query}
dispatch={dispatchQuery}
initialValues={aggregations.experience}
updatedValues={searchResult.aggregations.experience}
/>
<DriversLicense
query={query}
dispatch={dispatchQuery}
Expand Down
19 changes: 12 additions & 7 deletions src/app/(sok)/_components/filters/FiltersMobile.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useEffect, useRef, useState } from "react";
import PropTypes from "prop-types";
import { Alert, Button, Heading, HStack, Label, Modal, Link as AkselLink } from "@navikt/ds-react";
import { Alert, Button, Heading, HStack, Label, Modal } from "@navikt/ds-react";
import { ChevronRightIcon, ChevronLeftIcon } from "@navikt/aksel-icons";
import { formatNumber } from "@/app/_common/utils/utils";
import Remote from "@/app/(sok)/_components/filters/Remote";
import Education from "@/app/(sok)/_components/filters/Education";
import DriversLicense from "@/app/(sok)/_components/filters/DriversLicense";
import NewFiltersMessage from "@/app/(sok)/_components/filters/NewFiltersMessage";
import Experience from "@/app/(sok)/_components/filters/Experience";
import Counties from "./Locations";
import Occupations from "./Occupations";
import Published from "./Published";
Expand Down Expand Up @@ -57,7 +59,7 @@ function FiltersMobile({ onCloseClick, searchResult, query, dispatchQuery, aggre
"Publisert",
"Sted og hjemmekontor",
"Yrke og sektor",
"Utdanning og førerkort",
"Utdanning, erfaring og førerkort",
"Arbeidsspråk",
"Omfang og ansettelsesform",
].map((filter) => (
Expand Down Expand Up @@ -122,20 +124,23 @@ function FiltersMobile({ onCloseClick, searchResult, query, dispatchQuery, aggre
/>
</>
)}
{selectedFilter === "Utdanning og førerkort" && (
{selectedFilter === "Utdanning, erfaring og førerkort" && (
<>
<Alert variant="info" className="mb-4">
Vi tester ut et nytt filter og jobber med å gjøre det mer nøyaktig. Har du noen tips?{" "}
<AkselLink href="https://surveys.hotjar.com/8eedca7e-3fae-4852-8d96-4c9c80424cdc">
Skriv en kort tilbakemelding
</AkselLink>
<NewFiltersMessage />
</Alert>
<Education
query={query}
dispatch={dispatchQuery}
initialValues={aggregations.education}
updatedValues={searchResult.aggregations.education}
/>
<Experience
query={query}
dispatch={dispatchQuery}
initialValues={aggregations.experience}
updatedValues={searchResult.aggregations.experience}
/>
<DriversLicense
query={query}
dispatch={dispatchQuery}
Expand Down
14 changes: 14 additions & 0 deletions src/app/(sok)/_components/filters/NewFiltersMessage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { Link as AkselLink } from "@navikt/ds-react";

export default function NewFiltersMessage() {
return (
<>
Vi tester ut nye filtre og jobber med å gjøre dem mer nøyaktige. Vi bruker kunstig intelligens (KI) til å
hjelpe oss med dette. Hvordan opplever du søkeresultatet?{" "}
<AkselLink href="https://surveys.hotjar.com/8eedca7e-3fae-4852-8d96-4c9c80424cdc">
Skriv en kort tilbakemelding
</AkselLink>
</>
);
}
17 changes: 17 additions & 0 deletions src/app/(sok)/_components/selectedFilters/SelectedFilters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TrashIcon } from "@navikt/aksel-icons";
import fixLocationName from "@/app/_common/utils/fixLocationName";
import { labelForNeedDriversLicense } from "@/app/(sok)/_components/filters/DriversLicense";
import { labelForEducation } from "@/app/(sok)/_components/filters/Education";
import { labelForExperience } from "@/app/(sok)/_components/filters/Experience";
import {
REMOVE_COUNTRY,
REMOVE_COUNTY,
Expand All @@ -22,6 +23,7 @@ import {
SET_PUBLISHED,
SET_SEARCH_STRING,
REMOVE_OCCUPATION,
REMOVE_EXPERIENCE,
} from "../../_utils/queryReducer";
import { PublishedLabelsEnum } from "../../_utils/query";
import SaveSearchButton from "../../../lagrede-sok/_components/SaveSearchButton";
Expand Down Expand Up @@ -264,6 +266,21 @@ function SelectedFilters({ query, queryDispatch }) {
}),
);

chips.push(
...query.experience.map((value) => {
const label = labelForExperience(value);
return (
<Chips.Removable
variant="neutral"
key={`experience-${value}`}
onClick={() => queryDispatch({ type: REMOVE_EXPERIENCE, value })}
>
{label === "Ikke oppgitt" ? "Erfaring ikke oppgitt" : label}
</Chips.Removable>
);
}),
);

if (query.remote.length > 0) {
chips.push(
...query.remote.map((value) => (
Expand Down
Loading

0 comments on commit 02088a9

Please sign in to comment.