@progress/sitefinity-nextjs-sdk
Version:
Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.
40 lines (39 loc) • 2.19 kB
JavaScript
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { SearchResultsSorting } from './interfaces/search-results-sorting';
import { getWhiteListSearchParams } from '../document-list/common/utils';
export function OrderByDropDown(props) {
const { sortingSelectId, searchParams, sorting, queryParams } = props;
const whitelistedQueryParams = ['sf_site', 'sfaction', 'sf_provider'];
const queryList = new URLSearchParams(getWhiteListSearchParams(queryParams || {}, whitelistedQueryParams));
const query = searchParams['searchQuery'];
const index = searchParams['indexCatalogue'];
const wordsMode = searchParams['wordsMode'];
const language = searchParams['sf_culture'];
const scoringInfo = searchParams['scoringInfo'];
const resultsForAllSites = searchParams['resultsForAllSites'];
const orderBy = sorting;
const filter = searchParams['filter'];
const handleSelectionChange = (event) => {
const orderValue = event.target.value || orderBy;
let newQuery = queryList + '&searchQuery=' + encodeURIComponent(query)?.toLowerCase() +
'&indexCatalogue=' + index +
'&wordsMode=' + wordsMode +
'&sf_culture=' + language +
'&orderBy=' + orderValue;
if (scoringInfo) {
newQuery = newQuery + '&scoringInfo=' + scoringInfo;
}
if (filter) {
newQuery = newQuery + '&filter=' + filter;
}
if (resultsForAllSites === 'True') {
newQuery += '&resultsForAllSites=True';
}
else if (resultsForAllSites === 'False') {
newQuery += '&resultsForAllSites=False';
}
window.location.search = newQuery;
};
return (_jsxs("select", { onChange: handleSelectionChange, className: "userSortDropdown form-select", value: orderBy, title: "SortDropdown", id: sortingSelectId, children: [_jsx("option", { value: SearchResultsSorting.MostRelevantOnTop, children: "Relevance" }), _jsx("option", { value: SearchResultsSorting.NewestFirst, children: "Newest first" }), _jsx("option", { value: SearchResultsSorting.OldestFirst, children: "Oldest first" })] }));
}