diff --git a/packages/frontend/src/components/SearchBar.tsx b/packages/frontend/src/components/SearchBar.tsx index 473da86a..95e6ec97 100644 --- a/packages/frontend/src/components/SearchBar.tsx +++ b/packages/frontend/src/components/SearchBar.tsx @@ -1,16 +1,10 @@ -import React, { ChangeEventHandler, forwardRef } from 'react'; +import React, { forwardRef } from 'react'; -import { Input } from '@material-tailwind/react'; - -interface SearchBarProps { - onChange?: ChangeEventHandler; - value?: string; - placeholder?: string; -} +import { Input, InputProps } from '@material-tailwind/react'; const SearchBar: React.ForwardRefRenderFunction< HTMLInputElement, - SearchBarProps + InputProps > = ({ value, onChange, placeholder = 'Search', ...props }, ref) => { return (
@@ -28,8 +22,8 @@ const SearchBar: React.ForwardRefRenderFunction< }} // TODO: Debug issue: https://github.com/creativetimofficial/material-tailwind/issues/427 crossOrigin={undefined} - ref={ref} {...props} + ref={ref} />
^ diff --git a/packages/frontend/src/components/projects/project/DeploymentsTabPanel.tsx b/packages/frontend/src/components/projects/project/DeploymentsTabPanel.tsx index 906e70dd..214a92cb 100644 --- a/packages/frontend/src/components/projects/project/DeploymentsTabPanel.tsx +++ b/packages/frontend/src/components/projects/project/DeploymentsTabPanel.tsx @@ -1,60 +1,47 @@ import React, { useCallback, useMemo, useState } from 'react'; -import { Button } from '@material-tailwind/react'; +import { Button, Typography } from '@material-tailwind/react'; import deploymentData from '../../../assets/deployments.json'; -import DeployDetailsCard from './DeploymentDetailsCard'; -import Dropdown from '../../Dropdown'; -import SearchBar from '../../SearchBar'; +import DeployDetailsCard from './deployments/DeploymentDetailsCard'; +import FilterForm, { StatusOptions } from './deployments/FilterForm'; -const STATUS_OPTIONS = [ - { value: 'building', label: 'Building' }, - { value: 'ready', label: 'Ready' }, - { value: 'error', label: 'Error' }, -]; +const DEFAULT_FILTER_VALUE = { + searchedBranch: '', + status: 'All status', +}; const DeploymentsTabPanel = () => { - const [searchedBranch, setSearchedBranch] = useState(''); + const [filterValue, setFilterValue] = useState(DEFAULT_FILTER_VALUE); const filteredDeployments = useMemo(() => { - if (searchedBranch) { - return deploymentData.filter((deployment) => - deployment.branch.toLowerCase().includes(searchedBranch.toLowerCase()), - ); - } + return deploymentData.filter((deployment) => { + // Searched branch filter + const branchMatch = + !filterValue.searchedBranch || + deployment.branch + .toLowerCase() + .includes(filterValue.searchedBranch.toLowerCase()); - return deploymentData; - }, [searchedBranch]); + // Status filter + const statusMatch = + filterValue.status === StatusOptions.ALL_STATUS || + deployment.status === filterValue.status; + + return branchMatch && statusMatch; + }); + }, [filterValue]); const handleResetFilters = useCallback(() => { - setSearchedBranch(''); + setFilterValue(DEFAULT_FILTER_VALUE); }, []); return (
-
-
- setSearchedBranch(event.target.value)} - /> -
-
- -
-
- {}} - /> -
-
+ setFilterValue(value)} + />
{Boolean(filteredDeployments.length) ? ( filteredDeployments.map((deployment, key) => { @@ -63,8 +50,10 @@ const DeploymentsTabPanel = () => { ) : (
-
No deployments found
-

Please change your search query or filters

+ No deployments found + + Please change your search query or filters +