-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGenericInfoCardListing.tsx
More file actions
73 lines (63 loc) · 2.13 KB
/
GenericInfoCardListing.tsx
File metadata and controls
73 lines (63 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (c) 2024. Devtron Inc.
*/
import { useMemo } from 'react'
import emptyList from '@Images/empty-create.png'
import ErrorScreenManager from '@Common/ErrorScreenManager'
import { GenericEmptyState, GenericFilterEmptyState } from '@Common/index'
import GenericInfoCard from './GenericInfoCard.component'
import { GenericInfoListSkeleton } from './GenericInfoListSkeleton'
import { GenericInfoCardListingProps } from './types'
export const GenericInfoCardListing = ({
isLoading,
error,
list,
searchKey,
reloadList,
borderVariant,
handleClearFilters,
emptyStateConfig,
}: GenericInfoCardListingProps) => {
const filteredList = useMemo(() => {
const sanitizedList = list || []
if (!searchKey || error) {
return sanitizedList
}
const loweredSearchKey = searchKey.toLowerCase()
return sanitizedList.filter(({ title }) => title.toLowerCase().includes(loweredSearchKey))
}, [searchKey, list, error])
if (isLoading) {
return <GenericInfoListSkeleton borderVariant={borderVariant} />
}
if (error) {
return <ErrorScreenManager code={error?.code as number} reload={reloadList} />
}
if (filteredList.length === 0) {
if (searchKey) {
return <GenericFilterEmptyState handleClearFilters={handleClearFilters} />
}
return (
<GenericEmptyState
image={emptyStateConfig.image ?? emptyList}
renderButton={emptyStateConfig.renderButton}
isButtonAvailable={!!emptyStateConfig.renderButton}
{...emptyStateConfig}
/>
)
}
return (
<>
{filteredList.map(({ id, title, description, author, Icon, onClick, linkProps }) => (
<GenericInfoCard
key={id}
title={title}
description={description}
author={author}
borderVariant={borderVariant}
Icon={Icon}
{...(onClick ? { onClick } : { linkProps })}
/>
))}
</>
)
}