-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathBAINodeNotificationItem.tsx
More file actions
83 lines (79 loc) · 2.89 KB
/
BAINodeNotificationItem.tsx
File metadata and controls
83 lines (79 loc) · 2.89 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
/**
@license
Copyright (c) 2015-2026 Lablup Inc. All rights reserved.
*/
import { NotificationState } from '../hooks/useBAINotification';
import BAIComputeSessionNodeNotificationItem from './BAIComputeSessionNodeNotificationItem';
import BAIVFolderNotificationItem from './BAIVFolderNotificationItem';
import BAIVirtualFolderNodeNotificationItem from './BAIVirtualFolderNodeNotificationItem';
import React from 'react';
import { graphql, useRefetchableFragment } from 'react-relay';
import { BAINodeNotificationItemFragment$key } from 'src/__generated__/BAINodeNotificationItemFragment.graphql';
// `... on VFolder` is the V2 (Strawberry GraphQL, FR-2573) branch and the
// preferred path for new VFolder list/mutation flows.
// `... on VirtualFolderNode` is the legacy V1 branch and is **deprecated** —
// kept here only so callers that still hold V1 fragments keep rendering. It
// will be removed once all VFolder callers migrate to V2 `VFolder`.
const nodeFragmentOperation = graphql`
fragment BAINodeNotificationItemFragment on Node
@refetchable(queryName: "BAINodeNotificationItemRefetchQuery") {
... on ComputeSessionNode {
__typename
status
name
row_id
...BAIComputeSessionNodeNotificationItemFragment
@alias(as: "sessionFrgmt")
}
... on VFolder {
__typename
...BAIVFolderNotificationItemFragment @alias(as: "vfolderFrgmt")
}
... on VirtualFolderNode {
__typename
status
...BAIVirtualFolderNodeNotificationItemFragment
@alias(as: "virtualFolderNodeFrgmt")
}
}
`;
const BAINodeNotificationItem: React.FC<{
notification: NotificationState;
nodeFrgmt: BAINodeNotificationItemFragment$key | null;
showDate?: boolean;
}> = ({ notification, nodeFrgmt, showDate }) => {
const [node] = useRefetchableFragment(nodeFragmentOperation, nodeFrgmt);
if (node?.__typename === 'ComputeSessionNode') {
return (
<BAIComputeSessionNodeNotificationItem
notification={notification}
sessionFrgmt={node.sessionFrgmt || null}
showDate={showDate}
primaryAppOption={notification.extraData}
/>
);
} else if (node?.__typename === 'VFolder') {
return (
<BAIVFolderNotificationItem
notification={notification}
vfolderFrgmt={node.vfolderFrgmt || null}
showDate={showDate}
/>
);
} else if (node?.__typename === 'VirtualFolderNode') {
// @deprecated Renders the legacy V1 VFolder notification. Will be removed
// once all V1 callers are gone — see the matching note on the V2 branch
// above.
return (
<BAIVirtualFolderNodeNotificationItem
notification={notification}
virtualFolderNodeFrgmt={node.virtualFolderNodeFrgmt || null}
showDate={showDate}
/>
);
} else {
// console.warn('Unknown node type in BAINodeNotificationItem:', node);
return null;
}
};
export default BAINodeNotificationItem;