@red-hat-developer-hub/backstage-plugin-lightspeed 0.5.7 → 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.
- package/CHANGELOG.md +14 -0
- package/dist/components/Attachment.esm.js +71 -61
- package/dist/components/Attachment.esm.js.map +1 -1
- package/dist/components/AttachmentContext.esm.js +32 -23
- package/dist/components/AttachmentContext.esm.js.map +1 -1
- package/dist/components/DeleteModal.esm.js +24 -15
- package/dist/components/DeleteModal.esm.js.map +1 -1
- package/dist/components/FilePreview.esm.js +16 -13
- package/dist/components/FilePreview.esm.js.map +1 -1
- package/dist/components/LightSpeedChat.esm.js +172 -129
- package/dist/components/LightSpeedChat.esm.js.map +1 -1
- package/dist/components/LightspeedChatBox.esm.js +43 -34
- package/dist/components/LightspeedChatBox.esm.js.map +1 -1
- package/dist/components/LightspeedChatBoxHeader.esm.js +15 -12
- package/dist/components/LightspeedChatBoxHeader.esm.js.map +1 -1
- package/dist/components/LightspeedIcon.esm.js +11 -2
- package/dist/components/LightspeedIcon.esm.js.map +1 -1
- package/dist/components/LightspeedPage.esm.js +32 -26
- package/dist/components/LightspeedPage.esm.js.map +1 -1
- package/dist/components/PermissionRequiredIcon.esm.js +10 -2
- package/dist/components/PermissionRequiredIcon.esm.js.map +1 -1
- package/dist/components/PermissionRequiredState.esm.js +25 -11
- package/dist/components/PermissionRequiredState.esm.js.map +1 -1
- package/dist/components/Trans.esm.js +33 -0
- package/dist/components/Trans.esm.js.map +1 -0
- package/dist/const.esm.js +20 -43
- package/dist/const.esm.js.map +1 -1
- package/dist/hooks/useAutoScroll.esm.js +11 -11
- package/dist/hooks/useAutoScroll.esm.js.map +1 -1
- package/dist/hooks/useBufferedMessages.esm.js +5 -5
- package/dist/hooks/useBufferedMessages.esm.js.map +1 -1
- package/dist/hooks/useConversationMessages.esm.js +8 -8
- package/dist/hooks/useConversationMessages.esm.js.map +1 -1
- package/dist/hooks/useFeedbackActions.esm.js +47 -18
- package/dist/hooks/useFeedbackActions.esm.js.map +1 -1
- package/dist/hooks/useIsMobile.esm.js +3 -3
- package/dist/hooks/useIsMobile.esm.js.map +1 -1
- package/dist/hooks/useLastOpenedConversation.esm.js.map +1 -1
- package/dist/hooks/useTranslation.esm.js +7 -0
- package/dist/hooks/useTranslation.esm.js.map +1 -0
- package/dist/hooks/useWelcomePrompts.esm.js +21 -6
- package/dist/hooks/useWelcomePrompts.esm.js.map +1 -1
- package/dist/index.d.ts +11 -5
- package/dist/index.esm.js +1 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/translations/de.esm.js +128 -0
- package/dist/translations/de.esm.js.map +1 -0
- package/dist/translations/es.esm.js +128 -0
- package/dist/translations/es.esm.js.map +1 -0
- package/dist/translations/fr.esm.js +128 -0
- package/dist/translations/fr.esm.js.map +1 -0
- package/dist/translations/index.esm.js +14 -0
- package/dist/translations/index.esm.js.map +1 -0
- package/dist/translations/translationRef.esm.js +128 -0
- package/dist/translations/translationRef.esm.js.map +1 -0
- package/dist/types.esm.js.map +1 -1
- package/dist/utils/lightspeed-chatbox-utils.esm.js +24 -21
- package/dist/utils/lightspeed-chatbox-utils.esm.js.map +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
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
|
+
|
|
3
17
|
## 0.5.7
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
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__ */
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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 */\
|
|
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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CAAA;AAAA,YACpB,GAAG,kBAAA;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
|
|
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 =
|
|
6
|
+
const FileAttachmentContext = createContext(null);
|
|
5
7
|
const FileAttachmentContextProvider = ({ children }) => {
|
|
6
|
-
const
|
|
7
|
-
const [
|
|
8
|
-
const [
|
|
9
|
-
|
|
10
|
-
|
|
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] =
|
|
14
|
-
const [isPreviewModalOpen, setIsPreviewModalOpen] =
|
|
15
|
-
const [isEditModalOpen, setIsEditModalOpen] =
|
|
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({
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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:
|
|
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__ */
|
|
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
|
-
|
|
98
|
+
},
|
|
99
|
+
children
|
|
100
|
+
}
|
|
91
101
|
);
|
|
92
102
|
};
|
|
93
103
|
const useFileAttachmentContext = () => {
|
|
94
|
-
const
|
|
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
|
|
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,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAAiB,CAAC,CAAA;AAChE,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GA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AAA;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
|
|
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
|
-
}) =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
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
|
|
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__ */
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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 */\
|
|
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,IAAI,CAAA;AAAA,GAC5B;AAEA,EAAM,MAAA,UAAA,GAAa,CAAC,aAA0B,KAAA;AAC5C,IAAA,eAAA;AAAA,MAAgB,kBACd,YAAa,CAAA,MAAA,CAAO,CAAC,CAAG,E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