diff --git a/ui/src/components/GlobalSearchShortcut.tsx b/ui/src/components/GlobalSearchShortcut.tsx new file mode 100644 index 00000000000..2c116c6dd63 --- /dev/null +++ b/ui/src/components/GlobalSearchShortcut.tsx @@ -0,0 +1,27 @@ +import React, { useEffect } from "react"; + +interface GlobalSearchShortcutProps { + onOpen: () => void; +} + +const GlobalSearchShortcut: React.FC = ({ + onOpen, +}) => { + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if ((event.metaKey || event.ctrlKey) && event.key === "k") { + event.preventDefault(); + onOpen(); + } + }; + + document.addEventListener("keydown", handleKeyDown); + return () => { + document.removeEventListener("keydown", handleKeyDown); + }; + }, [onOpen]); + + return null; // This component doesn't render anything +}; + +export default GlobalSearchShortcut; diff --git a/ui/src/components/RegistrySearch.tsx b/ui/src/components/RegistrySearch.tsx index b859249963b..24d6886d4d5 100644 --- a/ui/src/components/RegistrySearch.tsx +++ b/ui/src/components/RegistrySearch.tsx @@ -1,5 +1,15 @@ -import React, { useState } from "react"; -import { EuiText, EuiFieldSearch, EuiSpacer } from "@elastic/eui"; +import React, { + useState, + useRef, + forwardRef, + useImperativeHandle, +} from "react"; +import { + EuiText, + EuiFieldSearch, + EuiSpacer, + EuiHorizontalRule, +} from "@elastic/eui"; import EuiCustomLink from "./EuiCustomLink"; interface RegistrySearchProps { @@ -10,81 +20,124 @@ interface RegistrySearchProps { }[]; } -const RegistrySearch: React.FC = ({ categories }) => { - const [searchText, setSearchText] = useState(""); +export interface RegistrySearchRef { + focusSearchInput: () => void; +} + +const RegistrySearch = forwardRef( + ({ categories }, ref) => { + const [searchText, setSearchText] = useState(""); + const inputRef = useRef(null); + + const focusSearchInput = () => { + if (inputRef.current) { + inputRef.current.focus(); + } + }; - const searchResults = categories.map(({ name, data, getLink }) => { - const filteredItems = searchText - ? data.filter((item) => { - const itemName = - "name" in item - ? String(item.name) - : "spec" in item && item.spec && "name" in item.spec - ? String(item.spec.name ?? "Unknown") - : "Unknown"; + useImperativeHandle( + ref, + () => ({ + focusSearchInput, + }), + [focusSearchInput], + ); - return itemName.toLowerCase().includes(searchText.toLowerCase()); - }) - : []; + const searchResults = categories.map(({ name, data, getLink }) => { + const filteredItems = searchText + ? data.filter((item) => { + const itemName = + "name" in item + ? String(item.name) + : "spec" in item && item.spec && "name" in item.spec + ? String(item.spec.name ?? "Unknown") + : "Unknown"; - return { name, items: filteredItems, getLink }; - }); + return itemName.toLowerCase().includes(searchText.toLowerCase()); + }) + : []; - return ( - <> - - -

Search in registry

-
- - setSearchText(e.target.value)} - isClearable - fullWidth - /> - + return { name, items: filteredItems, getLink }; + }); - {searchText && ( - -

Search Results

- {searchResults.some(({ items }) => items.length > 0) ? ( - searchResults.map(({ name, items, getLink }, index) => - items.length > 0 ? ( -
-

{name}

-
    - {items.map((item, idx) => { - const itemName = - "name" in item - ? item.name - : "spec" in item - ? item.spec?.name - : "Unknown"; + return ( + <> + setSearchText(e.target.value)} + isClearable + fullWidth + inputRef={(node) => { + inputRef.current = node; + }} + aria-label="Search registry" + compressed + append={ + + ⌘K + + } + /> + + {searchText && ( + <> + +

    Search Results

    +
    + + {searchResults.some(({ items }) => items.length > 0) ? ( +
    + {searchResults.map(({ name, items, getLink }, index) => + items.length > 0 ? ( +
    + +
    {name}
    +
    + +
      + {items.map((item, idx) => { + const itemName = + "name" in item + ? item.name + : "spec" in item + ? item.spec?.name + : "Unknown"; - const itemLink = getLink(item); + const itemLink = getLink(item); - return ( -
    • - - {itemName} - -
    • - ); - })} -
    - + return ( +
  • + + {itemName} + +
  • + ); + })} +
+ {index < + searchResults.filter( + (result) => result.items.length > 0, + ).length - + 1 && } +
+ ) : null, + )} + + ) : ( +
+
+

No matches found.

- ) : null, - ) - ) : ( -

No matches found.

- )} - - )} - - ); -}; +
+ )} + + )} + + ); + }, +); export default RegistrySearch; diff --git a/ui/src/pages/Layout.tsx b/ui/src/pages/Layout.tsx index 24251be4483..633d9303a4d 100644 --- a/ui/src/pages/Layout.tsx +++ b/ui/src/pages/Layout.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState, useRef } from "react"; import { EuiPage, @@ -7,34 +7,95 @@ import { EuiErrorBoundary, EuiHorizontalRule, EuiSpacer, + EuiPageHeader, + EuiFlexGroup, + EuiFlexItem, } from "@elastic/eui"; import { Outlet } from "react-router-dom"; import RegistryPathContext from "../contexts/RegistryPathContext"; import { useParams } from "react-router-dom"; import { useLoadProjectsList } from "../contexts/ProjectListContext"; +import useLoadRegistry from "../queries/useLoadRegistry"; import ProjectSelector from "../components/ProjectSelector"; import Sidebar from "./Sidebar"; import FeastWordMark from "../graphics/FeastWordMark"; import ThemeToggle from "../components/ThemeToggle"; +import RegistrySearch, { + RegistrySearchRef, +} from "../components/RegistrySearch"; +import GlobalSearchShortcut from "../components/GlobalSearchShortcut"; const Layout = () => { // Registry Path Context has to be inside Layout // because it has to be under routes // in order to use useParams let { projectName } = useParams(); + const [isSearchOpen, setIsSearchOpen] = useState(false); + const searchRef = useRef(null); - const { data } = useLoadProjectsList(); + const { data: projectsData } = useLoadProjectsList(); - const currentProject = data?.projects.find((project) => { + const currentProject = projectsData?.projects.find((project) => { return project.id === projectName; }); const registryPath = currentProject?.registryPath || ""; + const { data } = useLoadRegistry(registryPath); + + const categories = data + ? [ + { + name: "Data Sources", + data: data.objects.dataSources || [], + getLink: (item: any) => `/p/${projectName}/data-source/${item.name}`, + }, + { + name: "Entities", + data: data.objects.entities || [], + getLink: (item: any) => `/p/${projectName}/entity/${item.name}`, + }, + { + name: "Features", + data: data.allFeatures || [], + getLink: (item: any) => { + const featureView = item?.featureView; + return featureView + ? `/p/${projectName}/feature-view/${featureView}/feature/${item.name}` + : "#"; + }, + }, + { + name: "Feature Views", + data: data.mergedFVList || [], + getLink: (item: any) => `/p/${projectName}/feature-view/${item.name}`, + }, + { + name: "Feature Services", + data: data.objects.featureServices || [], + getLink: (item: any) => { + const serviceName = item?.name || item?.spec?.name; + return serviceName + ? `/p/${projectName}/feature-service/${serviceName}` + : "#"; + }, + }, + ] + : []; + + const handleSearchOpen = () => { + setIsSearchOpen(true); + setTimeout(() => { + if (searchRef.current) { + searchRef.current.focusSearchInput(); + } + }, 100); + }; return ( + { - +
+ +
)}
+ {isSearchOpen && data && ( + + + + + + + + )} diff --git a/ui/src/pages/ProjectOverviewPage.tsx b/ui/src/pages/ProjectOverviewPage.tsx index 17269b776d2..746bbb4e059 100644 --- a/ui/src/pages/ProjectOverviewPage.tsx +++ b/ui/src/pages/ProjectOverviewPage.tsx @@ -171,9 +171,6 @@ const ProjectOverviewPage = () => { {selectedTabId === "visualization" && } - - {isSuccess && } - ); };