* feat: add improved search * wip: add support for sorting, rename use-options to use-query-options, add use-options for local usage, add pages search group * feat: add help links from manage layout to help search mode * feat: add additional search engines * feat: add group search details * refactor: improve users search group type * feat: add apps search group, add disabled search interaction * feat: add integrations and boards for search * wip: hook issue with react * fix: hook issue regarding actions and interactions * chore: address pull request feedback * fix: format issues * feat: add additional global actions to search * chore: remove unused code * fix: search engine short key * fix: typecheck issues * fix: deepsource issues * fix: eslint issue * fix: lint issues * fix: unordered dependencies * chore: address pull request feedback
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import Link from "next/link";
|
|
import { Spotlight } from "@mantine/spotlight";
|
|
|
|
import type { TranslationObject } from "@homarr/translation";
|
|
|
|
import type { SearchGroup } from "../../../lib/group";
|
|
import type { inferSearchInteractionOptions } from "../../../lib/interaction";
|
|
import classes from "./action-item.module.css";
|
|
|
|
interface SpotlightGroupActionItemProps<TOption extends Record<string, unknown>> {
|
|
option: TOption;
|
|
query: string;
|
|
setMode: (mode: keyof TranslationObject["search"]["mode"]) => void;
|
|
setChildrenOptions: (options: inferSearchInteractionOptions<"children">) => void;
|
|
group: SearchGroup<TOption>;
|
|
}
|
|
|
|
export const SpotlightGroupActionItem = <TOption extends Record<string, unknown>>({
|
|
group,
|
|
query,
|
|
setMode,
|
|
setChildrenOptions,
|
|
option,
|
|
}: SpotlightGroupActionItemProps<TOption>) => {
|
|
const interaction = group.useInteraction(option, query);
|
|
|
|
const renderRoot =
|
|
interaction.type === "link"
|
|
? (props: Record<string, unknown>) => {
|
|
return <Link href={interaction.href} target={interaction.newTab ? "_blank" : undefined} {...props} />;
|
|
}
|
|
: undefined;
|
|
|
|
const handleClickAsync = async () => {
|
|
if (interaction.type === "javaScript") {
|
|
await interaction.onSelect();
|
|
} else if (interaction.type === "mode") {
|
|
setMode(interaction.mode);
|
|
} else if (interaction.type === "children") {
|
|
setChildrenOptions(interaction);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Spotlight.Action
|
|
renderRoot={renderRoot}
|
|
onClick={handleClickAsync}
|
|
closeSpotlightOnTrigger={interaction.type !== "mode" && interaction.type !== "children"}
|
|
className={classes.spotlightAction}
|
|
>
|
|
<group.component {...option} />
|
|
</Spotlight.Action>
|
|
);
|
|
};
|