Skip to content

Commit af27a84

Browse files
authored
Merge pull request #551 from aevo98765/bug/#515/display-invalid-yaml-error-message
Bug/#515/display invalid yaml error message
2 parents eb016ba + 80d7461 commit af27a84

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

src/components/Contribute/Knowledge/Github/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ export const KnowledgeFormGithub: React.FunctionComponent<KnowledgeFormProps> =
732732
setIsModalOpen={setIsYamlModalOpen}
733733
isKnowledgeForm={true}
734734
onYamlUploadKnowledgeFillForm={onYamlUploadKnowledgeFillForm}
735+
setActionGroupAlertContent={setActionGroupAlertContent}
735736
/>
736737

737738
<Wizard startIndex={activeStepIndex} onClose={handleCancel} height={600}>

src/components/Contribute/Knowledge/Native/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ export const KnowledgeFormNative: React.FunctionComponent<KnowledgeFormProps> =
714714
setIsModalOpen={setIsYamlModalOpen}
715715
isKnowledgeForm={true}
716716
onYamlUploadKnowledgeFillForm={onYamlUploadKnowledgeFillForm}
717+
setActionGroupAlertContent={setActionGroupAlertContent}
717718
/>
718719

719720
<Wizard startIndex={activeStepIndex} onClose={handleCancel} height={600}>

src/components/Contribute/Skill/Github/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ export const SkillFormGithub: React.FunctionComponent<SkillFormProps> = ({ skill
468468
setIsModalOpen={setIsModalOpen}
469469
isKnowledgeForm={false}
470470
onYamlUploadSkillsFillForm={onYamlUploadSkillsFillForm}
471+
setActionGroupAlertContent={setActionGroupAlertContent}
471472
/>
472473

473474
<Wizard startIndex={activeStepIndex} onClose={handleCancel} height={600}>

src/components/Contribute/Skill/Native/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ export const SkillFormNative: React.FunctionComponent<SkillFormProps> = ({ skill
450450
setIsModalOpen={setIsModalOpen}
451451
isKnowledgeForm={false}
452452
onYamlUploadSkillsFillForm={onYamlUploadSkillsFillForm}
453+
setActionGroupAlertContent={setActionGroupAlertContent}
453454
/>
454455

455456
<Wizard startIndex={activeStepIndex} onClose={handleCancel} height={600}>

src/components/Contribute/YamlFileUpload.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import yaml from 'js-yaml';
33
import { KnowledgeYamlData, SkillYamlData } from '@/types';
44
import { DropEvent, MultipleFileUpload, MultipleFileUploadMain } from '@patternfly/react-core';
55
import { UploadIcon } from '@patternfly/react-icons';
6+
import { ActionGroupAlertContent } from './Knowledge/Github';
67

78
interface readFile {
89
fileName: string;
@@ -16,13 +17,15 @@ interface YamlFileUploadProps {
1617
isKnowledgeForm: boolean;
1718
onYamlUploadKnowledgeFillForm?: (data: KnowledgeYamlData) => void;
1819
onYamlUploadSkillsFillForm?: (data: SkillYamlData) => void;
20+
setActionGroupAlertContent: React.Dispatch<React.SetStateAction<ActionGroupAlertContent | undefined>>;
1921
}
2022

2123
const YamlFileUpload: React.FC<YamlFileUploadProps> = ({
2224
setIsModalOpen,
2325
isKnowledgeForm,
2426
onYamlUploadKnowledgeFillForm,
25-
onYamlUploadSkillsFillForm
27+
onYamlUploadSkillsFillForm,
28+
setActionGroupAlertContent
2629
}) => {
2730
const [currentFiles, setCurrentFiles] = React.useState<File[]>([]);
2831
const [readFileData, setReadFileData] = React.useState<readFile[]>([]);
@@ -51,9 +54,23 @@ const YamlFileUpload: React.FC<YamlFileUploadProps> = ({
5154
onYamlUploadSkillsFillForm?.(parsedData);
5255
setIsModalOpen(false);
5356
} else {
57+
const yamlFileSchemaIssueAlertContent: ActionGroupAlertContent = {
58+
title: 'YAML file upload error!',
59+
message: `This yaml file does not match the Skills or Knowledge schema.`,
60+
success: false,
61+
timeout: false
62+
};
63+
setActionGroupAlertContent(yamlFileSchemaIssueAlertContent);
5464
console.error('This yaml file does not match the Skills or Knowledge schema');
5565
}
5666
} catch (error) {
67+
const yamlFileParsingIssueAlertContent: ActionGroupAlertContent = {
68+
title: 'YAML file upload error!',
69+
message: `This yaml file is not correct and cannot be parsed.`,
70+
success: false,
71+
timeout: false
72+
};
73+
setActionGroupAlertContent(yamlFileParsingIssueAlertContent);
5774
console.error('Error parsing YAML file:', error);
5875
}
5976
};

src/components/Contribute/YamlFileUploadModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ import React from 'react';
22
import YamlFileUpload from './YamlFileUpload';
33
import { KnowledgeYamlData, SkillYamlData } from '@/types';
44
import { Modal, ModalVariant, ModalHeader, ModalBody } from '@patternfly/react-core';
5+
import { ActionGroupAlertContent } from './Knowledge/Github';
56

67
interface Props {
78
isModalOpen: boolean;
89
setIsModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
910
isKnowledgeForm: boolean;
1011
onYamlUploadKnowledgeFillForm?: (data: KnowledgeYamlData) => void;
1112
onYamlUploadSkillsFillForm?: (data: SkillYamlData) => void;
13+
setActionGroupAlertContent: React.Dispatch<React.SetStateAction<ActionGroupAlertContent | undefined>>;
1214
}
1315

1416
export const YamlFileUploadModal: React.FunctionComponent<Props> = ({
1517
isModalOpen,
1618
setIsModalOpen,
1719
isKnowledgeForm,
1820
onYamlUploadKnowledgeFillForm,
19-
onYamlUploadSkillsFillForm
21+
onYamlUploadSkillsFillForm,
22+
setActionGroupAlertContent
2023
}) => {
2124
const handleModalToggle = () => {
2225
setIsModalOpen(!isModalOpen);
@@ -40,6 +43,7 @@ export const YamlFileUploadModal: React.FunctionComponent<Props> = ({
4043
isKnowledgeForm={isKnowledgeForm}
4144
onYamlUploadKnowledgeFillForm={onYamlUploadKnowledgeFillForm}
4245
onYamlUploadSkillsFillForm={onYamlUploadSkillsFillForm}
46+
setActionGroupAlertContent={setActionGroupAlertContent}
4347
/>
4448
</ModalBody>
4549
</Modal>

0 commit comments

Comments
 (0)