|
| 1 | +import BAINotificationBackgroundItem from './BAINotificationBackgroundItem'; |
| 2 | +import { useToggle } from 'ahooks'; |
| 3 | +import { Card, List, theme, Typography } from 'antd'; |
| 4 | +import { BAIFlex, BAILink, BAINotificationItem, BAIText } from 'backend.ai-ui'; |
| 5 | +import dayjs from 'dayjs'; |
| 6 | +import _ from 'lodash'; |
| 7 | +import { useTranslation } from 'react-i18next'; |
| 8 | +import { graphql, useFragment } from 'react-relay'; |
| 9 | +import { useNavigate } from 'react-router-dom'; |
| 10 | +import { |
| 11 | + NotificationState, |
| 12 | + useSetBAINotification, |
| 13 | +} from 'src/hooks/useBAINotification'; |
| 14 | + |
| 15 | +interface BAIVirtualFolderNodeNotificationItemProps { |
| 16 | + notification: NotificationState; |
| 17 | + virtualFolderNodeFrgmt: any; |
| 18 | + showDate?: boolean; |
| 19 | +} |
| 20 | + |
| 21 | +const BAIVirtualFolderNodeNotificationItem: React.FC< |
| 22 | + BAIVirtualFolderNodeNotificationItemProps |
| 23 | +> = ({ notification, virtualFolderNodeFrgmt, showDate }) => { |
| 24 | + const navigate = useNavigate(); |
| 25 | + const { t } = useTranslation(); |
| 26 | + const { token } = theme.useToken(); |
| 27 | + const { closeNotification } = useSetBAINotification(); |
| 28 | + const [showExtraDescription, { toggle: toggleShowExtraDescription }] = |
| 29 | + useToggle(false); |
| 30 | + |
| 31 | + const node = useFragment( |
| 32 | + graphql` |
| 33 | + fragment BAIVirtualFolderNodeNotificationItemFragment on VirtualFolderNode { |
| 34 | + row_id |
| 35 | + id |
| 36 | + name |
| 37 | + status |
| 38 | + } |
| 39 | + `, |
| 40 | + virtualFolderNodeFrgmt, |
| 41 | + ); |
| 42 | + |
| 43 | + // Implementation goes here |
| 44 | + return ( |
| 45 | + node && ( |
| 46 | + <BAINotificationItem |
| 47 | + title={ |
| 48 | + <BAIText ellipsis> |
| 49 | + {t('general.Folder')}: |
| 50 | + <BAILink |
| 51 | + style={{ |
| 52 | + fontWeight: 'normal', |
| 53 | + }} |
| 54 | + title={node.name || ''} |
| 55 | + onClick={() => { |
| 56 | + navigate( |
| 57 | + `/data${node.row_id ? `?${new URLSearchParams({ folder: node.row_id }).toString()}` : ''}`, |
| 58 | + ); |
| 59 | + closeNotification(notification.key); |
| 60 | + }} |
| 61 | + > |
| 62 | + {node.name} |
| 63 | + </BAILink> |
| 64 | + </BAIText> |
| 65 | + } |
| 66 | + description={ |
| 67 | + <List.Item> |
| 68 | + <BAIFlex direction="column" align="stretch" gap={'xxs'}> |
| 69 | + <BAIFlex |
| 70 | + direction="row" |
| 71 | + align="end" |
| 72 | + gap={'xxs'} |
| 73 | + justify="between" |
| 74 | + > |
| 75 | + {_.isString(notification.description) ? ( |
| 76 | + <Typography.Paragraph> |
| 77 | + {_.truncate(notification.description, { length: 300 })} |
| 78 | + </Typography.Paragraph> |
| 79 | + ) : ( |
| 80 | + notification.description |
| 81 | + )} |
| 82 | + |
| 83 | + {notification.extraDescription && !notification?.onCancel ? ( |
| 84 | + <BAIFlex> |
| 85 | + <Typography.Link |
| 86 | + onClick={() => { |
| 87 | + toggleShowExtraDescription(); |
| 88 | + }} |
| 89 | + > |
| 90 | + {t('notification.SeeDetail')} |
| 91 | + </Typography.Link> |
| 92 | + </BAIFlex> |
| 93 | + ) : null} |
| 94 | + </BAIFlex> |
| 95 | + |
| 96 | + {notification.extraDescription && showExtraDescription ? ( |
| 97 | + <Card |
| 98 | + size="small" |
| 99 | + style={{ |
| 100 | + maxHeight: '300px', |
| 101 | + overflow: 'auto', |
| 102 | + overflowX: 'hidden', |
| 103 | + marginTop: token.marginSM, |
| 104 | + }} |
| 105 | + > |
| 106 | + {_.isString(notification.extraDescription) ? ( |
| 107 | + <Typography.Text type="secondary" copyable> |
| 108 | + {notification.extraDescription} |
| 109 | + </Typography.Text> |
| 110 | + ) : ( |
| 111 | + notification.extraDescription |
| 112 | + )} |
| 113 | + </Card> |
| 114 | + ) : null} |
| 115 | + |
| 116 | + {notification.backgroundTask && ( |
| 117 | + <BAINotificationBackgroundItem |
| 118 | + backgroundTask={notification.backgroundTask} |
| 119 | + showDate={showDate} |
| 120 | + /> |
| 121 | + )} |
| 122 | + </BAIFlex> |
| 123 | + </List.Item> |
| 124 | + } |
| 125 | + footer={ |
| 126 | + showDate ? dayjs(notification.created).format('lll') : undefined |
| 127 | + } |
| 128 | + /> |
| 129 | + ) |
| 130 | + ); |
| 131 | +}; |
| 132 | + |
| 133 | +export default BAIVirtualFolderNodeNotificationItem; |
0 commit comments