Skip to content

Commit 7e9cff1

Browse files
authored
fix(top-bar): fix bug in 'Download Resolved JSON/YAML' menu items (#4081)
Refs #4080
1 parent 701d58e commit 7e9cff1

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/plugins/top-bar/components/FileMenu/items/DownloadResolvedJSONMenuItemHandler.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const DownloadResolvedJSONMenuItemHandler = forwardRef(
1515
useImperativeHandle(ref, () => ({
1616
async downloadResolvedJSON() {
1717
const content = editorSelectors.selectContent();
18+
let dereferencedContent = content;
19+
const isContentJSON = editorSelectors.selectIsContentFormatJSON();
1820
const fileName = editorSelectors.selectInferFileNameFromContent();
1921
const fileExtension = '.json';
2022
const fileNameWithExtension = `${fileName}${fileExtension}`;
@@ -25,16 +27,20 @@ const DownloadResolvedJSONMenuItemHandler = forwardRef(
2527
setIsAlertDialogOpen(true);
2628
return;
2729
}
30+
dereferencedContent = dereferenceFSA.payload;
2831

29-
const convertFSA = await editorActions.convertContentToJSON(dereferenceFSA.payload);
30-
if (convertFSA.error) {
31-
alertDialogMessage.current = convertFSA.meta.errorMessage;
32-
setIsAlertDialogOpen(true);
33-
return;
32+
if (!isContentJSON) {
33+
const convertFSA = await editorActions.convertContentToJSON(dereferenceFSA.payload);
34+
if (convertFSA.error) {
35+
alertDialogMessage.current = convertFSA.meta.errorMessage;
36+
setIsAlertDialogOpen(true);
37+
return;
38+
}
39+
dereferencedContent = convertFSA.payload;
3440
}
3541

3642
const downloadFSA = await editorActions.downloadContent({
37-
content: convertFSA.payload,
43+
content: dereferencedContent,
3844
fileNameWithExtension,
3945
});
4046
if (downloadFSA.error) {
@@ -61,6 +67,7 @@ DownloadResolvedJSONMenuItemHandler.propTypes = {
6167
editorSelectors: PropTypes.shape({
6268
selectContent: PropTypes.func.isRequired,
6369
selectInferFileNameFromContent: PropTypes.func.isRequired,
70+
selectIsContentFormatJSON: PropTypes.func.isRequired,
6471
}).isRequired,
6572
editorActions: PropTypes.shape({
6673
dereferenceContent: PropTypes.func.isRequired,

src/plugins/top-bar/components/FileMenu/items/DownloadResolvedYAMLMenuItemHandler.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const DownloadResolvedYAMLMenuItemHandler = forwardRef(
1515
useImperativeHandle(ref, () => ({
1616
async downloadResolvedYAML() {
1717
const content = editorSelectors.selectContent();
18+
let dereferencedContent = content;
19+
const isContentYAML = editorSelectors.selectIsContentFormatYAML();
1820
const fileName = editorSelectors.selectInferFileNameFromContent();
1921
const fileExtension = '.yaml';
2022
const fileNameWithExtension = `${fileName}${fileExtension}`;
@@ -25,16 +27,20 @@ const DownloadResolvedYAMLMenuItemHandler = forwardRef(
2527
setIsAlertDialogOpen(true);
2628
return;
2729
}
30+
dereferencedContent = dereferenceFSA.payload;
2831

29-
const convertFSA = await editorActions.convertContentToYAML(dereferenceFSA.payload);
30-
if (convertFSA.error) {
31-
alertDialogMessage.current = convertFSA.meta.errorMessage;
32-
setIsAlertDialogOpen(true);
33-
return;
32+
if (!isContentYAML) {
33+
const convertFSA = await editorActions.convertContentToYAML(dereferencedContent);
34+
if (convertFSA.error) {
35+
alertDialogMessage.current = convertFSA.meta.errorMessage;
36+
setIsAlertDialogOpen(true);
37+
return;
38+
}
39+
dereferencedContent = convertFSA.payload;
3440
}
3541

3642
const downloadFSA = await editorActions.downloadContent({
37-
content: convertFSA.payload,
43+
content: dereferencedContent,
3844
fileNameWithExtension,
3945
});
4046
if (downloadFSA.error) {
@@ -61,6 +67,7 @@ DownloadResolvedYAMLMenuItemHandler.propTypes = {
6167
editorSelectors: PropTypes.shape({
6268
selectContent: PropTypes.func.isRequired,
6369
selectInferFileNameFromContent: PropTypes.func.isRequired,
70+
selectIsContentFormatYAML: PropTypes.func.isRequired,
6471
}).isRequired,
6572
editorActions: PropTypes.shape({
6673
dereferenceContent: PropTypes.func.isRequired,

0 commit comments

Comments
 (0)