Skip to content

Commit 9a367e9

Browse files
authored
Merge pull request #160 from vishnoianil/knowledge-improvements
Improves following in the knowledge submission form
2 parents bd7b4b5 + e15546b commit 9a367e9

File tree

9 files changed

+21
-114
lines changed

9 files changed

+21
-114
lines changed

src/components/Contribute/Knowledge/AttributionInformation/AttributionInformation.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const AttributionInformation: React.FC<Props> = ({
136136
titleText={{
137137
text: (
138138
<p>
139-
Attribution Info <span style={{ color: 'red' }}>*</span>
139+
Attribution Information <span style={{ color: 'red' }}>*</span>
140140
</p>
141141
),
142142
id: 'attribution-info-id'

src/components/Contribute/Knowledge/AuthorInformation/AuthorInformation.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const AuthorInformation: React.FC<Props> = ({ reset, knowledgeFormData, setDisab
5858
titleText={{
5959
text: (
6060
<p>
61-
Author Info <span style={{ color: 'red' }}>*</span>
61+
Author Information <span style={{ color: 'red' }}>*</span>
6262
</p>
6363
),
6464
id: 'author-info-id'

src/components/Contribute/Knowledge/DocumentInformation/DocumentInformation.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ const DocumentInformation: React.FC<Props> = ({
212212
titleText={{
213213
text: (
214214
<p>
215-
Document Info <span style={{ color: 'red' }}>*</span>
215+
Document Information <span style={{ color: 'red' }}>*</span>
216216
</p>
217217
),
218218
id: 'doc-info-id'

src/components/Contribute/Knowledge/FilePathInformation/FilePathInformation.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const FilePathInformation: React.FC<Props> = ({ reset, path, setFilePath }) => {
1818
titleText={{
1919
text: (
2020
<p>
21-
File Path Info <span style={{ color: 'red' }}>*</span>
21+
Taxonomy Directory Path <span style={{ color: 'red' }}>*</span>
2222
</p>
2323
),
2424
id: 'file-path-info-id'

src/components/Contribute/Knowledge/KnowledgeInformation/KnowledgeInformation.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const KnowledgeInformation: React.FC<Props> = ({
9494
titleText={{
9595
text: (
9696
<p>
97-
Knowledge Info <span style={{ color: 'red' }}>*</span>
97+
Knowledge Information <span style={{ color: 'red' }}>*</span>
9898
</p>
9999
),
100100
id: 'knowledge-info-id'

src/components/Contribute/Knowledge/KnowledgeQuestionAnswerPairs/KnowledgeQuestionAnswerPairs.tsx

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22
import { FormFieldGroupExpandable, FormFieldGroupHeader, FormGroup, FormHelperText } from '@patternfly/react-core/dist/dynamic/components/Form';
33
import { TextArea } from '@patternfly/react-core/dist/dynamic/components/TextArea';
4-
import { Button } from '@patternfly/react-core/dist/dynamic/components/Button';
5-
import { TrashIcon, PlusCircleIcon, ExclamationCircleIcon } from '@patternfly/react-icons/dist/dynamic/icons/';
4+
import { ExclamationCircleIcon } from '@patternfly/react-icons/dist/dynamic/icons/';
65
import { QuestionAndAnswerPair, SeedExample } from '..';
76
import { ValidatedOptions } from '@patternfly/react-core/dist/esm/helpers/constants';
87
import { HelperText } from '@patternfly/react-core/dist/dynamic/components/HelperText';
@@ -17,8 +16,6 @@ interface Props {
1716
handleQuestionBlur: (seedExampleIndex: number, questionAndAnswerIndex: number) => void;
1817
handleAnswerInputChange: (seedExampleIndex: number, questionAndAnswerIndex: number, answerValue: string) => void;
1918
handleAnswerBlur: (seedExampleIndex: number, questionAndAnswerIndex: number) => void;
20-
deleteQuestionAnswerPair: (seedExampleIndex: number, questionAnswerIndex: number) => void;
21-
addQuestionAnswerPair: (seedExampleIndex: number) => void;
2219
}
2320

2421
const KnowledgeQuestionAnswerPairs: React.FC<Props> = ({
@@ -29,9 +26,7 @@ const KnowledgeQuestionAnswerPairs: React.FC<Props> = ({
2926
handleQuestionInputChange,
3027
handleQuestionBlur,
3128
handleAnswerInputChange,
32-
handleAnswerBlur,
33-
deleteQuestionAnswerPair,
34-
addQuestionAnswerPair
29+
handleAnswerBlur
3530
}) => {
3631
return (
3732
<FormGroup key={seedExampleIndex}>
@@ -72,13 +67,6 @@ const KnowledgeQuestionAnswerPairs: React.FC<Props> = ({
7267
),
7368
id: 'nested-field-group1-titleText-id'
7469
}}
75-
actions={
76-
!seedExample.questionAndAnswers[questionAnswerIndex].immutable && (
77-
<Button variant="plain" aria-label="Remove" onClick={() => deleteQuestionAnswerPair(seedExampleIndex, questionAnswerIndex)}>
78-
<TrashIcon />
79-
</Button>
80-
)
81-
}
8270
/>
8371
}
8472
>
@@ -128,11 +116,6 @@ const KnowledgeQuestionAnswerPairs: React.FC<Props> = ({
128116
</React.Fragment>
129117
</FormFieldGroupExpandable>
130118
))}
131-
<div style={{ marginTop: '10px', marginBottom: '20px', textAlign: 'right' }}>
132-
<Button variant="link" onClick={() => addQuestionAnswerPair(seedExampleIndex)}>
133-
<PlusCircleIcon /> Add Q&A Pair
134-
</Button>
135-
</div>
136119
</FormGroup>
137120
);
138121
};

src/components/Contribute/Knowledge/KnowledgeSeedExample/KnowledgeSeedExample.tsx

+1-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React from 'react';
22
import { FormFieldGroupExpandable, FormFieldGroupHeader } from '@patternfly/react-core/dist/dynamic/components/Form';
3-
import { Button } from '@patternfly/react-core/dist/dynamic/components/Button';
4-
import { TrashIcon, PlusCircleIcon } from '@patternfly/react-icons/dist/dynamic/icons/';
53
import KnowledgeQuestionAnswerPairs from '../KnowledgeQuestionAnswerPairs/KnowledgeQuestionAnswerPairs';
64
import { SeedExample } from '..';
75

@@ -13,10 +11,6 @@ interface Props {
1311
handleQuestionBlur: (seedExampleIndex: number, questionAndAnswerIndex: number) => void;
1412
handleAnswerInputChange: (seedExampleIndex: number, questionAndAnswerIndex: number, answerValue: string) => void;
1513
handleAnswerBlur: (seedExampleIndex: number, questionAndAnswerIndex: number) => void;
16-
deleteQuestionAnswerPair: (seedExampleIndex: number, questionAnswerIndex: number) => void;
17-
addQuestionAnswerPair: (seedExampleIndex: number) => void;
18-
addSeedExample: () => void;
19-
deleteSeedExample: (seedExampleIndex: number) => void;
2014
}
2115

2216
const KnowledgeSeedExample: React.FC<Props> = ({
@@ -26,11 +20,7 @@ const KnowledgeSeedExample: React.FC<Props> = ({
2620
handleQuestionInputChange,
2721
handleQuestionBlur,
2822
handleAnswerInputChange,
29-
handleAnswerBlur,
30-
deleteQuestionAnswerPair,
31-
addQuestionAnswerPair,
32-
addSeedExample,
33-
deleteSeedExample
23+
handleAnswerBlur
3424
}) => {
3525
return (
3626
<FormFieldGroupExpandable
@@ -66,13 +56,6 @@ const KnowledgeSeedExample: React.FC<Props> = ({
6656
id: 'nested-field-group1-titleText-id'
6757
}}
6858
titleDescription="Please enter context and at least 3 Q&A pairs for the seed example."
69-
actions={
70-
!seedExample.immutable && (
71-
<Button variant="plain" aria-label="Remove" onClick={() => deleteSeedExample(seedExampleIndex)}>
72-
<TrashIcon />
73-
</Button>
74-
)
75-
}
7659
/>
7760
}
7861
>
@@ -85,14 +68,9 @@ const KnowledgeSeedExample: React.FC<Props> = ({
8568
handleQuestionBlur={handleQuestionBlur}
8669
handleAnswerInputChange={handleAnswerInputChange}
8770
handleAnswerBlur={handleAnswerBlur}
88-
deleteQuestionAnswerPair={deleteQuestionAnswerPair}
89-
addQuestionAnswerPair={addQuestionAnswerPair}
9071
/>
9172
</FormFieldGroupExpandable>
9273
))}
93-
<Button variant="link" onClick={addSeedExample}>
94-
<PlusCircleIcon /> Add Seed Example
95-
</Button>
9674
</FormFieldGroupExpandable>
9775
);
9876
};

src/components/Contribute/Knowledge/index.tsx

-52
Original file line numberDiff line numberDiff line change
@@ -331,54 +331,6 @@ export const KnowledgeForm: React.FunctionComponent<KnowledgeFormProps> = ({ kno
331331
);
332332
};
333333

334-
const addQuestionAnswerPair = (seedExampleIndex: number): void => {
335-
const newQuestionAnswerPair: QuestionAndAnswerPair = {
336-
immutable: false,
337-
question: '',
338-
isQuestionValid: ValidatedOptions.default,
339-
answer: '',
340-
isAnswerValid: ValidatedOptions.default
341-
};
342-
setSeedExamples(
343-
seedExamples.map((seedExample: SeedExample, index: number) =>
344-
index === seedExampleIndex
345-
? {
346-
...seedExample,
347-
questionAndAnswers: [...seedExample.questionAndAnswers, newQuestionAnswerPair]
348-
}
349-
: seedExample
350-
)
351-
);
352-
setDisableAction(true);
353-
};
354-
355-
const deleteQuestionAnswerPair = (seedExampleIndex: number, questionAnswerIndex: number): void => {
356-
setSeedExamples(
357-
seedExamples.map((seedExample: SeedExample, index: number) =>
358-
index === seedExampleIndex
359-
? {
360-
...seedExample,
361-
questionAndAnswers: seedExample.questionAndAnswers.filter((_, i) => i !== questionAnswerIndex)
362-
}
363-
: seedExample
364-
)
365-
);
366-
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData));
367-
};
368-
369-
const addSeedExample = (): void => {
370-
const seedExample = emptySeedExample;
371-
seedExample.immutable = false;
372-
seedExample.isExpanded = true;
373-
setSeedExamples([...seedExamples, seedExample]);
374-
setDisableAction(true);
375-
};
376-
377-
const deleteSeedExample = (seedExampleIndex: number): void => {
378-
setSeedExamples(seedExamples.filter((_, index: number) => index !== seedExampleIndex));
379-
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData));
380-
};
381-
382334
const onCloseActionGroupAlert = () => {
383335
setActionGroupAlertContent(undefined);
384336
};
@@ -485,10 +437,6 @@ export const KnowledgeForm: React.FunctionComponent<KnowledgeFormProps> = ({ kno
485437
handleQuestionBlur={handleQuestionBlur}
486438
handleAnswerInputChange={handleAnswerInputChange}
487439
handleAnswerBlur={handleAnswerBlur}
488-
deleteQuestionAnswerPair={deleteQuestionAnswerPair}
489-
addQuestionAnswerPair={addQuestionAnswerPair}
490-
addSeedExample={addSeedExample}
491-
deleteSeedExample={deleteSeedExample}
492440
/>
493441

494442
<DocumentInformation

src/utils/yamlConfig.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,20 @@ function filterEmptyContext(data: unknown): unknown {
5858
function trimTrailingSpaces(yamlString: string): string {
5959
const hasTrailingNewline = yamlString.endsWith('\n');
6060
const lines = yamlString.split('\n');
61-
const trimmedLines = lines
62-
.map((line, index) => {
63-
if (index === lines.length - 1 && line === '' && hasTrailingNewline) {
64-
return undefined;
65-
}
66-
// Preserve empty lines
67-
if (line.trim() === '') return '';
68-
// Trim trailing spaces, preserving indentation
69-
const match = line.match(/^(\s*)(.*)$/);
70-
if (match) {
71-
const [, indent, content] = match;
72-
return indent + content.trimEnd();
73-
}
61+
const trimmedLines = lines.map((line, index) => {
62+
if (index === lines.length - 1 && line === '' && hasTrailingNewline) {
7463
return line;
75-
})
76-
.filter((line) => line !== undefined);
64+
}
65+
// Preserve empty lines
66+
if (line.trim() === '') return '';
67+
// Trim trailing spaces, preserving indentation
68+
const match = line.match(/^(\s*)(.*)$/);
69+
if (match) {
70+
const [, indent, content] = match;
71+
return indent + content.trimEnd();
72+
}
73+
return line;
74+
});
7775

7876
return trimmedLines.join('\n');
7977
}

0 commit comments

Comments
 (0)