From 318ebdfd26331ca12ccf8ca77fe751a6826c8d90 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Wed, 20 Dec 2023 16:43:27 +0530 Subject: [PATCH] Filter deployments with status options (#15) --- .../frontend/src/components/SearchBar.tsx | 14 +--- .../projects/project/DeploymentsTabPanel.tsx | 75 ++++++++---------- .../DeploymentDetailsCard.tsx | 2 +- .../project/deployments/FilterForm.tsx | 77 +++++++++++++++++++ 4 files changed, 114 insertions(+), 54 deletions(-) rename packages/frontend/src/components/projects/project/{ => deployments}/DeploymentDetailsCard.tsx (96%) create mode 100644 packages/frontend/src/components/projects/project/deployments/FilterForm.tsx diff --git a/packages/frontend/src/components/SearchBar.tsx b/packages/frontend/src/components/SearchBar.tsx index 473da86..95e6ec9 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 906e70d..214a92c 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 +