Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/Assets/Img/empty-create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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(() => {
if (!searchKey || error) {
Comment thread
AbhishekA1509 marked this conversation as resolved.
return list
}

const loweredSearchKey = searchKey.toLowerCase()
return list.filter(({ title }) => title.toLowerCase().includes(loweredSearchKey))
Comment thread
shivani170 marked this conversation as resolved.
Outdated
}, [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} {...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 })}
/>
))}
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import GenericInfoCard from './GenericInfoCard.component'

export const GenericInfoListSkeleton = (borderVariant) => (
Comment thread
AbhishekA1509 marked this conversation as resolved.
Outdated
<>
<GenericInfoCard isLoading borderVariant={borderVariant} />
<GenericInfoCard isLoading borderVariant={borderVariant} />
<GenericInfoCard isLoading borderVariant={borderVariant} />
</>
)
4 changes: 3 additions & 1 deletion src/Shared/Components/GenericInfoCard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
*/

export { default as GenericInfoCard } from './GenericInfoCard.component'
export { GenericInfoCardBorderVariant, type GenericInfoCardProps } from './types'
export * from './GenericInfoCardListing'
export { GenericInfoListSkeleton } from './GenericInfoListSkeleton'
export { GenericInfoCardBorderVariant, type GenericInfoCardListingProps, type GenericInfoCardProps } from './types'
17 changes: 17 additions & 0 deletions src/Shared/Components/GenericInfoCard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import { MouseEventHandler, ReactElement } from 'react'
import { LinkProps } from 'react-router-dom'

import { GenericFilterEmptyStateProps } from '@Common/EmptyState/types'
import { GenericEmptyStateType } from '@Common/Types'

import { APIResponseHandlerProps } from '../APIResponseHandler'

type BaseGenericInfoCardProps = {
title: string
description: string
Expand Down Expand Up @@ -46,3 +51,15 @@ export type GenericInfoCardProps = { borderVariant: GenericInfoCardBorderVariant
isLoading?: boolean
} & BaseGenericInfoCardProps)
)

export interface GenericInfoCardListingProps
extends Pick<GenericInfoCardProps, 'borderVariant'>,
Pick<GenericFilterEmptyStateProps, 'handleClearFilters'> {
list: (Pick<GenericInfoCardProps, 'Icon' | 'author' | 'description' | 'linkProps' | 'onClick' | 'title'> &
Record<'id', string>)[]
emptyStateConfig: Pick<GenericEmptyStateType, 'title' | 'subTitle' | 'image'>
searchKey?: string
reloadList?: () => void
Comment thread
shivani170 marked this conversation as resolved.
Outdated
error?: APIResponseHandlerProps['error']
isLoading?: boolean
}