-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add search + status executions filters (#986)
* feat: add search + status executions filters * refactor: filters container styling * fix: linting * fix: linting 2
- Loading branch information
1 parent
2296ad9
commit ae29abe
Showing
10 changed files
with
299 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...b/src/components/organisms/ExecutionsTable/ExecutionsFilters/ExecutionsFilters.styled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Input} from 'antd'; | ||
|
||
import styled from 'styled-components'; | ||
|
||
export const FiltersContainer = styled.div` | ||
display: grid; | ||
grid-template-columns: repeat(2, minmax(120px, 248px)); | ||
grid-column-gap: 16px; | ||
align-items: center; | ||
width: 100%; | ||
margin: 8px 0 24px; | ||
`; | ||
|
||
export const SearchInput = styled(Input)` | ||
height: 46px; | ||
width: auto; | ||
`; |
52 changes: 52 additions & 0 deletions
52
...ages/web/src/components/organisms/ExecutionsTable/ExecutionsFilters/ExecutionsFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {useEffect, useState} from 'react'; | ||
import {useDebounce} from 'react-use'; | ||
|
||
import {SearchOutlined} from '@ant-design/icons'; | ||
|
||
import {useEntityDetailsField, useEntityDetailsPick} from '@store/entityDetails'; | ||
|
||
import Colors from '@styles/Colors'; | ||
|
||
import * as S from './ExecutionsFilters.styled'; | ||
import ExecutionsStatusFilter from './ExecutionsStatusFilter'; | ||
|
||
const ExecutionsFilters: React.FC = () => { | ||
const [executionsFilters, setExecutionsFilters] = useEntityDetailsField('executionsFilters'); | ||
const {executionsLoading} = useEntityDetailsPick('executionsLoading'); | ||
|
||
const [searchInputValue, setSearchInputValue] = useState(executionsFilters.textSearch); | ||
|
||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchInputValue(e.target.value); | ||
}; | ||
|
||
const [, cancel] = useDebounce( | ||
() => { | ||
setExecutionsFilters({...executionsFilters, textSearch: searchInputValue}); | ||
}, | ||
300, | ||
[searchInputValue] | ||
); | ||
|
||
useEffect(() => { | ||
return () => { | ||
cancel(); | ||
}; | ||
}, [cancel]); | ||
|
||
return ( | ||
<S.FiltersContainer> | ||
<S.SearchInput | ||
prefix={<SearchOutlined style={{color: Colors.slate500}} />} | ||
placeholder="Search execution" | ||
data-cy="executions-search-filter" | ||
value={searchInputValue} | ||
onChange={onChange} | ||
disabled={executionsLoading} | ||
/> | ||
<ExecutionsStatusFilter /> | ||
</S.FiltersContainer> | ||
); | ||
}; | ||
|
||
export default ExecutionsFilters; |
95 changes: 95 additions & 0 deletions
95
...web/src/components/organisms/ExecutionsTable/ExecutionsFilters/ExecutionsStatusFilter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import {useCallback, useMemo, useState} from 'react'; | ||
|
||
import {FilterFilled} from '@ant-design/icons'; | ||
|
||
import {capitalize} from 'lodash'; | ||
|
||
import {ExecutionStatusEnum, executionStatusList} from '@models/execution'; | ||
|
||
import { | ||
FilterMenuFooter, | ||
StyledFilterCheckbox, | ||
StyledFilterDropdown, | ||
StyledFilterLabel, | ||
StyledFilterMenu, | ||
StyledFilterMenuItem, | ||
} from '@molecules/FilterMenu'; | ||
|
||
import {useEntityDetailsField, useEntityDetailsPick} from '@store/entityDetails'; | ||
|
||
import Colors from '@styles/Colors'; | ||
|
||
const ExecutionsStatusFilter: React.FC = () => { | ||
const [executionsFilters, setExecutionsFilters] = useEntityDetailsField('executionsFilters'); | ||
const {executionsLoading} = useEntityDetailsPick('executionsLoading'); | ||
|
||
const [isVisible, setVisibilityState] = useState(false); | ||
|
||
const handleClick = useCallback( | ||
(status: ExecutionStatusEnum) => { | ||
if (executionsFilters.status.includes(status)) { | ||
setExecutionsFilters({ | ||
...executionsFilters, | ||
status: executionsFilters.status.filter((currentStatus: string) => { | ||
return status !== currentStatus; | ||
}), | ||
}); | ||
} else { | ||
setExecutionsFilters({ | ||
...executionsFilters, | ||
status: [...executionsFilters.status, status], | ||
}); | ||
} | ||
}, | ||
[executionsFilters, setExecutionsFilters] | ||
); | ||
|
||
const renderedStatuses = useMemo(() => { | ||
return executionStatusList.map(status => { | ||
return ( | ||
<StyledFilterMenuItem key={status}> | ||
<StyledFilterCheckbox | ||
checked={executionsFilters.status.includes(status)} | ||
onChange={() => handleClick(status)} | ||
data-testid={status} | ||
> | ||
{capitalize(status)} | ||
</StyledFilterCheckbox> | ||
</StyledFilterMenuItem> | ||
); | ||
}); | ||
}, [executionsFilters.status, handleClick]); | ||
|
||
const resetFilter = () => { | ||
setExecutionsFilters({...executionsFilters, status: []}); | ||
setVisibilityState(false); | ||
}; | ||
|
||
const menu = ( | ||
<StyledFilterMenu data-cy="status-filter-dropdown"> | ||
{renderedStatuses} | ||
<FilterMenuFooter onReset={resetFilter} onOk={() => setVisibilityState(false)} /> | ||
</StyledFilterMenu> | ||
); | ||
|
||
return ( | ||
<StyledFilterDropdown | ||
overlay={menu} | ||
trigger={['click']} | ||
placement="bottom" | ||
onOpenChange={(value: boolean) => setVisibilityState(value)} | ||
open={isVisible} | ||
disabled={executionsLoading} | ||
> | ||
<StyledFilterLabel | ||
onClick={e => e.preventDefault()} | ||
data-cy="executions-status-filter-button" | ||
$disabled={executionsLoading} | ||
> | ||
Status <FilterFilled style={{color: executionsFilters.status.length ? Colors.purple : Colors.slate500}} /> | ||
</StyledFilterLabel> | ||
</StyledFilterDropdown> | ||
); | ||
}; | ||
|
||
export default ExecutionsStatusFilter; |
1 change: 1 addition & 0 deletions
1
packages/web/src/components/organisms/ExecutionsTable/ExecutionsFilters/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from './ExecutionsFilters'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.