-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRecordChatterPanel.tsx
More file actions
207 lines (198 loc) · 6.61 KB
/
Copy pathRecordChatterPanel.tsx
File metadata and controls
207 lines (198 loc) · 6.61 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import { cn, Button } from '@object-ui/components';
import { MessageSquare, PanelRightOpen, PanelRightClose, X } from 'lucide-react';
import type { RecordChatterComponentProps, FeedItem, RecordSubscription } from '@object-ui/types';
import { RecordActivityTimeline } from './RecordActivityTimeline';
import type { FeedFilterMode, RecordActivityTimelineProps } from './RecordActivityTimeline';
export interface RecordChatterPanelProps {
/** Chatter panel configuration from RecordChatterComponentProps */
config?: RecordChatterComponentProps;
/** Feed items to display in the embedded timeline */
items: FeedItem[];
/** Whether there are more items to load */
hasMore?: boolean;
/** Called when user wants to load more */
onLoadMore?: () => void | Promise<void>;
/** Loading state */
loading?: boolean;
/** Called when a comment is submitted */
onAddComment?: (text: string) => void | Promise<void>;
/** Called when a reply is submitted */
onAddReply?: (parentId: string | number, text: string) => void | Promise<void>;
/** Called when user toggles a reaction */
onToggleReaction?: (itemId: string | number, emoji: string) => void | Promise<void>;
/** Subscription state */
subscription?: RecordSubscription;
/** Called when user toggles subscription */
onToggleSubscription?: (subscribed: boolean) => void | Promise<void>;
/** Filter mode */
filterMode?: FeedFilterMode;
/** Called when filter changes */
onFilterChange?: (mode: FeedFilterMode) => void;
/** When true, auto-collapse panel when there are no feed items */
collapseWhenEmpty?: boolean;
className?: string;
}
/**
* RecordChatterPanel — Side/inline/drawer panel for record discussions.
*
* Consumes RecordChatterComponentProps from the spec protocol.
* Supports three positions: bottom (inline), right (sidebar), left (sidebar).
* Can be collapsible/expandable.
*
* Embeds RecordActivityTimeline as the feed sub-component.
*/
export const RecordChatterPanel: React.FC<RecordChatterPanelProps> = ({
config,
items,
hasMore,
onLoadMore,
loading,
onAddComment,
onAddReply,
onToggleReaction,
subscription,
onToggleSubscription,
filterMode,
onFilterChange,
collapseWhenEmpty = false,
className,
}) => {
const position = config?.position ?? 'right';
const width = config?.width ?? '360px';
const collapsible = config?.collapsible ?? true;
const defaultCollapsed = (collapseWhenEmpty && items.length === 0) || (config?.defaultCollapsed ?? false);
const [collapsed, setCollapsed] = React.useState(defaultCollapsed);
const isSidebar = position === 'right' || position === 'left';
const isInline = position === 'bottom';
// Sidebar mode
if (isSidebar) {
if (collapsed && collapsible) {
return (
<div
className={cn(
'flex items-start pt-4',
position === 'right' ? 'border-l' : 'border-r',
className,
)}
>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 mx-1"
onClick={() => setCollapsed(false)}
aria-label="Open discussion panel"
>
<PanelRightOpen className="h-4 w-4" />
</Button>
</div>
);
}
return (
<div
className={cn(
'flex flex-col overflow-hidden',
position === 'right' ? 'border-l' : 'border-r',
className,
)}
style={{ width, minWidth: width }}
>
{/* Header */}
<div className="flex items-center justify-between px-4 py-3 border-b">
<div className="flex items-center gap-2">
<MessageSquare className="h-4 w-4" />
<span className="text-sm font-medium">Discussion</span>
</div>
{collapsible && (
<Button
variant="ghost"
size="icon"
className="h-7 w-7"
onClick={() => setCollapsed(true)}
aria-label="Close discussion panel"
>
<X className="h-3.5 w-3.5" />
</Button>
)}
</div>
{/* Embedded Timeline */}
<div className="flex-1 overflow-y-auto">
<RecordActivityTimeline
items={items}
config={config?.feed}
hasMore={hasMore}
onLoadMore={onLoadMore}
loading={loading}
onAddComment={onAddComment}
onAddReply={onAddReply}
onToggleReaction={onToggleReaction}
subscription={subscription}
onToggleSubscription={onToggleSubscription}
filterMode={filterMode}
onFilterChange={onFilterChange}
collapseWhenEmpty={collapseWhenEmpty}
className="border-0 shadow-none"
/>
</div>
</div>
);
}
// Inline / bottom mode
return (
<div className={cn('', className)}>
{collapsible && collapsed ? (
<Button
variant="ghost"
className="w-full justify-start gap-2 text-muted-foreground"
onClick={() => setCollapsed(false)}
aria-label="Show discussion"
>
<MessageSquare className="h-4 w-4" />
<span>Show Discussion ({items.length})</span>
</Button>
) : (
<div>
{collapsible && (
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-2 text-sm font-medium">
<MessageSquare className="h-4 w-4" />
Discussion
</div>
<Button
variant="ghost"
size="icon"
className="h-7 w-7"
onClick={() => setCollapsed(true)}
aria-label="Hide discussion"
>
<PanelRightClose className="h-3.5 w-3.5" />
</Button>
</div>
)}
<RecordActivityTimeline
items={items}
config={config?.feed}
hasMore={hasMore}
onLoadMore={onLoadMore}
loading={loading}
onAddComment={onAddComment}
onAddReply={onAddReply}
onToggleReaction={onToggleReaction}
subscription={subscription}
onToggleSubscription={onToggleSubscription}
filterMode={filterMode}
onFilterChange={onFilterChange}
collapseWhenEmpty={collapseWhenEmpty}
/>
</div>
)}
</div>
);
};