-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathBAIVirtualFolderNodeNotificationItem.tsx
More file actions
148 lines (139 loc) · 4.86 KB
/
BAIVirtualFolderNodeNotificationItem.tsx
File metadata and controls
148 lines (139 loc) · 4.86 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
@license
Copyright (c) 2015-2026 Lablup Inc. All rights reserved.
*/
import BAINotificationBackgroundProgress from './BAINotificationBackgroundProgress';
import { useToggle } from 'ahooks';
import { Card, List, theme, Typography } from 'antd';
import { BAIFlex, BAILink, BAINotificationItem, BAIText } from 'backend.ai-ui';
import dayjs from 'dayjs';
import * as _ from 'lodash-es';
import { useTranslation } from 'react-i18next';
import { graphql, useFragment } from 'react-relay';
import { BAIVirtualFolderNodeNotificationItemFragment$key } from 'src/__generated__/BAIVirtualFolderNodeNotificationItemFragment.graphql';
import { useWebUINavigate } from 'src/hooks';
import {
NotificationState,
useSetBAINotification,
} from 'src/hooks/useBAINotification';
interface BAIVirtualFolderNodeNotificationItemProps {
notification: NotificationState;
virtualFolderNodeFrgmt: BAIVirtualFolderNodeNotificationItemFragment$key | null;
showDate?: boolean;
}
/**
* @deprecated Renders V1 `VirtualFolderNode` notifications. The V2 counterpart
* `BAIVFolderNotificationItem` (operating on `VFolder implements Node` from
* the Strawberry GraphQL API, FR-2573) is the preferred path going forward.
* This component will be removed once all V1 callers migrate.
*/
const BAIVirtualFolderNodeNotificationItem: React.FC<
BAIVirtualFolderNodeNotificationItemProps
> = ({ notification, virtualFolderNodeFrgmt, showDate }) => {
'use memo';
const navigate = useWebUINavigate();
const { t } = useTranslation();
const { token } = theme.useToken();
const { closeNotification } = useSetBAINotification();
const [showExtraDescription, { toggle: toggleShowExtraDescription }] =
useToggle(false);
const node = useFragment(
graphql`
fragment BAIVirtualFolderNodeNotificationItemFragment on VirtualFolderNode {
row_id
id
name
status
}
`,
virtualFolderNodeFrgmt,
);
return (
node && (
<BAINotificationItem
title={
<BAIText ellipsis>
{t('general.Folder')}:
<BAILink
style={{
fontWeight: 'normal',
}}
title={node.name || ''}
onClick={() => {
navigate(
`/data${node.row_id ? `?${new URLSearchParams({ folder: node.row_id }).toString()}` : ''}`,
);
closeNotification(notification.key);
}}
>
{node.name}
</BAILink>
</BAIText>
}
description={
<List.Item>
<BAIFlex direction="column" align="stretch" gap={'xxs'}>
<BAIFlex
direction="row"
align="end"
gap={'xxs'}
justify="between"
>
{_.isString(notification.description) ? (
<BAIText style={{ flex: 1, minWidth: 0 }}>
{_.truncate(notification.description, { length: 300 })}
</BAIText>
) : (
notification.description
)}
{notification.extraDescription && !notification?.onCancel ? (
<BAIFlex style={{ flexShrink: 0 }}>
<Typography.Link
style={{ whiteSpace: 'nowrap' }}
onClick={() => {
toggleShowExtraDescription();
}}
>
{showExtraDescription
? t('notification.SeeSummary')
: t('notification.SeeDetail')}
</Typography.Link>
</BAIFlex>
) : null}
</BAIFlex>
{notification.extraDescription && showExtraDescription ? (
<Card
size="small"
style={{
maxHeight: '300px',
overflow: 'auto',
overflowX: 'hidden',
marginTop: token.marginSM,
}}
>
{_.isString(notification.extraDescription) ? (
<Typography.Text type="secondary" copyable>
{notification.extraDescription}
</Typography.Text>
) : (
notification.extraDescription
)}
</Card>
) : null}
{notification.backgroundTask && (
<BAINotificationBackgroundProgress
backgroundTask={notification.backgroundTask}
showDate={showDate}
/>
)}
</BAIFlex>
</List.Item>
}
footer={
showDate ? dayjs(notification.created).format('lll') : undefined
}
/>
)
);
};
export default BAIVirtualFolderNodeNotificationItem;