META-INF.resources.js.SearchOptions.tsx Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import ClayButton from '@clayui/button';
import {Option, Picker} from '@clayui/core';
import DropDown from '@clayui/drop-down';
import ClayForm from '@clayui/form';
import ClayIcon from '@clayui/icon';
import ClayLayout from '@clayui/layout';
import {addParams, navigate} from 'frontend-js-web';
import React, {Key} from 'react';
const Trigger = React.forwardRef(
(
{
'aria-label': ariaLabel,
children,
'className': _className,
onClick,
triggerIcon,
...otherProps
},
ref
) => (
{triggerIcon && }
{children}
)
);
type Option = {
label: string;
value: string;
};
type Props = {
portletNamespace: string;
searchIn: Key;
searchInCommentsURL: string;
searchInOptions: Option[];
searchLocation: Key;
searchLocationOptions: Option[];
searchResults: Key;
searchURL: string;
};
const SearchOptions = ({
portletNamespace: namespace,
searchIn: initialSearchIn,
searchInCommentsURL,
searchInOptions,
searchLocation: initialLocation,
searchLocationOptions,
searchResults: initialResults,
searchURL,
}: Props) => {
const onChange = ({
location,
results,
searchIn,
}: {
location?: Key;
results?: Key;
searchIn?: Key;
}) => {
const baseURL =
searchIn === 'comments' ? searchInCommentsURL : searchURL;
const parsedBaseURL = new URL(baseURL);
const searchParams = parsedBaseURL.searchParams;
searchParams.delete(`${namespace}tab`);
const url = addParams(
{
[`${namespace}searchIn`]: searchIn || initialSearchIn,
[`${namespace}searchLocation`]: location || initialLocation,
[`${namespace}tab`]: results || initialResults,
},
parsedBaseURL.toString()
);
navigate(url);
};
return (
{searchLocationOptions ? (
onChange({location: key})
}
selectedKey={initialLocation}
triggerIcon="folder"
>
{(item) => (
)}
) : null}
{searchInOptions ? (
onChange({searchIn: key})
}
selectedKey={initialSearchIn}
>
{(item) => (
)}
) : null}
);
};
export default SearchOptions;
© 2015 - 2024 Weber Informatics LLC | Privacy Policy