Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add loading spinner to search bar #3719

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Box from "@mui/material/Box";
import CircularProgress from "@mui/material/CircularProgress";
import Container from "@mui/material/Container";
import Typography from "@mui/material/Typography";
import { useFormik } from "formik";
import { useSearch } from "hooks/useSearch";
import { debounce } from "lodash";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect, useMemo } from "react";
import React, { useEffect, useMemo, useState } from "react";
import ChecklistItem from "ui/shared/ChecklistItem";
import Input from "ui/shared/Input";

Expand All @@ -25,6 +26,8 @@ const Search: React.FC = () => {
state.orderedFlow,
state.setOrderedFlow,
]);
const [isSearching, setIsSearching] = useState(false);
const [lastSearchedTerm, setLastSearchedTerm] = useState("");

useEffect(() => {
if (!orderedFlow) setOrderedFlow();
Expand All @@ -46,11 +49,19 @@ const Search: React.FC = () => {
() =>
debounce((pattern: string) => {
console.debug("Search term: ", pattern);
return search(pattern);
search(pattern);
setLastSearchedTerm(pattern);
setIsSearching(false);
}, DEBOUNCE_MS),
[search],
);

useEffect(() => {
if (formik.values.pattern !== lastSearchedTerm) {
setIsSearching(true);
}
}, [formik.values.pattern, lastSearchedTerm]);

return (
<Container component={Box} p={3}>
<form onSubmit={formik.handleSubmit}>
Expand All @@ -63,16 +74,30 @@ const Search: React.FC = () => {
>
Search this flow and internal portals
</Typography>
<Input
id="pattern"
name="pattern"
value={formik.values.pattern}
onChange={(e) => {
formik.setFieldValue("pattern", e.target.value);
formik.handleSubmit();
}}
inputProps={{ spellCheck: false }}
/>
<Box
sx={{ display: "flex", position: "relative", alignItems: "center" }}
>
<Input
id="pattern"
name="pattern"
value={formik.values.pattern}
onChange={(e) => {
formik.setFieldValue("pattern", e.target.value);
formik.handleSubmit();
}}
inputProps={{ spellCheck: false }}
/>
{isSearching && (
<CircularProgress
size={25}
sx={(theme) => ({
position: "absolute",
right: theme.spacing(1.5),
zIndex: 1,
})}
/>
)}
</Box>
<ChecklistItem
label="Search only data fields"
id={"search-data-field-facet"}
Expand Down
Loading