@red-hat-developer-hub/backstage-plugin-lightspeed 0.5.6 → 0.6.0

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/components/Attachment.esm.js +71 -61
  3. package/dist/components/Attachment.esm.js.map +1 -1
  4. package/dist/components/AttachmentContext.esm.js +32 -23
  5. package/dist/components/AttachmentContext.esm.js.map +1 -1
  6. package/dist/components/DeleteModal.esm.js +24 -15
  7. package/dist/components/DeleteModal.esm.js.map +1 -1
  8. package/dist/components/FilePreview.esm.js +16 -13
  9. package/dist/components/FilePreview.esm.js.map +1 -1
  10. package/dist/components/LightSpeedChat.esm.js +172 -129
  11. package/dist/components/LightSpeedChat.esm.js.map +1 -1
  12. package/dist/components/LightspeedChatBox.esm.js +43 -34
  13. package/dist/components/LightspeedChatBox.esm.js.map +1 -1
  14. package/dist/components/LightspeedChatBoxHeader.esm.js +15 -12
  15. package/dist/components/LightspeedChatBoxHeader.esm.js.map +1 -1
  16. package/dist/components/LightspeedIcon.esm.js +11 -2
  17. package/dist/components/LightspeedIcon.esm.js.map +1 -1
  18. package/dist/components/LightspeedPage.esm.js +32 -26
  19. package/dist/components/LightspeedPage.esm.js.map +1 -1
  20. package/dist/components/PermissionRequiredIcon.esm.js +10 -2
  21. package/dist/components/PermissionRequiredIcon.esm.js.map +1 -1
  22. package/dist/components/PermissionRequiredState.esm.js +25 -11
  23. package/dist/components/PermissionRequiredState.esm.js.map +1 -1
  24. package/dist/components/Trans.esm.js +33 -0
  25. package/dist/components/Trans.esm.js.map +1 -0
  26. package/dist/const.esm.js +20 -43
  27. package/dist/const.esm.js.map +1 -1
  28. package/dist/hooks/useAutoScroll.esm.js +11 -11
  29. package/dist/hooks/useAutoScroll.esm.js.map +1 -1
  30. package/dist/hooks/useBufferedMessages.esm.js +5 -5
  31. package/dist/hooks/useBufferedMessages.esm.js.map +1 -1
  32. package/dist/hooks/useConversationMessages.esm.js +8 -8
  33. package/dist/hooks/useConversationMessages.esm.js.map +1 -1
  34. package/dist/hooks/useFeedbackActions.esm.js +47 -18
  35. package/dist/hooks/useFeedbackActions.esm.js.map +1 -1
  36. package/dist/hooks/useIsMobile.esm.js +3 -3
  37. package/dist/hooks/useIsMobile.esm.js.map +1 -1
  38. package/dist/hooks/useLastOpenedConversation.esm.js.map +1 -1
  39. package/dist/hooks/useTranslation.esm.js +7 -0
  40. package/dist/hooks/useTranslation.esm.js.map +1 -0
  41. package/dist/hooks/useWelcomePrompts.esm.js +21 -6
  42. package/dist/hooks/useWelcomePrompts.esm.js.map +1 -1
  43. package/dist/index.d.ts +11 -5
  44. package/dist/index.esm.js +1 -0
  45. package/dist/index.esm.js.map +1 -1
  46. package/dist/translations/de.esm.js +128 -0
  47. package/dist/translations/de.esm.js.map +1 -0
  48. package/dist/translations/es.esm.js +128 -0
  49. package/dist/translations/es.esm.js.map +1 -0
  50. package/dist/translations/fr.esm.js +128 -0
  51. package/dist/translations/fr.esm.js.map +1 -0
  52. package/dist/translations/index.esm.js +14 -0
  53. package/dist/translations/index.esm.js.map +1 -0
  54. package/dist/translations/translationRef.esm.js +128 -0
  55. package/dist/translations/translationRef.esm.js.map +1 -0
  56. package/dist/types.esm.js.map +1 -1
  57. package/dist/utils/lightspeed-chatbox-utils.esm.js +24 -21
  58. package/dist/utils/lightspeed-chatbox-utils.esm.js.map +1 -1
  59. package/package.json +14 -14
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  ## @red-hat-developer-hub/backstage-plugin-lightspeed
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 693c3df: Add internationalization (i18n) support with German, French and Spanish translations in lightspeed.
8
+ - d922b04: Backstage version bump to v1.42.5
9
+
10
+ ### Patch Changes
11
+
12
+ - cfa3434: Updated dependency `@patternfly/chatbot` to `6.3.2`.
13
+ Updated dependency `@patternfly/react-core` to `6.3.1`.
14
+ - Updated dependencies [d922b04]
15
+ - @red-hat-developer-hub/backstage-plugin-lightspeed-common@0.4.0
16
+
17
+ ## 0.5.7
18
+
19
+ ### Patch Changes
20
+
21
+ - 0e00cb6: Upgrade backstage to 1.39.1
22
+ - Updated dependencies [0e00cb6]
23
+ - @red-hat-developer-hub/backstage-plugin-lightspeed-common@0.3.4
24
+
3
25
  ## 0.5.6
4
26
 
5
27
  ### Patch Changes
@@ -1,6 +1,7 @@
1
- import React__default from 'react';
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
2
  import { makeStyles } from '@material-ui/core';
3
3
  import { PreviewAttachment, ChatbotDisplayMode, AttachmentEdit } from '@patternfly/chatbot';
4
+ import { useTranslation } from '../hooks/useTranslation.esm.js';
4
5
  import { useFileAttachmentContext } from './AttachmentContext.esm.js';
5
6
 
6
7
  const useStyles = makeStyles(() => ({
@@ -18,6 +19,7 @@ const Attachment = () => {
18
19
  setCurrentFileContent
19
20
  } = useFileAttachmentContext();
20
21
  const classes = useStyles();
22
+ const { t } = useTranslation();
21
23
  if (!currentFileContent) {
22
24
  return null;
23
25
  }
@@ -29,69 +31,77 @@ const Attachment = () => {
29
31
  setIsEditModalOpen,
30
32
  setIsPreviewModalOpen
31
33
  } = modalState;
32
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
33
- PreviewAttachment,
34
- {
35
- key: previewModalKey,
36
- code: currentFileContent?.content,
37
- fileName: currentFileContent?.name,
38
- isModalOpen: isPreviewModalOpen,
39
- secondaryActionButtonText: "Close",
40
- modalFooterClassName: classes.modalFooter,
41
- onEdit: () => {
42
- setIsPreviewModalOpen(false);
43
- setIsEditModalOpen(true);
34
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
35
+ /* @__PURE__ */ jsx(
36
+ PreviewAttachment,
37
+ {
38
+ code: currentFileContent?.content,
39
+ fileName: currentFileContent?.name,
40
+ isModalOpen: isPreviewModalOpen,
41
+ secondaryActionButtonText: t("modal.close"),
42
+ primaryActionButtonText: t("modal.edit"),
43
+ title: t("modal.title.preview"),
44
+ modalFooterClassName: classes.modalFooter,
45
+ onEdit: () => {
46
+ setIsPreviewModalOpen(false);
47
+ setIsEditModalOpen(true);
48
+ },
49
+ onDismiss: () => {
50
+ setCurrentFileContent(undefined);
51
+ setIsPreviewModalOpen(false);
52
+ },
53
+ handleModalToggle: () => setIsPreviewModalOpen(false),
54
+ displayMode: ChatbotDisplayMode.fullscreen
44
55
  },
45
- onDismiss: () => {
46
- setCurrentFileContent(undefined);
47
- setIsPreviewModalOpen(false);
48
- },
49
- handleModalToggle: () => setIsPreviewModalOpen(false),
50
- displayMode: ChatbotDisplayMode.fullscreen
51
- }
52
- ), /* @__PURE__ */ React__default.createElement(
53
- AttachmentEdit,
54
- {
55
- key: currentFileContent?.content,
56
- code: currentFileContent?.content,
57
- fileName: currentFileContent?.name,
58
- isModalOpen: isEditModalOpen,
59
- modalFooterClassName: classes.modalFooter,
60
- onSave: (_, content) => {
61
- setCurrentFileContent({
62
- ...currentFileContent,
63
- content
64
- });
65
- setFileContents((prev) => {
66
- const existingIndex = prev.findIndex(
67
- (f) => f.name === currentFileContent?.name
68
- );
69
- if (existingIndex !== -1) {
70
- const updated = [...prev];
71
- updated[existingIndex] = {
72
- ...updated[existingIndex],
73
- content
74
- };
75
- return updated;
76
- }
77
- return [
78
- ...prev,
79
- {
80
- name: currentFileContent?.name,
81
- type: currentFileContent?.type,
82
- content
56
+ previewModalKey
57
+ ),
58
+ /* @__PURE__ */ jsx(
59
+ AttachmentEdit,
60
+ {
61
+ code: currentFileContent?.content,
62
+ fileName: currentFileContent?.name,
63
+ isModalOpen: isEditModalOpen,
64
+ title: t("modal.title.edit"),
65
+ secondaryActionButtonText: t("modal.cancel"),
66
+ primaryActionButtonText: t("modal.save"),
67
+ modalFooterClassName: classes.modalFooter,
68
+ onSave: (_, content) => {
69
+ setCurrentFileContent({
70
+ ...currentFileContent,
71
+ content
72
+ });
73
+ setFileContents((prev) => {
74
+ const existingIndex = prev.findIndex(
75
+ (f) => f.name === currentFileContent?.name
76
+ );
77
+ if (existingIndex !== -1) {
78
+ const updated = [...prev];
79
+ updated[existingIndex] = {
80
+ ...updated[existingIndex],
81
+ content
82
+ };
83
+ return updated;
83
84
  }
84
- ];
85
- });
86
- setPreviewModalKey((prev) => prev + 1);
87
- setIsEditModalOpen(false);
88
- setIsPreviewModalOpen(true);
85
+ return [
86
+ ...prev,
87
+ {
88
+ name: currentFileContent?.name,
89
+ type: currentFileContent?.type,
90
+ content
91
+ }
92
+ ];
93
+ });
94
+ setPreviewModalKey((prev) => prev + 1);
95
+ setIsEditModalOpen(false);
96
+ setIsPreviewModalOpen(true);
97
+ },
98
+ onCancel: () => setCurrentFileContent(undefined),
99
+ handleModalToggle: () => setIsEditModalOpen(false),
100
+ displayMode: ChatbotDisplayMode.fullscreen
89
101
  },
90
- onCancel: () => setCurrentFileContent(undefined),
91
- handleModalToggle: () => setIsEditModalOpen(false),
92
- displayMode: ChatbotDisplayMode.fullscreen
93
- }
94
- ));
102
+ currentFileContent?.content
103
+ )
104
+ ] });
95
105
  };
96
106
 
97
107
  export { Attachment as default };
@@ -1 +1 @@
1
- {"version":3,"file":"Attachment.esm.js","sources":["../../src/components/Attachment.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport { makeStyles } from '@material-ui/core';\nimport {\n AttachmentEdit,\n ChatbotDisplayMode,\n PreviewAttachment,\n} from '@patternfly/chatbot';\n\nimport { useFileAttachmentContext } from './AttachmentContext';\n\nconst useStyles = makeStyles(() => ({\n modalFooter: {\n '&>button': {\n width: '12% !important',\n },\n },\n}));\nconst Attachment = () => {\n const {\n currentFileContent,\n setFileContents,\n modalState,\n setCurrentFileContent,\n } = useFileAttachmentContext();\n const classes = useStyles();\n\n if (!currentFileContent) {\n return null;\n }\n const {\n previewModalKey,\n isPreviewModalOpen,\n isEditModalOpen,\n setPreviewModalKey,\n setIsEditModalOpen,\n setIsPreviewModalOpen,\n } = modalState;\n\n return (\n <>\n <PreviewAttachment\n key={previewModalKey}\n code={currentFileContent?.content}\n fileName={currentFileContent?.name}\n isModalOpen={isPreviewModalOpen}\n secondaryActionButtonText=\"Close\"\n modalFooterClassName={classes.modalFooter}\n onEdit={() => {\n setIsPreviewModalOpen(false);\n setIsEditModalOpen(true);\n }}\n onDismiss={() => {\n setCurrentFileContent(undefined);\n setIsPreviewModalOpen(false);\n }}\n handleModalToggle={() => setIsPreviewModalOpen(false)}\n displayMode={ChatbotDisplayMode.fullscreen}\n />\n <AttachmentEdit\n key={currentFileContent?.content}\n code={currentFileContent?.content}\n fileName={currentFileContent?.name}\n isModalOpen={isEditModalOpen}\n modalFooterClassName={classes.modalFooter}\n onSave={(_, content) => {\n setCurrentFileContent({\n ...currentFileContent,\n content,\n });\n setFileContents(prev => {\n const existingIndex = prev.findIndex(\n f => f.name === currentFileContent?.name,\n );\n\n if (existingIndex !== -1) {\n // Update the existing file's content\n const updated = [...prev];\n updated[existingIndex] = {\n ...updated[existingIndex],\n content: content as string,\n };\n return updated;\n }\n\n // File doesn't exist, add a new one\n return [\n ...prev,\n {\n name: currentFileContent?.name,\n type: currentFileContent?.type,\n content: content as string,\n },\n ];\n });\n\n setPreviewModalKey(prev => prev + 1);\n setIsEditModalOpen(false);\n setIsPreviewModalOpen(true);\n }}\n onCancel={() => setCurrentFileContent(undefined)}\n handleModalToggle={() => setIsEditModalOpen(false)}\n displayMode={ChatbotDisplayMode.fullscreen}\n />\n </>\n );\n};\n\nexport default Attachment;\n"],"names":["React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AAAA;AAAA,GAEpC,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"Attachment.esm.js","sources":["../../src/components/Attachment.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { makeStyles } from '@material-ui/core';\nimport {\n AttachmentEdit,\n ChatbotDisplayMode,\n PreviewAttachment,\n} from '@patternfly/chatbot';\n\nimport { useTranslation } from '../hooks/useTranslation';\nimport { useFileAttachmentContext } from './AttachmentContext';\n\nconst useStyles = makeStyles(() => ({\n modalFooter: {\n '&>button': {\n width: '12% !important',\n },\n },\n}));\nconst Attachment = () => {\n const {\n currentFileContent,\n setFileContents,\n modalState,\n setCurrentFileContent,\n } = useFileAttachmentContext();\n const classes = useStyles();\n const { t } = useTranslation();\n\n if (!currentFileContent) {\n return null;\n }\n const {\n previewModalKey,\n isPreviewModalOpen,\n isEditModalOpen,\n setPreviewModalKey,\n setIsEditModalOpen,\n setIsPreviewModalOpen,\n } = modalState;\n\n return (\n <>\n <PreviewAttachment\n key={previewModalKey}\n code={currentFileContent?.content}\n fileName={currentFileContent?.name}\n isModalOpen={isPreviewModalOpen}\n secondaryActionButtonText={t('modal.close')}\n primaryActionButtonText={t('modal.edit')}\n title={t('modal.title.preview')}\n modalFooterClassName={classes.modalFooter}\n onEdit={() => {\n setIsPreviewModalOpen(false);\n setIsEditModalOpen(true);\n }}\n onDismiss={() => {\n setCurrentFileContent(undefined);\n setIsPreviewModalOpen(false);\n }}\n handleModalToggle={() => setIsPreviewModalOpen(false)}\n displayMode={ChatbotDisplayMode.fullscreen}\n />\n <AttachmentEdit\n key={currentFileContent?.content}\n code={currentFileContent?.content}\n fileName={currentFileContent?.name}\n isModalOpen={isEditModalOpen}\n title={t('modal.title.edit')}\n secondaryActionButtonText={t('modal.cancel')}\n primaryActionButtonText={t('modal.save')}\n modalFooterClassName={classes.modalFooter}\n onSave={(_, content) => {\n setCurrentFileContent({\n ...currentFileContent,\n content,\n });\n setFileContents(prev => {\n const existingIndex = prev.findIndex(\n f => f.name === currentFileContent?.name,\n );\n\n if (existingIndex !== -1) {\n // Update the existing file's content\n const updated = [...prev];\n updated[existingIndex] = {\n ...updated[existingIndex],\n content: content as string,\n };\n return updated;\n }\n\n // File doesn't exist, add a new one\n return [\n ...prev,\n {\n name: currentFileContent?.name,\n type: currentFileContent?.type,\n content: content as string,\n },\n ];\n });\n\n setPreviewModalKey(prev => prev + 1);\n setIsEditModalOpen(false);\n setIsPreviewModalOpen(true);\n }}\n onCancel={() => setCurrentFileContent(undefined)}\n handleModalToggle={() => setIsEditModalOpen(false)}\n displayMode={ChatbotDisplayMode.fullscreen}\n />\n </>\n );\n};\n\nexport default Attachment;\n"],"names":[],"mappings":";;;;;;AA0BA,MAAM,SAAA,GAAY,WAAW,OAAO;AAAA,EAClC,WAAa,EAAA;AAAA,IACX,UAAY,EAAA;AAAA,MACV,KAAO,EAAA;AAAA;AACT;AAEJ,CAAE,CAAA,CAAA;AACF,MAAM,aAAa,MAAM;AACvB,EAAM,MAAA;AAAA,IACJ,kBAAA;AAAA,IACA,eAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,MACE,wBAAyB,EAAA;AAC7B,EAAA,MAAM,UAAU,SAAU,EAAA;AAC1B,EAAM,MAAA,EAAE,CAAE,EAAA,GAAI,cAAe,EAAA;AAE7B,EAAA,IAAI,CAAC,kBAAoB,EAAA;AACvB,IAAO,OAAA,IAAA;AAAA;AAET,EAAM,MAAA;AAAA,IACJ,eAAA;AAAA,IACA,kBAAA;AAAA,IACA,eAAA;AAAA,IACA,kBAAA;AAAA,IACA,kB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AAA;AAAA,YACH;AAAA,WACD,CAAA;AACD,UAAA,eAAA,CAAgB,CAAQ,IAAA,KAAA;AACtB,YAAA,MAAM,gBAAgB,IAAK,CAAA,SAAA;AAAA,cACzB,CAAA,CAAA,KAAK,CAAE,CAAA,IAAA,KAAS,kBAAoB,EAAA;AAAA,aACtC;AAEA,YAAA,IAAI,kBAAkB,EAAI,EAAA;AAExB,cAAM,MAAA,OAAA,GAAU,CAAC,GAAG,IAAI,CAAA;AACxB,cAAA,OAAA,CAAQ,aAAa,CAAI,GAAA;AAAA,gBACvB,GAAG,QAAQ,aAAa,CAAA;AAAA,gBACxB;AAAA,eACF;AACA,cAAO,OAAA,OAAA;AAAA;AAIT,YAAO,OAAA;AAAA,cACL,GAAG,IAAA;AAAA,cACH;AAAA,gBACE,MAAM,kBAAoB,EAAA,IAAA;AAAA,gBAC1B,MAAM,kBAAoB,EAAA,IAAA;AAAA,gBAC1B;AAAA;AACF,aACF;AAAA,WACD,CAAA;AAED,UAAmB,kBAAA,CAAA,CAAA,IAAA,KAAQ,OAAO,CAAC,CAAA;AACnC,UAAA,kBAAA,CAAmB,KAAK,CAAA;AACxB,UAAA,qBAAA,CAAsB,IAAI,CAAA;AAAA,SAC5B;AAAA,QACA,QAAA,EAAU,MAAM,qBAAA,CAAsB,SAAS,CAAA;AAAA,QAC/C,iBAAA,EAAmB,MAAM,kBAAA,CAAmB,KAAK,CAAA;AAAA,QACjD,aAAa,kBAAmB,CAAA;AAAA,OAAA;AAAA,MA7C3B,kBAAoB,EAAA;AAAA;AA8C3B,GACF,EAAA,CAAA;AAEJ;;;;"}
@@ -1,46 +1,54 @@
1
- import React__default from 'react';
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { createContext, useState, useContext } from 'react';
3
+ import { useTranslation } from '../hooks/useTranslation.esm.js';
2
4
  import { isSupportedFileType, readFileAsText } from '../utils/attachment-utils.esm.js';
3
5
 
4
- const FileAttachmentContext = React__default.createContext(null);
6
+ const FileAttachmentContext = createContext(null);
5
7
  const FileAttachmentContextProvider = ({ children }) => {
6
- const [currentFileContent, setCurrentFileContent] = React__default.useState();
7
- const [isLoadingFile, setIsLoadingFile] = React__default.useState({});
8
- const [previewModalKey, setPreviewModalKey] = React__default.useState(0);
9
- const [showAlert, setShowAlert] = React__default.useState(false);
10
- const [uploadError, setUploadError] = React__default.useState({
8
+ const { t } = useTranslation();
9
+ const [currentFileContent, setCurrentFileContent] = useState();
10
+ const [isLoadingFile, setIsLoadingFile] = useState(
11
+ {}
12
+ );
13
+ const [previewModalKey, setPreviewModalKey] = useState(0);
14
+ const [showAlert, setShowAlert] = useState(false);
15
+ const [uploadError, setUploadError] = useState({
11
16
  message: null
12
17
  });
13
- const [fileContents, setFileContents] = React__default.useState([]);
14
- const [isPreviewModalOpen, setIsPreviewModalOpen] = React__default.useState(false);
15
- const [isEditModalOpen, setIsEditModalOpen] = React__default.useState(false);
18
+ const [fileContents, setFileContents] = useState([]);
19
+ const [isPreviewModalOpen, setIsPreviewModalOpen] = useState(false);
20
+ const [isEditModalOpen, setIsEditModalOpen] = useState(false);
16
21
  const handleFileUpload = (fileArr) => {
17
22
  const existingFile = fileContents.find(
18
23
  (file) => file.name === fileArr[0].name
19
24
  );
20
25
  if (existingFile) {
21
26
  setShowAlert(true);
22
- setUploadError({ type: "info", message: "File already exists." });
27
+ setUploadError({
28
+ type: "info",
29
+ message: t("file.upload.error.alreadyExists")
30
+ });
23
31
  return;
24
32
  }
25
33
  setIsLoadingFile({ [fileArr[0].name]: true });
26
34
  if (fileArr.length > 1) {
27
35
  setShowAlert(true);
28
36
  setUploadError({
29
- message: "Uploaded more than one file."
37
+ message: t("file.upload.error.multipleFiles")
30
38
  });
31
39
  return;
32
40
  }
33
41
  if (!isSupportedFileType(fileArr[0])) {
34
42
  setShowAlert(true);
35
43
  setUploadError({
36
- message: "Unsupported file type. Supported types are: .txt, .yaml, .json and .xml."
44
+ message: t("file.upload.error.unsupportedType")
37
45
  });
38
46
  return;
39
47
  }
40
48
  if (fileArr[0].size > 25e6) {
41
49
  setShowAlert(true);
42
50
  setUploadError({
43
- message: "Your file size is too large. Please ensure that your file is less than 25 MB."
51
+ message: t("file.upload.error.fileTooLarge")
44
52
  });
45
53
  return;
46
54
  }
@@ -58,7 +66,9 @@ const FileAttachmentContextProvider = ({ children }) => {
58
66
  setIsLoadingFile({ [fileArr[0].name]: false });
59
67
  }).catch((error) => {
60
68
  setUploadError({
61
- message: `Failed to read file: ${error.message}`
69
+ message: t("file.upload.error.readFailed", {
70
+ errorMessage: error.message
71
+ })
62
72
  });
63
73
  });
64
74
  };
@@ -70,7 +80,7 @@ const FileAttachmentContextProvider = ({ children }) => {
70
80
  previewModalKey,
71
81
  setPreviewModalKey
72
82
  };
73
- return /* @__PURE__ */ React__default.createElement(
83
+ return /* @__PURE__ */ jsx(
74
84
  FileAttachmentContext.Provider,
75
85
  {
76
86
  value: {
@@ -85,19 +95,18 @@ const FileAttachmentContextProvider = ({ children }) => {
85
95
  setUploadError,
86
96
  currentFileContent,
87
97
  setCurrentFileContent
88
- }
89
- },
90
- children
98
+ },
99
+ children
100
+ }
91
101
  );
92
102
  };
93
103
  const useFileAttachmentContext = () => {
94
- const context = React__default.useContext(
104
+ const { t } = useTranslation();
105
+ const context = useContext(
95
106
  FileAttachmentContext
96
107
  );
97
108
  if (context === null) {
98
- throw new Error(
99
- "useFileAttachmentContext must be within a FileAttachmentContextProvider"
100
- );
109
+ throw new Error(t("error.context.fileAttachment"));
101
110
  }
102
111
  return context;
103
112
  };
@@ -1 +1 @@
1
- {"version":3,"file":"AttachmentContext.esm.js","sources":["../../src/components/AttachmentContext.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport { FileContent } from '../types';\nimport { isSupportedFileType, readFileAsText } from '../utils/attachment-utils';\n\ntype UploadError = { type?: 'info' | 'danger'; message: string | null };\ninterface FileAttachmentContextType {\n showAlert: boolean;\n uploadError: UploadError;\n fileContents: FileContent[];\n isLoadingFile: Record<string, boolean>;\n handleFileUpload: (files: File[]) => void;\n setFileContents: React.Dispatch<React.SetStateAction<FileContent[]>>;\n setUploadError: React.Dispatch<React.SetStateAction<UploadError>>;\n setShowAlert: React.Dispatch<React.SetStateAction<boolean>>;\n currentFileContent?: FileContent;\n setCurrentFileContent: React.Dispatch<\n React.SetStateAction<FileContent | undefined>\n >;\n modalState: {\n previewModalKey: number;\n setPreviewModalKey: React.Dispatch<React.SetStateAction<number>>;\n isPreviewModalOpen: boolean;\n setIsPreviewModalOpen: React.Dispatch<React.SetStateAction<boolean>>;\n isEditModalOpen: boolean;\n setIsEditModalOpen: React.Dispatch<React.SetStateAction<boolean>>;\n };\n}\n\nexport const FileAttachmentContext =\n React.createContext<FileAttachmentContextType | null>(null);\n\nconst FileAttachmentContextProvider: React.FC<{\n children: React.ReactNode;\n}> = ({ children }) => {\n const [currentFileContent, setCurrentFileContent] = React.useState<\n FileContent | undefined\n >();\n const [isLoadingFile, setIsLoadingFile] = React.useState<\n Record<string, boolean>\n >({});\n const [previewModalKey, setPreviewModalKey] = React.useState<number>(0);\n const [showAlert, setShowAlert] = React.useState<boolean>(false);\n const [uploadError, setUploadError] = React.useState<UploadError>({\n message: null,\n });\n const [fileContents, setFileContents] = React.useState<FileContent[]>([]);\n const [isPreviewModalOpen, setIsPreviewModalOpen] =\n React.useState<boolean>(false);\n const [isEditModalOpen, setIsEditModalOpen] = React.useState<boolean>(false);\n const handleFileUpload = (fileArr: File[]) => {\n const existingFile = fileContents.find(\n file => file.name === fileArr[0].name,\n );\n if (existingFile) {\n setShowAlert(true);\n setUploadError({ type: 'info', message: 'File already exists.' });\n return;\n }\n\n setIsLoadingFile({ [fileArr[0].name]: true });\n\n if (fileArr.length > 1) {\n setShowAlert(true);\n setUploadError({\n message: 'Uploaded more than one file.',\n });\n return;\n }\n if (!isSupportedFileType(fileArr[0])) {\n setShowAlert(true);\n setUploadError({\n message:\n 'Unsupported file type. Supported types are: .txt, .yaml, .json and .xml.',\n });\n return;\n }\n\n // this is 25MB in bytes; size is in bytes\n if (fileArr[0].size > 25000000) {\n setShowAlert(true);\n setUploadError({\n message:\n 'Your file size is too large. Please ensure that your file is less than 25 MB.',\n });\n return;\n }\n\n readFileAsText(fileArr[0])\n .then(data => {\n setFileContents(prev => [\n ...prev,\n {\n name: fileArr[0].name,\n type: fileArr[0].type,\n content: data as string,\n },\n ]);\n setShowAlert(false);\n setUploadError({ message: null });\n setIsLoadingFile({ [fileArr[0].name]: false });\n })\n .catch((error: DOMException) => {\n setUploadError({\n message: `Failed to read file: ${error.message}`,\n });\n });\n };\n\n const modalState = {\n isPreviewModalOpen,\n setIsPreviewModalOpen,\n isEditModalOpen,\n setIsEditModalOpen,\n previewModalKey,\n setPreviewModalKey,\n };\n return (\n <FileAttachmentContext.Provider\n value={{\n modalState,\n fileContents,\n setFileContents,\n handleFileUpload,\n isLoadingFile,\n showAlert,\n setShowAlert,\n uploadError,\n setUploadError,\n currentFileContent,\n setCurrentFileContent,\n }}\n >\n {children}\n </FileAttachmentContext.Provider>\n );\n};\n\nexport default FileAttachmentContextProvider;\n\nexport const useFileAttachmentContext = (): FileAttachmentContextType => {\n const context = React.useContext<FileAttachmentContextType | null>(\n FileAttachmentContext,\n );\n\n if (context === null) {\n throw new Error(\n 'useFileAttachmentContext must be within a FileAttachmentContextProvider',\n );\n }\n\n return context;\n};\n"],"names":["React"],"mappings":";;;AA4Ca,MAAA,qBAAA,GACXA,cAAM,CAAA,aAAA,CAAgD,IAAI;AAE5D,MAAM,6BAED,GAAA,CAAC,EAAE,QAAA,EAAe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Aa,GAAA;AAAA,IACjB,kBAAA;AAAA,IACA,qBAAA;AAAA,IACA,eAAA;AAAA,IACA,kBAAA;AAAA,IACA,eAAA;AAAA,IACA;AAAA,GACF;AACA,EACE,uBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,qBAAsB,CAAA,QAAA;AAAA,IAAtB;AAAA,MACC,KAAO,EAAA;AAAA,QACL,UAAA;AAAA,QACA,YAAA;AAAA,QACA,eAAA;AAAA,QACA,gBAAA;AAAA,QACA,aAAA;AAAA,QACA,SAAA;AAAA,QACA,YAAA;AAAA,QACA,WAAA;AAAA,QACA,cAAA;AAAA,QACA,kBAAA;AAAA,QACA;AAAA;AACF,KAAA;AAAA,IAEC;AAAA,GACH;AAEJ;AAIO,MAAM,2BAA2B,MAAiC;AACvE,EAAA,MAAM,UAAUA,cAAM,CAAA,UAAA;AAAA,IACpB;AAAA,GACF;AAEA,EAAA,IAAI,YAAY,IAAM,EAAA;AACpB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AAGF,EAAO,OAAA,OAAA;AACT;;;;"}
1
+ {"version":3,"file":"AttachmentContext.esm.js","sources":["../../src/components/AttachmentContext.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createContext,\n Dispatch,\n FC,\n ReactNode,\n SetStateAction,\n useContext,\n useState,\n} from 'react';\n\nimport { useTranslation } from '../hooks/useTranslation';\nimport { FileContent } from '../types';\nimport { isSupportedFileType, readFileAsText } from '../utils/attachment-utils';\n\ntype UploadError = { type?: 'info' | 'danger'; message: string | null };\ninterface FileAttachmentContextType {\n showAlert: boolean;\n uploadError: UploadError;\n fileContents: FileContent[];\n isLoadingFile: Record<string, boolean>;\n handleFileUpload: (files: File[]) => void;\n setFileContents: Dispatch<SetStateAction<FileContent[]>>;\n setUploadError: Dispatch<SetStateAction<UploadError>>;\n setShowAlert: Dispatch<SetStateAction<boolean>>;\n currentFileContent?: FileContent;\n setCurrentFileContent: Dispatch<SetStateAction<FileContent | undefined>>;\n modalState: {\n previewModalKey: number;\n setPreviewModalKey: Dispatch<SetStateAction<number>>;\n isPreviewModalOpen: boolean;\n setIsPreviewModalOpen: Dispatch<SetStateAction<boolean>>;\n isEditModalOpen: boolean;\n setIsEditModalOpen: Dispatch<SetStateAction<boolean>>;\n };\n}\n\nexport const FileAttachmentContext =\n createContext<FileAttachmentContextType | null>(null);\n\nconst FileAttachmentContextProvider: FC<{\n children: ReactNode;\n}> = ({ children }) => {\n const { t } = useTranslation();\n const [currentFileContent, setCurrentFileContent] = useState<\n FileContent | undefined\n >();\n const [isLoadingFile, setIsLoadingFile] = useState<Record<string, boolean>>(\n {},\n );\n const [previewModalKey, setPreviewModalKey] = useState<number>(0);\n const [showAlert, setShowAlert] = useState<boolean>(false);\n const [uploadError, setUploadError] = useState<UploadError>({\n message: null,\n });\n const [fileContents, setFileContents] = useState<FileContent[]>([]);\n const [isPreviewModalOpen, setIsPreviewModalOpen] = useState<boolean>(false);\n const [isEditModalOpen, setIsEditModalOpen] = useState<boolean>(false);\n const handleFileUpload = (fileArr: File[]) => {\n const existingFile = fileContents.find(\n file => file.name === fileArr[0].name,\n );\n if (existingFile) {\n setShowAlert(true);\n setUploadError({\n type: 'info',\n message: t('file.upload.error.alreadyExists'),\n });\n return;\n }\n\n setIsLoadingFile({ [fileArr[0].name]: true });\n\n if (fileArr.length > 1) {\n setShowAlert(true);\n setUploadError({\n message: t('file.upload.error.multipleFiles'),\n });\n return;\n }\n if (!isSupportedFileType(fileArr[0])) {\n setShowAlert(true);\n setUploadError({\n message: t('file.upload.error.unsupportedType'),\n });\n return;\n }\n\n // this is 25MB in bytes; size is in bytes\n if (fileArr[0].size > 25000000) {\n setShowAlert(true);\n setUploadError({\n message: t('file.upload.error.fileTooLarge'),\n });\n return;\n }\n\n readFileAsText(fileArr[0])\n .then(data => {\n setFileContents(prev => [\n ...prev,\n {\n name: fileArr[0].name,\n type: fileArr[0].type,\n content: data as string,\n },\n ]);\n setShowAlert(false);\n setUploadError({ message: null });\n setIsLoadingFile({ [fileArr[0].name]: false });\n })\n .catch((error: DOMException) => {\n setUploadError({\n message: t('file.upload.error.readFailed' as any, {\n errorMessage: error.message,\n }),\n });\n });\n };\n\n const modalState = {\n isPreviewModalOpen,\n setIsPreviewModalOpen,\n isEditModalOpen,\n setIsEditModalOpen,\n previewModalKey,\n setPreviewModalKey,\n };\n return (\n <FileAttachmentContext.Provider\n value={{\n modalState,\n fileContents,\n setFileContents,\n handleFileUpload,\n isLoadingFile,\n showAlert,\n setShowAlert,\n uploadError,\n setUploadError,\n currentFileContent,\n setCurrentFileContent,\n }}\n >\n {children}\n </FileAttachmentContext.Provider>\n );\n};\n\nexport default FileAttachmentContextProvider;\n\nexport const useFileAttachmentContext = (): FileAttachmentContextType => {\n const { t } = useTranslation();\n const context = useContext<FileAttachmentContextType | null>(\n FileAttachmentContext,\n );\n\n if (context === null) {\n // The error message is developer-facing and typically not translated\n throw new Error(t('error.context.fileAttachment'));\n }\n\n return context;\n};\n"],"names":[],"mappings":";;;;;AAoDa,MAAA,qBAAA,GACX,cAAgD,IAAI;AAEtD,MAAM,6BAED,GAAA,CAAC,EAAE,QAAA,EAAe,KAAA;AACrB,EAAM,MAAA,EAAE,CAAE,EAAA,GAAI,cAAe,EAAA;AAC7B,EAAA,MAAM,CAAC,kBAAA,EAAoB,qBAAqB,CAAA,GAAI,QAElD,EAAA;AACF,EAAM,MAAA,CAAC,aAAe,EAAA,gBAAgB,CAAI,GAAA,QAAA;AAAA,IACxC;AAAC,GACH;AACA,EAAA,MAAM,C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A,QAAA;AAAA,IAAtB;AAAA,MACC,KAAO,EAAA;AAAA,QACL,UAAA;AAAA,QACA,YAAA;AAAA,QACA,eAAA;AAAA,QACA,gBAAA;AAAA,QACA,aAAA;AAAA,QACA,SAAA;AAAA,QACA,YAAA;AAAA,QACA,WAAA;AAAA,QACA,cAAA;AAAA,QACA,kBAAA;AAAA,QACA;AAAA,OACF;AAAA,MAEC;AAAA;AAAA,GACH;AAEJ;AAIO,MAAM,2BAA2B,MAAiC;AACvE,EAAM,MAAA,EAAE,CAAE,EAAA,GAAI,cAAe,EAAA;AAC7B,EAAA,MAAM,OAAU,GAAA,UAAA;AAAA,IACd;AAAA,GACF;AAEA,EAAA,IAAI,YAAY,IAAM,EAAA;AAEpB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAE,CAAA,8BAA8B,CAAC,CAAA;AAAA;AAGnD,EAAO,OAAA,OAAA;AACT;;;;"}
@@ -1,24 +1,33 @@
1
- import React__default from 'react';
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { Modal, ModalVariant, ModalHeader, ModalBody, ModalFooter, Button } from '@patternfly/react-core';
3
+ import { useTranslation } from '../hooks/useTranslation.esm.js';
3
4
 
4
5
  const DeleteModal = ({
5
6
  isOpen,
6
7
  onClose,
7
8
  onConfirm
8
- }) => /* @__PURE__ */ React__default.createElement(
9
- Modal,
10
- {
11
- variant: ModalVariant.small,
12
- isOpen,
13
- onClose,
14
- ouiaId: "DeleteModal",
15
- "aria-labelledby": "delete-modal",
16
- "aria-describedby": "delete-modal-confiramtion"
17
- },
18
- /* @__PURE__ */ React__default.createElement(ModalHeader, { title: "Delete chat?" }),
19
- /* @__PURE__ */ React__default.createElement(ModalBody, { id: "delete-modal-body-confirmation" }, "You'll no longer see this chat here. This will also delete related activity like prompts, responses, and feedback from your Lightspeed Activity."),
20
- /* @__PURE__ */ React__default.createElement(ModalFooter, null, /* @__PURE__ */ React__default.createElement(Button, { key: "confirm", variant: "danger", onClick: onConfirm }, "Delete"), /* @__PURE__ */ React__default.createElement(Button, { key: "cancel", variant: "link", onClick: onClose }, "Cancel"))
21
- );
9
+ }) => {
10
+ const { t } = useTranslation();
11
+ return /* @__PURE__ */ jsxs(
12
+ Modal,
13
+ {
14
+ variant: ModalVariant.small,
15
+ isOpen,
16
+ onClose,
17
+ ouiaId: "DeleteModal",
18
+ "aria-labelledby": "delete-modal",
19
+ "aria-describedby": "delete-modal-confiramtion",
20
+ children: [
21
+ /* @__PURE__ */ jsx(ModalHeader, { title: t("conversation.history.confirm.title") }),
22
+ /* @__PURE__ */ jsx(ModalBody, { id: "delete-modal-body-confirmation", children: t("conversation.history.confirm.message") }),
23
+ /* @__PURE__ */ jsxs(ModalFooter, { children: [
24
+ /* @__PURE__ */ jsx(Button, { variant: "danger", onClick: onConfirm, children: t("conversation.history.confirm.delete") }, "confirm"),
25
+ /* @__PURE__ */ jsx(Button, { variant: "link", onClick: onClose, children: t("common.cancel") }, "cancel")
26
+ ] })
27
+ ]
28
+ }
29
+ );
30
+ };
22
31
 
23
32
  export { DeleteModal };
24
33
  //# sourceMappingURL=DeleteModal.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DeleteModal.esm.js","sources":["../../src/components/DeleteModal.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\n\nimport {\n Button,\n Modal,\n ModalBody,\n ModalFooter,\n ModalHeader,\n ModalVariant,\n} from '@patternfly/react-core';\n\nexport const DeleteModal = ({\n isOpen,\n onClose,\n onConfirm,\n}: {\n isOpen: boolean;\n onClose: () => void;\n onConfirm: () => void;\n}) => (\n <Modal\n variant={ModalVariant.small}\n isOpen={isOpen}\n onClose={onClose}\n ouiaId=\"DeleteModal\"\n aria-labelledby=\"delete-modal\"\n aria-describedby=\"delete-modal-confiramtion\"\n >\n <ModalHeader title=\"Delete chat?\" />\n <ModalBody id=\"delete-modal-body-confirmation\">\n You'll no longer see this chat here. This will also delete related\n activity like prompts, responses, and feedback from your Lightspeed\n Activity.\n </ModalBody>\n <ModalFooter>\n <Button key=\"confirm\" variant=\"danger\" onClick={onConfirm}>\n Delete\n </Button>\n <Button key=\"cancel\" variant=\"link\" onClick={onClose}>\n Cancel\n </Button>\n </ModalFooter>\n </Modal>\n);\n"],"names":["React"],"mappings":";;;AA2BO,MAAM,cAAc,CAAC;AAAA,EAC1B,MAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAKE,qBAAAA,cAAA,CAAA,aAAA;AAAA,EAAC,KAAA;AAAA,EAAA;AAAA,IACC,SAAS,YAAa,CAAA,KAAA;AAAA,IACtB,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAO,EAAA,aAAA;AAAA,IACP,iBAAgB,EAAA,cAAA;AAAA,IAChB,kBAAiB,EAAA;AAAA,GAAA;AAAA,kBAEjBA,cAAA,CAAA,aAAA,CAAC,WAAY,EAAA,EAAA,KAAA,EAAM,cAAe,EAAA,CAAA;AAAA,kBACjCA,cAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAU,EAAG,EAAA,gCAAA,EAAA,EAAiC,kJAI/C,CAAA;AAAA,kBACAA,cAAA,CAAA,aAAA,CAAC,mCACEA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAO,KAAI,SAAU,EAAA,OAAA,EAAQ,UAAS,OAAS,EAAA,SAAA,EAAA,EAAW,QAE3D,CACA,kBAAAA,cAAA,CAAA,aAAA,CAAC,UAAO,GAAI,EAAA,QAAA,EAAS,SAAQ,MAAO,EAAA,OAAA,EAAS,OAAS,EAAA,EAAA,QAEtD,CACF;AACF;;;;"}
1
+ {"version":3,"file":"DeleteModal.esm.js","sources":["../../src/components/DeleteModal.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n Button,\n Modal,\n ModalBody,\n ModalFooter,\n ModalHeader,\n ModalVariant,\n} from '@patternfly/react-core';\n\nimport { useTranslation } from '../hooks/useTranslation';\n\nexport const DeleteModal = ({\n isOpen,\n onClose,\n onConfirm,\n}: {\n isOpen: boolean;\n onClose: () => void;\n onConfirm: () => void;\n}) => {\n const { t } = useTranslation();\n\n return (\n <Modal\n variant={ModalVariant.small}\n isOpen={isOpen}\n onClose={onClose}\n ouiaId=\"DeleteModal\"\n aria-labelledby=\"delete-modal\"\n aria-describedby=\"delete-modal-confiramtion\"\n >\n <ModalHeader title={t('conversation.history.confirm.title')} />\n <ModalBody id=\"delete-modal-body-confirmation\">\n {t('conversation.history.confirm.message')}\n </ModalBody>\n <ModalFooter>\n <Button key=\"confirm\" variant=\"danger\" onClick={onConfirm}>\n {t('conversation.history.confirm.delete')}\n </Button>\n <Button key=\"cancel\" variant=\"link\" onClick={onClose}>\n {t('common.cancel')}\n </Button>\n </ModalFooter>\n </Modal>\n );\n};\n"],"names":[],"mappings":";;;;AA2BO,MAAM,cAAc,CAAC;AAAA,EAC1B,MAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAIM,KAAA;AACJ,EAAM,MAAA,EAAE,CAAE,EAAA,GAAI,cAAe,EAAA;AAE7B,EACE,uBAAA,IAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,SAAS,YAAa,CAAA,KAAA;AAAA,MACtB,MAAA;AAAA,MACA,OAAA;AAAA,MACA,MAAO,EAAA,aAAA;AAAA,MACP,iBAAgB,EAAA,cAAA;AAAA,MAChB,kBAAiB,EAAA,2BAAA;AAAA,MAEjB,QAAA,EAAA;AAAA,wBAAA,GAAA,CAAC,WAAY,EAAA,EAAA,KAAA,EAAO,CAAE,CAAA,oCAAoC,CAAG,EAAA,CAAA;AAAA,4BAC5D,SAAU,EAAA,EAAA,EAAA,EAAG,gCACX,EAAA,QAAA,EAAA,CAAA,CAAE,sCAAsC,CAC3C,EAAA,CAAA;AAAA,6BACC,WACC,EAAA,EAAA,QAAA,EAAA;AAAA,0BAAC,GAAA,CAAA,MAAA,EAAA,EAAqB,SAAQ,QAAS,EAAA,OAAA,EAAS,WAC7C,QAAE,EAAA,CAAA,CAAA,qCAAqC,KAD9B,SAEZ,CAAA;AAAA,0BACA,GAAA,CAAC,UAAoB,OAAQ,EAAA,MAAA,EAAO,SAAS,OAC1C,EAAA,QAAA,EAAA,CAAA,CAAE,eAAe,CAAA,EAAA,EADR,QAEZ;AAAA,SACF,EAAA;AAAA;AAAA;AAAA,GACF;AAEJ;;;;"}
@@ -1,4 +1,4 @@
1
- import React__default from 'react';
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
2
  import { Divider } from '@material-ui/core';
3
3
  import { FileDetailsLabel } from '@patternfly/chatbot';
4
4
  import { useFileAttachmentContext } from './AttachmentContext.esm.js';
@@ -28,18 +28,21 @@ const FilePreview = () => {
28
28
  (prevContents) => prevContents.filter((_, index) => index !== indexToRemove)
29
29
  );
30
30
  };
31
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, fileContents.length > 0 && /* @__PURE__ */ React__default.createElement(Divider, null), fileContents && /* @__PURE__ */ React__default.createElement("div", { style: { display: "flex", gap: "10px" } }, fileContents.map((file, index) => /* @__PURE__ */ React__default.createElement(
32
- FileDetailsLabel,
33
- {
34
- key: index,
35
- fileName: file.name,
36
- isLoading: isLoadingFile[file.name],
37
- onClick: onAttachmentClick,
38
- onClose: () => {
39
- removeFile(index);
40
- }
41
- }
42
- ))));
31
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
32
+ fileContents.length > 0 && /* @__PURE__ */ jsx(Divider, {}),
33
+ fileContents && /* @__PURE__ */ jsx("div", { style: { display: "flex", gap: "10px" }, children: fileContents.map((file, index) => /* @__PURE__ */ jsx(
34
+ FileDetailsLabel,
35
+ {
36
+ fileName: file.name,
37
+ isLoading: isLoadingFile[file.name],
38
+ onClick: onAttachmentClick,
39
+ onClose: () => {
40
+ removeFile(index);
41
+ }
42
+ },
43
+ index
44
+ )) })
45
+ ] });
43
46
  };
44
47
 
45
48
  export { FilePreview as default };
@@ -1 +1 @@
1
- {"version":3,"file":"FilePreview.esm.js","sources":["../../src/components/FilePreview.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport { Divider } from '@material-ui/core';\nimport { FileDetailsLabel } from '@patternfly/chatbot';\n\nimport { useFileAttachmentContext } from './AttachmentContext';\n\nconst FilePreview = () => {\n const {\n fileContents,\n isLoadingFile,\n modalState,\n setFileContents,\n setCurrentFileContent,\n } = useFileAttachmentContext();\n\n const { setIsEditModalOpen, setIsPreviewModalOpen, setPreviewModalKey } =\n modalState;\n\n const onAttachmentClick = (_: React.MouseEvent, name: string) => {\n const file = fileContents?.find(f => f.name === name);\n setCurrentFileContent({\n name,\n type: file?.type ?? 'text/plain',\n content: file?.content ?? '',\n });\n setPreviewModalKey(prev => prev + 1); // update key to re-render content\n setIsEditModalOpen(false);\n setIsPreviewModalOpen(true);\n };\n\n const removeFile = (indexToRemove: number) => {\n setFileContents(prevContents =>\n prevContents.filter((_, index) => index !== indexToRemove),\n );\n };\n\n return (\n <>\n {fileContents.length > 0 && <Divider />}\n {fileContents && (\n <div style={{ display: 'flex', gap: '10px' }}>\n {fileContents.map((file, index) => (\n <FileDetailsLabel\n key={index}\n fileName={file.name}\n isLoading={isLoadingFile[file.name]}\n onClick={onAttachmentClick}\n onClose={() => {\n removeFile(index);\n }}\n />\n ))}\n </div>\n )}\n </>\n );\n};\n\nexport default FilePreview;\n"],"names":["React"],"mappings":";;;;;AAsBA,MAAM,cAAc,MAAM;AACxB,EAAM,MAAA;AAAA,IACJ,YAAA;AAAA,IACA,aAAA;AAAA,IACA,UAAA;AAAA,IACA,eAAA;AAAA,IACA;AAAA,MACE,wBAAyB,EAAA;AAE7B,EAAA,MAAM,EAAE,kBAAA,EAAoB,qBAAuB,EAAA,kBAAA,EACjD,GAAA,UAAA;AAEF,EAAM,MAAA,iBAAA,GAAoB,CAAC,CAAA,EAAqB,IAAiB,KAAA;AAC/D,IAAA,MAAM,OAAO,YAAc,EAAA,IAAA,CAAK,CAAK,CAAA,KAAA,CAAA,CAAE,SAAS,IAAI,CAAA;AACpD,IAAsB,qBAAA,CAAA;AAAA,MACpB,IAAA;AAAA,MACA,IAAA,EAAM,MAAM,IAAQ,IAAA,YAAA;AAAA,MACpB,OAAA,EAAS,MAAM,OAAW,IAAA;AAAA,KAC3B,CAAA;AACD,IAAmB,kBAAA,CAAA,CAAA,IAAA,KAAQ,OAAO,CAAC,CAAA;AACnC,IAAA,kBAAA,CAAmB,KAAK,CAAA;AACxB,IAAA,qBAAA,CAAsB,IAAI,CAAA;AAAA,GAC5B;AAEA,EAAM,MAAA,UAAA,GAAa,CAAC,aAA0B,KAAA;AAC5C,IAAA,eAAA;AAAA,MAAgB,kBACd,YAAa,CAAA,MAAA,CAAO,CAAC,CAAG,EAAA,KAAA,KAAU,UAAU,aAAa;AAAA,KAC3D;AAAA,GACF;AAEA,EACE,uBAAAA,cAAA,CAAA,aAAA,CAAAA,cAAA,CAAA,QAAA,EAAA,IAAA,EACG,aAAa,MAAS,GAAA,CAAA,iDAAM,OAAQ,EAAA,IAAA,CAAA,EACpC,gCACEA,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAI,OAAO,EAAE,OAAA,EAAS,QAAQ,GAAK,EAAA,MAAA,MACjC,YAAa,CAAA,GAAA,CAAI,CAAC,IAAA,EAAM,KACvB,qBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,gBAAA;AAAA,IAAA;AAAA,MACC,GAAK,EAAA,KAAA;AAAA,MACL,UAAU,IAAK,CAAA,IAAA;AAAA,MACf,SAAA,EAAW,aAAc,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,MAClC,OAAS,EAAA,iBAAA;AAAA,MACT,SAAS,MAAM;AACb,QAAA,UAAA,CAAW,KAAK,CAAA;AAAA;AAClB;AAAA,GAEH,CACH,CAEJ,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"FilePreview.esm.js","sources":["../../src/components/FilePreview.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Divider } from '@material-ui/core';\nimport { FileDetailsLabel } from '@patternfly/chatbot';\n\nimport { useFileAttachmentContext } from './AttachmentContext';\n\nconst FilePreview = () => {\n const {\n fileContents,\n isLoadingFile,\n modalState,\n setFileContents,\n setCurrentFileContent,\n } = useFileAttachmentContext();\n\n const { setIsEditModalOpen, setIsPreviewModalOpen, setPreviewModalKey } =\n modalState;\n\n const onAttachmentClick = (_: React.MouseEvent, name: string) => {\n const file = fileContents?.find(f => f.name === name);\n setCurrentFileContent({\n name,\n type: file?.type ?? 'text/plain',\n content: file?.content ?? '',\n });\n setPreviewModalKey(prev => prev + 1); // update key to re-render content\n setIsEditModalOpen(false);\n setIsPreviewModalOpen(true);\n };\n\n const removeFile = (indexToRemove: number) => {\n setFileContents(prevContents =>\n prevContents.filter((_, index) => index !== indexToRemove),\n );\n };\n\n return (\n <>\n {fileContents.length > 0 && <Divider />}\n {fileContents && (\n <div style={{ display: 'flex', gap: '10px' }}>\n {fileContents.map((file, index) => (\n <FileDetailsLabel\n key={index}\n fileName={file.name}\n isLoading={isLoadingFile[file.name]}\n onClick={onAttachmentClick}\n onClose={() => {\n removeFile(index);\n }}\n />\n ))}\n </div>\n )}\n </>\n );\n};\n\nexport default FilePreview;\n"],"names":[],"mappings":";;;;;AAqBA,MAAM,cAAc,MAAM;AACxB,EAAM,MAAA;AAAA,IACJ,YAAA;AAAA,IACA,aAAA;AAAA,IACA,UAAA;AAAA,IACA,eAAA;AAAA,IACA;AAAA,MACE,wBAAyB,EAAA;AAE7B,EAAA,MAAM,EAAE,kBAAA,EAAoB,qBAAuB,EAAA,kBAAA,EACjD,GAAA,UAAA;AAEF,EAAM,MAAA,iBAAA,GAAoB,CAAC,CAAA,EAAqB,IAAiB,KAAA;AAC/D,IAAA,MAAM,OAAO,YAAc,EAAA,IAAA,CAAK,CAAK,CAAA,KAAA,CAAA,CAAE,SAAS,IAAI,CAAA;AACpD,IAAsB,qBAAA,CAAA;AAAA,MACpB,IAAA;AAAA,MACA,IAAA,EAAM,MAAM,IAAQ,IAAA,YAAA;AAAA,MACpB,OAAA,EAAS,MAAM,OAAW,IAAA;AAAA,KAC3B,CAAA;AACD,IAAmB,kBAAA,CAAA,CAAA,IAAA,KAAQ,OAAO,CAAC,CAAA;AACnC,IAAA,kBAAA,CAAmB,KAAK,CAAA;AACxB,IAAA,qBAAA,CAAsB,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