-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathOthersActivityStatus.tsx
More file actions
89 lines (72 loc) · 2.83 KB
/
OthersActivityStatus.tsx
File metadata and controls
89 lines (72 loc) · 2.83 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
import { warnOnce } from '@msinternal/botframework-webchat-base/utils';
import { useStyles } from '@msinternal/botframework-webchat-styles/react';
import { hooks } from 'botframework-webchat-api';
import {
getOrgSchemaMessage,
OrgSchemaProject,
parseAction,
parseClaim,
type WebChatActivity
} from 'botframework-webchat-core';
import cx from 'classnames';
import React, { memo, useMemo } from 'react';
import ActivityFeedback from '../ActivityFeedback/ActivityFeedback';
import dereferenceBlankNodes from '../Utils/JSONLinkedData/dereferenceBlankNodes';
import Originator from './private/Originator';
import StatusSlot from './StatusSlot';
import Timestamp from './Timestamp';
import styles from './ActivityStatus.module.css';
const { useStyleOptions } = hooks;
type Props = Readonly<{ activity: WebChatActivity; className?: string | undefined; slotted?: boolean }>;
const warnRootLevelThings = warnOnce(
'Root-level things are being deprecated, please relate all things to `entities[@id=""]` instead. This feature will be removed in 2025-03-06.'
);
const OthersActivityStatus = memo(({ activity, className, slotted }: Props) => {
const [{ feedbackActionsPlacement }] = useStyleOptions();
const classNames = useStyles(styles);
const { timestamp } = activity;
const graph = useMemo(() => dereferenceBlankNodes(activity.entities || []), [activity.entities]);
const messageThing = useMemo(() => getOrgSchemaMessage(graph), [graph]);
const claimInterpreter = useMemo<OrgSchemaProject | undefined>(() => {
try {
if (messageThing) {
return parseClaim((messageThing?.citation || [])[0])?.claimInterpreter;
}
const [firstClaim] = graph.filter(({ type }) => type === 'https://schema.org/Claim').map(parseClaim);
if (firstClaim) {
warnRootLevelThings();
return firstClaim?.claimInterpreter;
}
const replyAction = parseAction(graph.find(({ type }) => type === 'https://schema.org/ReplyAction'));
if (replyAction) {
warnRootLevelThings();
return replyAction?.provider;
}
} catch {
// Intentionally left blank.
}
}, [graph, messageThing]);
return (
<span
className={cx(classNames['activity-status'], { [classNames['activity-status--slotted']]: slotted }, className)}
>
{timestamp && (
<StatusSlot>
<Timestamp key="timestamp" timestamp={timestamp} />
</StatusSlot>
)}
{claimInterpreter && (
<StatusSlot>
<Originator key="originator" project={claimInterpreter} />
</StatusSlot>
)}
{feedbackActionsPlacement === 'activity-status' && (
<StatusSlot>
<ActivityFeedback activity={activity} key="feedback" />
</StatusSlot>
)}
</span>
);
});
OthersActivityStatus.displayName = 'OthersActivityStatus';
export default OthersActivityStatus;