@nualang/nualang-ui-components 0.1.1402 → 0.1.1404

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { useState } from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import { useInView } from "react-intersection-observer";
4
4
  import PlaceholderImages from "../../utils/placeholder-images/index";
5
- import { Button, Typography, CardActionArea, CardActions, Menu, MenuItem, IconButton, Divider, Tooltip } from "@mui/material";
5
+ import { Button, Typography, CardActionArea, CardActions, Checkbox, Menu, MenuItem, IconButton, Divider, Tooltip } from "@mui/material";
6
6
  import Skeleton from "@mui/material/Skeleton";
7
7
  import Person from "@mui/icons-material/Person";
8
8
  import LanguageIcon from "@mui/icons-material/Public";
@@ -120,6 +120,8 @@ function Bot({
120
120
  handleOpenPreview,
121
121
  disablePreview,
122
122
  cardTitleComponent = "h3",
123
+ selectionEnabled = false,
124
+ isSelected = false,
123
125
  compact = false
124
126
  }) {
125
127
  const [anchorEl, setAnchorEl] = useState(null);
@@ -278,7 +280,14 @@ function Bot({
278
280
  component: cardTitleComponent,
279
281
  compact: compact
280
282
  }),
281
- action: /*#__PURE__*/_jsx(Tooltip, {
283
+ action: selectionEnabled ? /*#__PURE__*/_jsx(Checkbox, {
284
+ checked: isSelected,
285
+ onChange: selectBot,
286
+ onClick: e => e.stopPropagation(),
287
+ color: "primary",
288
+ disabled: disableActions,
289
+ "aria-label": `${t("select")}: ${botName}`
290
+ }) : /*#__PURE__*/_jsx(Tooltip, {
282
291
  title: t("more_options"),
283
292
  children: /*#__PURE__*/_jsx(IconButton, {
284
293
  "aria-label": "More Options",
@@ -358,7 +367,7 @@ function Bot({
358
367
  color: "primary",
359
368
  variant: "outlined",
360
369
  "data-cy": "bot_select_button",
361
- disabled: disableActions,
370
+ disabled: disableActions || selectionEnabled && isSelected,
362
371
  "aria-label": `${t(selectText)}: ${botName}`,
363
372
  children: t(selectText)
364
373
  }), handleOpenPreview && !disablePreview ? /*#__PURE__*/_jsx(Button, {
@@ -2,7 +2,7 @@ import { useState } from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import { useInView } from "react-intersection-observer";
4
4
  import PlaceholderImages from "../../utils/placeholder-images/index";
5
- import { Button, Typography, CardActionArea, Divider, CardActions, Menu, MenuItem, IconButton, Tooltip } from "@mui/material";
5
+ import { Button, Typography, CardActionArea, Divider, CardActions, Checkbox, Menu, MenuItem, IconButton, Tooltip } from "@mui/material";
6
6
  import Skeleton from "@mui/material/Skeleton";
7
7
  import Person from "@mui/icons-material/Person";
8
8
  import LanguageIcon from "@mui/icons-material/Public";
@@ -120,6 +120,8 @@ function Roleplay({
120
120
  handleOpenPreview,
121
121
  disablePreview,
122
122
  cardTitleComponent = "h3",
123
+ selectionEnabled = false,
124
+ isSelected = false,
123
125
  compact = false
124
126
  }) {
125
127
  const [anchorEl, setAnchorEl] = useState(null);
@@ -277,7 +279,14 @@ function Roleplay({
277
279
  component: cardTitleComponent,
278
280
  compact: compact
279
281
  }),
280
- action: /*#__PURE__*/_jsx(Tooltip, {
282
+ action: selectionEnabled ? /*#__PURE__*/_jsx(Checkbox, {
283
+ checked: isSelected,
284
+ onChange: selectRoleplay,
285
+ onClick: e => e.stopPropagation(),
286
+ color: "primary",
287
+ disabled: disableActions,
288
+ "aria-label": `${t("select")} roleplay: ${roleplayName}`
289
+ }) : /*#__PURE__*/_jsx(Tooltip, {
281
290
  title: t("more_options"),
282
291
  children: /*#__PURE__*/_jsx(IconButton, {
283
292
  "aria-label": "More Options",
@@ -357,7 +366,7 @@ function Roleplay({
357
366
  color: "primary",
358
367
  variant: "outlined",
359
368
  "data-cy": "roleplay_select_button",
360
- disabled: disableActions,
369
+ disabled: disableActions || selectionEnabled && isSelected,
361
370
  "aria-label": `${t(selectText)}) roleplay: ${roleplayName}`,
362
371
  children: t(selectText)
363
372
  }), handleOpenPreview && roleplay.roleplayId !== "nualang.author-from-scratch.0.0.1" && !disablePreview ? /*#__PURE__*/_jsx(Button, {
@@ -0,0 +1,321 @@
1
+ import { useState, useEffect, useRef } from "react";
2
+ import { useInView } from "react-intersection-observer";
3
+ import Dialog from "@mui/material/Dialog";
4
+ import AppBar from "@mui/material/AppBar";
5
+ import Toolbar from "@mui/material/Toolbar";
6
+ import IconButton from "@mui/material/IconButton";
7
+ import Typography from "@mui/material/Typography";
8
+ import Box from "@mui/material/Box";
9
+ import Tabs from "@mui/material/Tabs";
10
+ import Tab from "@mui/material/Tab";
11
+ import Avatar from "@mui/material/Avatar";
12
+ import Chip from "@mui/material/Chip";
13
+ import Button from "@mui/material/Button";
14
+ import CircularProgress from "@mui/material/CircularProgress";
15
+ import CloseIcon from "@mui/icons-material/Close";
16
+ import AddIcon from "@mui/icons-material/Add";
17
+ import Bots from "../../Lists/Bots/Bots";
18
+ import PlaceholderImages from "../../utils/placeholder-images/index";
19
+ import { SearchFilters, Transition } from "../SearchFilters/SearchFilters";
20
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
21
+ export default function FindChatbotDialog({
22
+ open,
23
+ handleClose,
24
+ onAddChatbots,
25
+ libraryChatbots = [],
26
+ communityChatbots = [],
27
+ isLoadingLibrary = false,
28
+ isLoadingCommunity = false,
29
+ onLoadMoreCommunity,
30
+ hasMoreCommunity = false,
31
+ isLoadingMoreCommunity = false,
32
+ t = text => text
33
+ }) {
34
+ const scrollRef = useRef(null);
35
+ const {
36
+ ref: sentinelRef,
37
+ inView: sentinelInView
38
+ } = useInView({
39
+ threshold: 0
40
+ });
41
+ const [tab, setTab] = useState(0);
42
+ const [selectedBotIds, setSelectedBotIds] = useState([]);
43
+ const [search, setSearch] = useState("");
44
+ const [filters, setFilters] = useState({
45
+ difficulty: "all",
46
+ sort: "newest"
47
+ });
48
+ const allChatbots = [...libraryChatbots, ...communityChatbots];
49
+ const selectedChatbots = allChatbots.filter(bot => selectedBotIds.includes(bot.botId)).filter((bot, index, arr) => arr.findIndex(b => b.botId === bot.botId) === index).map(bot => ({
50
+ ...bot,
51
+ picture: bot.picture || bot.botAvatar || PlaceholderImages.bot
52
+ }));
53
+ const handleToggle = botId => {
54
+ setSelectedBotIds(prev => prev.includes(botId) ? prev.filter(id => id !== botId) : [...prev, botId]);
55
+ };
56
+ const handleFilterChange = event => {
57
+ const {
58
+ name,
59
+ value
60
+ } = event.target;
61
+ setFilters(prev => ({
62
+ ...prev,
63
+ [name]: value
64
+ }));
65
+ };
66
+ const handleAdd = () => {
67
+ onAddChatbots(selectedChatbots);
68
+ reset();
69
+ handleClose();
70
+ };
71
+ const reset = () => {
72
+ setSelectedBotIds([]);
73
+ setSearch("");
74
+ setFilters({
75
+ difficulty: "all",
76
+ sort: "newest"
77
+ });
78
+ setTab(0);
79
+ };
80
+ const handleDialogClose = () => {
81
+ reset();
82
+ handleClose();
83
+ };
84
+ useEffect(() => {
85
+ if (sentinelInView && tab === 1 && hasMoreCommunity && !isLoadingMoreCommunity) {
86
+ onLoadMoreCommunity?.();
87
+ }
88
+ }, [sentinelInView, tab, hasMoreCommunity, isLoadingMoreCommunity, onLoadMoreCommunity]);
89
+ const handleTabChange = (_, v) => {
90
+ setTab(v);
91
+ setSearch("");
92
+ setFilters({
93
+ difficulty: "all",
94
+ sort: "newest"
95
+ });
96
+ if (scrollRef.current) scrollRef.current.scrollTop = 0;
97
+ };
98
+ const filterChatbots = chatbots => {
99
+ if (!search.trim()) return chatbots;
100
+ const q = search.toLowerCase();
101
+ return chatbots.filter(bot => bot.botName?.toLowerCase().includes(q) || bot.description?.toLowerCase().includes(q) || bot.createdByName?.toLowerCase().includes(q));
102
+ };
103
+ const applyCommunityFilters = chatbots => {
104
+ let result = filterChatbots(chatbots);
105
+ if (filters.difficulty && filters.difficulty !== "all") {
106
+ result = result.filter(bot => bot.difficulty === filters.difficulty);
107
+ }
108
+ if (filters.sort === "newest") {
109
+ result = [...result].sort((a, b) => new Date(b.createdAt || 0) - new Date(a.createdAt || 0));
110
+ } else if (filters.sort === "oldest") {
111
+ result = [...result].sort((a, b) => new Date(a.createdAt || 0) - new Date(b.createdAt || 0));
112
+ } else {
113
+ result = [...result].sort((a, b) => (b.exerciseStartTotal || 0) - (a.exerciseStartTotal || 0));
114
+ }
115
+ return result;
116
+ };
117
+ const currentChatbots = tab === 0 ? filterChatbots(libraryChatbots) : applyCommunityFilters(communityChatbots);
118
+ const isLoading = tab === 0 ? isLoadingLibrary : isLoadingCommunity;
119
+ const sectionLabel = tab === 0 ? t("add_own_exercise_message", {
120
+ exerciseName: t("chatbots").toLowerCase()
121
+ }) : t("or_select_a_community_template_desc");
122
+ const addButtonLabel = selectedBotIds.length > 0 ? `${t("add_chatbots")} (${selectedBotIds.length})` : t("add_chatbots");
123
+ return /*#__PURE__*/_jsxs(Dialog, {
124
+ open: open,
125
+ onClose: handleDialogClose,
126
+ fullScreen: true,
127
+ TransitionComponent: Transition,
128
+ PaperProps: {
129
+ sx: {
130
+ display: "flex",
131
+ flexDirection: "column"
132
+ }
133
+ },
134
+ children: [/*#__PURE__*/_jsx(AppBar, {
135
+ sx: {
136
+ position: "relative"
137
+ },
138
+ children: /*#__PURE__*/_jsxs(Toolbar, {
139
+ children: [/*#__PURE__*/_jsx(IconButton, {
140
+ edge: "start",
141
+ color: "inherit",
142
+ onClick: handleDialogClose,
143
+ "aria-label": "close",
144
+ children: /*#__PURE__*/_jsx(CloseIcon, {})
145
+ }), /*#__PURE__*/_jsx(Typography, {
146
+ variant: "h6",
147
+ sx: {
148
+ ml: 1,
149
+ fontWeight: 700
150
+ },
151
+ children: t("find_chatbots") || "Find Chatbots"
152
+ })]
153
+ })
154
+ }), /*#__PURE__*/_jsxs(Box, {
155
+ sx: {
156
+ display: "flex",
157
+ flexDirection: "column",
158
+ flex: 1,
159
+ minHeight: 0
160
+ },
161
+ children: [/*#__PURE__*/_jsx(Box, {
162
+ sx: {
163
+ px: 3,
164
+ pt: 1,
165
+ borderBottom: 1,
166
+ borderColor: "divider"
167
+ },
168
+ children: /*#__PURE__*/_jsxs(Tabs, {
169
+ value: tab,
170
+ onChange: handleTabChange,
171
+ indicatorColor: "primary",
172
+ textColor: "primary",
173
+ children: [/*#__PURE__*/_jsx(Tab, {
174
+ label: t("my_library") || "My Library"
175
+ }), /*#__PURE__*/_jsx(Tab, {
176
+ label: t("community") || "Community"
177
+ })]
178
+ })
179
+ }), tab === 1 && /*#__PURE__*/_jsx(Box, {
180
+ sx: {
181
+ px: 3,
182
+ py: {
183
+ xs: 0,
184
+ md: 1.5
185
+ },
186
+ borderBottom: 1,
187
+ borderColor: "divider"
188
+ },
189
+ children: /*#__PURE__*/_jsx(SearchFilters, {
190
+ t: t,
191
+ difficulty: filters.difficulty,
192
+ handleFilterChange: handleFilterChange,
193
+ sort: filters.sort,
194
+ search: search,
195
+ setSearch: setSearch
196
+ })
197
+ }), /*#__PURE__*/_jsx(Box, {
198
+ ref: scrollRef,
199
+ sx: {
200
+ flex: 1,
201
+ overflowY: "auto",
202
+ overflowX: "hidden",
203
+ p: 3
204
+ },
205
+ children: isLoading ? /*#__PURE__*/_jsx(Bots, {
206
+ t: t,
207
+ selectText: t("select") || "Select",
208
+ compact: true
209
+ }) : currentChatbots.length === 0 ? /*#__PURE__*/_jsx(Box, {
210
+ display: "flex",
211
+ justifyContent: "center",
212
+ pt: 8,
213
+ children: /*#__PURE__*/_jsx(Typography, {
214
+ color: "text.secondary",
215
+ children: t("no_chatbots_found") || "No chatbots found"
216
+ })
217
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
218
+ children: [/*#__PURE__*/_jsx(Typography, {
219
+ color: "text.secondary",
220
+ sx: {
221
+ display: "block",
222
+ mb: 2
223
+ },
224
+ children: sectionLabel
225
+ }), /*#__PURE__*/_jsx(Bots, {
226
+ t: t,
227
+ bots: currentChatbots,
228
+ handleSelectBot: bot => handleToggle(bot.botId),
229
+ selectText: t("select") || "Select",
230
+ disablePreview: true,
231
+ selectionEnabled: true,
232
+ isSelected: bot => selectedBotIds.includes(bot.botId),
233
+ compact: true,
234
+ handleViewUserProfile: () => {}
235
+ }), tab === 1 && /*#__PURE__*/_jsx(Box, {
236
+ ref: sentinelRef,
237
+ sx: {
238
+ height: 40,
239
+ display: "flex",
240
+ justifyContent: "center",
241
+ alignItems: "center"
242
+ },
243
+ children: isLoadingMoreCommunity && /*#__PURE__*/_jsx(CircularProgress, {
244
+ size: 24
245
+ })
246
+ })]
247
+ })
248
+ }), /*#__PURE__*/_jsxs(Box, {
249
+ sx: {
250
+ px: 3,
251
+ py: 1.5,
252
+ borderTop: 1,
253
+ borderColor: "divider",
254
+ display: "flex",
255
+ alignItems: "center",
256
+ gap: 2,
257
+ bgcolor: "background.paper",
258
+ flexShrink: 0
259
+ },
260
+ children: [/*#__PURE__*/_jsxs(Box, {
261
+ sx: {
262
+ flex: 1,
263
+ display: "flex",
264
+ flexWrap: "wrap",
265
+ gap: 1,
266
+ alignItems: "center"
267
+ },
268
+ children: [selectedBotIds.length > 0 && /*#__PURE__*/_jsx(Typography, {
269
+ variant: "body2",
270
+ color: "text.secondary",
271
+ sx: {
272
+ flexShrink: 0
273
+ },
274
+ children: `${selectedBotIds.length} ${t("selected") || "selected"}`
275
+ }), selectedChatbots.map(bot => /*#__PURE__*/_jsx(Chip, {
276
+ avatar: /*#__PURE__*/_jsx(Avatar, {
277
+ src: bot.picture,
278
+ alt: bot.botName
279
+ }),
280
+ label: bot.botName,
281
+ onDelete: () => handleToggle(bot.botId),
282
+ sx: {
283
+ flexShrink: 0,
284
+ display: {
285
+ xs: "none",
286
+ sm: "inline-flex"
287
+ }
288
+ }
289
+ }, bot.botId))]
290
+ }), /*#__PURE__*/_jsxs(Box, {
291
+ sx: {
292
+ display: "flex",
293
+ gap: 1.5,
294
+ alignItems: "center",
295
+ flexShrink: 0
296
+ },
297
+ children: [/*#__PURE__*/_jsx(Button, {
298
+ onClick: handleDialogClose,
299
+ color: "primary",
300
+ sx: {
301
+ fontWeight: 600
302
+ },
303
+ children: t("cancel") || "Cancel"
304
+ }), /*#__PURE__*/_jsx(Button, {
305
+ variant: "contained",
306
+ color: "success",
307
+ disabled: selectedBotIds.length === 0,
308
+ onClick: handleAdd,
309
+ startIcon: /*#__PURE__*/_jsx(AddIcon, {}),
310
+ sx: {
311
+ borderRadius: 6,
312
+ px: 3,
313
+ py: 1
314
+ },
315
+ children: addButtonLabel
316
+ })]
317
+ })]
318
+ })]
319
+ })]
320
+ });
321
+ }