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

Add search bar for pools page #46437

Merged
merged 1 commit into from
Feb 4, 2025
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
39 changes: 34 additions & 5 deletions airflow/ui/src/pages/Pools/Pools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,50 @@
* under the License.
*/
import { Box, Skeleton } from "@chakra-ui/react";
import { useState } from "react";
import { useSearchParams } from "react-router-dom";

import { usePoolServiceGetPools } from "openapi/queries";
import { ErrorAlert } from "src/components/ErrorAlert";
import { SearchBar } from "src/components/SearchBar";
import { type SearchParamsKeysType, SearchParamsKeys } from "src/constants/searchParams";

import PoolBar from "./PoolBar";

export const Pools = () => {
const { data, error, isLoading } = usePoolServiceGetPools();
const [searchParams, setSearchParams] = useSearchParams();
const { NAME_PATTERN: NAME_PATTERN_PARAM }: SearchParamsKeysType = SearchParamsKeys;
const [poolNamePattern, setPoolNamePattern] = useState(searchParams.get(NAME_PATTERN_PARAM) ?? undefined);
const { data, error, isLoading } = usePoolServiceGetPools({
poolNamePattern: poolNamePattern ?? undefined,
});

return isLoading ? (
<Skeleton height="30" />
) : (
const handleSearchChange = (value: string) => {
if (value) {
searchParams.set(NAME_PATTERN_PARAM, value);
} else {
searchParams.delete(NAME_PATTERN_PARAM);
}
setSearchParams(searchParams);
setPoolNamePattern(value);
};

return (
<>
<ErrorAlert error={error} />
<Box p={2}>{data?.pools.map((pool) => <PoolBar key={pool.name} pool={pool} />)}</Box>
<SearchBar
buttonProps={{ disabled: true }}
defaultValue={poolNamePattern ?? ""}
onChange={handleSearchChange}
placeHolder="Search Pools"
/>
<Box mt={4}>
{isLoading ? (
<Skeleton height="100px" />
) : (
data?.pools.map((pool) => <PoolBar key={pool.name} pool={pool} />)
)}
</Box>
</>
);
};