in src/amo/pages/SearchPage/index.js [47:132]
constructor(props: InternalProps) {
super(props);
const { clientApp, filters, lang, location } = props;
let pathname = '/search/';
let shouldRedirect = false;
const newFilters = { ...filters };
// If this is an old category search, redirect to the new category page,
// unless the `type` is invalid.
if (
newFilters.category &&
newFilters.addonType &&
visibleAddonTypeIsValid(newFilters.addonType) &&
// We have to add this below the call to visibleAddonTypeIsValid or
// Flow gets angry.
newFilters.addonType
) {
pathname = getCategoryResultsPathname({
addonType: newFilters.addonType,
slug: newFilters.category,
});
delete newFilters.addonType;
delete newFilters.category;
if (newFilters.sort === DEFAULT_CATEGORY_SORT) {
delete newFilters.sort;
}
shouldRedirect = true;
} else if (
// If this is a tag search we want to redirect to new tag pages.
newFilters.tag
) {
pathname = getTagResultsPathname({ tag: newFilters.tag });
delete newFilters.tag;
if (newFilters.sort === DEFAULT_TAG_SORT) {
delete newFilters.sort;
}
shouldRedirect = true;
}
// We removed the `platform` parameter, so if it's present, ignore it and
// redirect.
if (location.query.platform) {
shouldRedirect = true;
}
// Map the old `atype` parameter to its corresponding `adddonType`.
// See: https://github.com/mozilla/addons-frontend/issues/3791.
if (location.query.atype) {
switch (String(location.query.atype)) {
case '1':
newFilters.addonType = ADDON_TYPE_EXTENSION;
break;
case '3':
newFilters.addonType = ADDON_TYPE_DICT;
break;
case '5':
newFilters.addonType = ADDON_TYPE_LANG;
break;
default:
return;
}
shouldRedirect = true;
}
if (shouldRedirect) {
const queryString = makeQueryString(
convertFiltersToQueryParams(newFilters),
);
props.dispatch(
sendServerRedirect({
status: 301,
url: `/${lang}/${clientApp}${pathname}${queryString}`,
}),
);
}
}