Skip to content

Commit 6256dfb

Browse files
committed
feat: add support for clear filter button in GenericFilterEmptyState
1 parent f994583 commit 6256dfb

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.0.84-beta-9",
3+
"version": "0.0.84-beta-10",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1-
import { GenericEmptyStateType } from '../Types'
21
import noResult from '../../Assets/Img/empty-noresult@2x.png'
32
import GenericEmptyState from './GenericEmptyState'
3+
import { GenericFilterEmptyStateProps } from './types'
44

5-
const GenericFilterEmptyState = (
6-
props: Omit<GenericEmptyStateType, 'image' | 'title' | 'subTitle'> &
7-
Partial<Pick<GenericEmptyStateType, 'title' | 'subTitle'>>,
8-
) => (
9-
<GenericEmptyState
10-
image={noResult}
11-
title="No results"
12-
subTitle="We couldn’t find any matching results"
13-
{...props}
14-
/>
15-
)
5+
/**
6+
* Empty state when no filters are applied
7+
*/
8+
const GenericFilterEmptyState = ({
9+
handleClearFilters,
10+
isButtonAvailable,
11+
renderButton,
12+
...props
13+
}: GenericFilterEmptyStateProps) => {
14+
const isClearFilterButtonAvailable = !!handleClearFilters
15+
16+
const renderClearFilterButton = () => (
17+
<button type="button" onClick={handleClearFilters} className="cta secondary flex h-32 lh-20-imp">
18+
Clear Filters
19+
</button>
20+
)
21+
22+
return (
23+
<GenericEmptyState
24+
image={noResult}
25+
title="No results"
26+
subTitle="We couldn’t find any matching results"
27+
{...props}
28+
isButtonAvailable={isClearFilterButtonAvailable || isButtonAvailable}
29+
renderButton={isClearFilterButtonAvailable ? renderClearFilterButton : renderButton}
30+
/>
31+
)
32+
}
1633

1734
export default GenericFilterEmptyState

src/Common/EmptyState/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { GenericEmptyStateType } from '../Types'
2+
3+
export type GenericFilterEmptyStateProps = Omit<
4+
GenericEmptyStateType,
5+
'image' | 'title' | 'subTitle' | 'isButtonAvailable' | 'renderButton'
6+
> &
7+
Partial<Pick<GenericEmptyStateType, 'title' | 'subTitle'>> &
8+
(
9+
| {
10+
/**
11+
* If provided, it will have priority over the isButtonAvailable prop
12+
* and render clear filter button
13+
*/
14+
handleClearFilters?: () => void
15+
isButtonAvailable?: never
16+
renderButton?: never
17+
}
18+
| (Pick<GenericEmptyStateType, 'isButtonAvailable' | 'renderButton'> & {
19+
handleClearFilters?: never
20+
})
21+
)

0 commit comments

Comments
 (0)