Skip to content

Commit

Permalink
Remove janzz occupation suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mnhhd committed Sep 24, 2024
1 parent 1fe4377 commit ac7c342
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 57 deletions.
37 changes: 1 addition & 36 deletions src/app/(sok)/_components/searchBox/SearchCombobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,13 @@ import {
PUBLISHED,
SEARCH_STRING,
} from "@/app/(sok)/_components/searchParamNames";
import { FetchAction, useFetchReducer } from "@/app/_common/hooks/useFetchReducer";
import * as actions from "@/app/_common/actions";
import { findLabelForFilter, getSearchBoxOptions } from "@/app/(sok)/_components/searchBox/buildSearchBoxOptions";
import logAmplitudeEvent, { logFilterChanged } from "@/app/_common/monitoring/amplitude";

let suggestionsCache = [];
const CACHE_MAX_SIZE = 50;
const MINIMUM_LENGTH = 1;

function SearchCombobox({ aggregations, locations }) {
const searchQuery = useSearchQuery();
const [suggestionsResponse, suggestionsDispatch] = useFetchReducer([]);

const options = useMemo(
() => getSearchBoxOptions(aggregations, locations, [...suggestionsResponse.data]),
[aggregations, locations, suggestionsResponse.data],
);
const options = useMemo(() => getSearchBoxOptions(aggregations, locations), [aggregations, locations]);

const selectedOptions = useMemo(
() => buildSelectedOptions(searchQuery.urlSearchParams),
Expand All @@ -42,30 +32,6 @@ function SearchCombobox({ aggregations, locations }) {
: { label: o.label, value: o.value };
});

async function fetchSuggestions(value) {
const cached = suggestionsCache.find((c) => c.value === value);
if (cached) {
suggestionsDispatch({ type: FetchAction.RESOLVE, data: cached.data });
return;
}
let data;
try {
data = await actions.getSuggestions(value, MINIMUM_LENGTH);
} catch (err) {
// ignore fetch failed errors
}
if (data) {
suggestionsCache = [{ value, data }, ...suggestionsCache].slice(0, CACHE_MAX_SIZE);
suggestionsDispatch({ type: FetchAction.RESOLVE, data });
}
}

function handleValueChange(value) {
if (value && value.length >= MINIMUM_LENGTH) {
fetchSuggestions(value);
}
}

const handleFreeTextSearchOption = (value, isSelected) => {
if (isSelected) {
searchQuery.append(SEARCH_STRING, value);
Expand Down Expand Up @@ -173,7 +139,6 @@ function SearchCombobox({ aggregations, locations }) {
onToggleSelected={onToggleSelected}
selectedOptions={selectedOptions}
options={optionList}
onChange={handleValueChange}
/>
);
}
Expand Down
22 changes: 1 addition & 21 deletions src/app/(sok)/_components/searchBox/buildSearchBoxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
INTERNATIONAL,
MUNICIPAL,
NEED_DRIVERS_LICENSE,
OCCUPATION,
OCCUPATION_FIRST_LEVEL,
OCCUPATION_SECOND_LEVEL,
PUBLISHED,
Expand All @@ -28,7 +27,6 @@ import {
import { PublishedLabels } from "@/app/(sok)/_utils/publishedLabels";

const promotedOptions: ComboboxOption[] = [
{ label: "Butikkmedarbeider", value: `${OCCUPATION}-Butikkmedarbeider` },
{ label: "Deltid", value: `${EXTENT}-Deltid` },
{ label: labelForEducation("Ingen krav"), value: `${EDUCATION}-Ingen krav` },
{ label: labelForExperience("Ingen"), value: `${EXPERIENCE}-Ingen` },
Expand Down Expand Up @@ -199,17 +197,6 @@ function getRemoteOptions(aggregations: Aggregations): ComboboxOption[] {
);
}

function getOccupationSuggestionOptions(allSuggestions: string[]): ComboboxOption[] {
return allSuggestions
.map(
(suggestion): ComboboxOption => ({
label: suggestion,
value: `${OCCUPATION}-${suggestion}`,
}),
)
.filter((option) => !promotedValues.includes(option.value));
}

function getDriversLicenseOptions(aggregations: Aggregations): ComboboxOption[] {
return aggregations.needDriversLicense
.map(
Expand Down Expand Up @@ -238,11 +225,7 @@ function getExperienceOptions(aggregations: Aggregations): ComboboxOption[] {
.filter((option) => !promotedValues.includes(option.value));
}

export function getSearchBoxOptions(
aggregations: Aggregations,
locations: LocationList[],
allSuggestions: string[],
): ComboboxOption[] {
export function getSearchBoxOptions(aggregations: Aggregations, locations: LocationList[]): ComboboxOption[] {
const locationList = buildLocations(aggregations, locations);

return [
Expand All @@ -261,7 +244,6 @@ export function getSearchBoxOptions(
...getRemoteOptions(aggregations),
...getDriversLicenseOptions(aggregations),
...getExperienceOptions(aggregations),
...getOccupationSuggestionOptions(allSuggestions),
];
}

Expand All @@ -277,8 +259,6 @@ export const findLabelForFilter = (value: string): string => {
return "(Kategori)";
case OCCUPATION_SECOND_LEVEL:
return "(Kategori)";
case OCCUPATION:
return "(Yrke)";
case SECTOR:
return "(Sektor)";
case ENGAGEMENT_TYPE:
Expand Down

0 comments on commit ac7c342

Please sign in to comment.