forked from opendatahub-io/odh-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathOdhExploreCard.tsx
More file actions
110 lines (105 loc) · 3.72 KB
/
OdhExploreCard.tsx
File metadata and controls
110 lines (105 loc) · 3.72 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React from 'react';
import classNames from 'classnames';
import { Card, CardBody, CardHeader, Flex, FlexItem, Label } from '@patternfly/react-core';
import { OdhApplication } from '#~/types';
import { makeCardVisible } from '#~/utilities/utils';
import EnableModal from '#~/pages/exploreApplication/EnableModal';
import { ODH_PRODUCT_NAME } from '#~/utilities/const';
import { useAppContext } from '#~/app/AppContext';
import BrandImage from './BrandImage';
import SupportedAppTitle from './SupportedAppTitle';
import OdhExploreCardTypeBadge from './OdhExploreCardTypeBadge';
import './OdhCard.scss';
type OdhExploreCardProps = {
odhApp: OdhApplication;
isSelected: boolean;
onSelect: () => void;
disableInfo?: boolean;
enableOpen: boolean;
onEnableClose: () => void;
};
const OdhExploreCard: React.FC<OdhExploreCardProps> = ({
odhApp,
isSelected,
onSelect,
disableInfo = false,
enableOpen,
onEnableClose,
}) => {
const { dashboardConfig } = useAppContext();
React.useEffect(() => {
if (isSelected) {
makeCardVisible(odhApp.metadata.name);
}
}, [odhApp.metadata.name, isSelected]);
const disabled = odhApp.spec.comingSoon || disableInfo;
const cardClasses = classNames('odh-card', { 'pf-m-disabled': disabled });
const badgeClasses = classNames('odh-card__partner-badge', {
'm-hidden': odhApp.spec.support === ODH_PRODUCT_NAME,
'odh-m-selectable': !disabled,
});
return (
<Card
component="div"
data-testid={`card ${odhApp.metadata.name}`}
id={odhApp.metadata.name}
role="listitem"
isSelectable={!disabled}
isSelected={isSelected}
className={cardClasses}
>
<CardHeader
className="pf-m-no-offset"
{...(!dashboardConfig.spec.dashboardConfig.disableISVBadges && {
actions: {
hasNoOffset: true,
actions: null,
},
selectableActions: {
selectableActionId: `${odhApp.metadata.name}-selectable-card-id`,
selectableActionAriaLabelledby: odhApp.metadata.name,
name: `odh-explore-selectable-card`,
variant: 'single',
isChecked: isSelected,
onChange: () => !disabled && onSelect(),
isHidden: true,
},
})}
>
<Flex
alignItems={{ default: 'alignItemsCenter' }}
gap={{ default: 'gapMd' }}
direction={{ default: 'row' }}
flexWrap={{ default: 'nowrap' }}
>
<BrandImage src={odhApp.spec.img} alt="" data-testid="brand-image" />
<Flex
spaceItems={{ default: 'spaceItemsSm' }}
alignItems={{ default: 'alignItemsCenter' }}
direction={{ default: 'column' }}
>
{odhApp.spec.comingSoon && (
<FlexItem className="odh-card__coming-soon">Coming soon</FlexItem>
)}
{!odhApp.spec.comingSoon && odhApp.spec.category && (
<FlexItem className={badgeClasses} onClick={disabled ? undefined : onSelect}>
<OdhExploreCardTypeBadge isDisabled={disabled} category={odhApp.spec.category} />
</FlexItem>
)}
{odhApp.spec.beta && (
<FlexItem className="odh-card__partner-badge odh-m-beta">
<Label className={disabled ? 'pf-m-disabled' : undefined} color="yellow">
Beta
</Label>
</FlexItem>
)}
</Flex>
</Flex>
</CardHeader>
<SupportedAppTitle odhApp={odhApp} showProvider />
<CardBody data-testid="cardbody">{odhApp.spec.description}</CardBody>
{enableOpen && <EnableModal onClose={onEnableClose} selectedApp={odhApp} />}
</Card>
);
};
export default OdhExploreCard;