Skip to content

Commit

Permalink
Improve dashboard search performance
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBurgess committed Nov 29, 2024
1 parent 77ed24e commit faddb65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 4 additions & 2 deletions ui/dashboard/src/components/DashboardList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ const DashboardList = () => {
return;
}
if (!searchValue) {
setFilteredDashboards(unfilteredDashboards);
setFilteredDashboards(() => unfilteredDashboards);
return;
}

Expand All @@ -393,7 +393,9 @@ const DashboardList = () => {
}
});

setFilteredDashboards(sortDashboardSearchResults(filtered, dashboardsMap));
setFilteredDashboards(() =>
sortDashboardSearchResults(filtered, dashboardsMap),
);
}, [
availableDashboardsLoaded,
dashboardsMap,
Expand Down
21 changes: 12 additions & 9 deletions ui/dashboard/src/components/DashboardSearch/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import SearchInput from "../SearchInput";
import useDebouncedEffect from "@powerpipe/hooks/useDebouncedEffect";
import { DashboardActions } from "@powerpipe/types";
import { useCallback } from "react";
import { useDashboard } from "@powerpipe/hooks/useDashboard";
import { useEffect, useState } from "react";

const DashboardSearch = () => {
const {
Expand All @@ -11,21 +12,23 @@ const DashboardSearch = () => {
search,
metadata,
} = useDashboard();
const [innerValue, setInnerValue] = useState(search.value);

const updateSearchValue = useCallback(
(value) =>
dispatch({ type: DashboardActions.SET_DASHBOARD_SEARCH_VALUE, value }),
[dispatch],
);
useEffect(() => {
setInnerValue(() => search.value);
}, [search.value]);

const updateSearchValue = (value) =>
dispatch({ type: DashboardActions.SET_DASHBOARD_SEARCH_VALUE, value });
useDebouncedEffect(() => updateSearchValue(innerValue), 250, [innerValue]);

return (
<div className="w-full sm:w-56 md:w-72 lg:w-96">
<SearchInput
//@ts-ignore
disabled={!metadata || !availableDashboardsLoaded}
placeholder={minBreakpoint("sm") ? "Search dashboards..." : "Search..."}
value={search.value}
setValue={updateSearchValue}
value={innerValue}
setValue={setInnerValue}
/>
</div>
);
Expand Down

0 comments on commit faddb65

Please sign in to comment.