From e15546b7b2f0beee5b1788196afa5a29493b131f Mon Sep 17 00:00:00 2001 From: Anil Vishnoi Date: Fri, 6 Sep 2024 14:59:09 -0700 Subject: [PATCH] Improves following in the knowlege submission form - Remove buttons to add new QnA pair and seed examples, because backend ignores more than 3 QnA pair per context and more than 5 seed examples. - Replace info to information Signed-off-by: Anil Vishnoi --- .../AttributionInformation.tsx | 2 +- .../AuthorInformation/AuthorInformation.tsx | 2 +- .../DocumentInformation.tsx | 2 +- .../FilePathInformation.tsx | 2 +- .../KnowledgeInformation.tsx | 2 +- .../KnowledgeQuestionAnswerPairs.tsx | 21 +------- .../KnowledgeSeedExample.tsx | 24 +-------- src/components/Contribute/Knowledge/index.tsx | 52 ------------------- src/utils/yamlConfig.ts | 28 +++++----- 9 files changed, 21 insertions(+), 114 deletions(-) diff --git a/src/components/Contribute/Knowledge/AttributionInformation/AttributionInformation.tsx b/src/components/Contribute/Knowledge/AttributionInformation/AttributionInformation.tsx index ef362c5a..6a2683ec 100644 --- a/src/components/Contribute/Knowledge/AttributionInformation/AttributionInformation.tsx +++ b/src/components/Contribute/Knowledge/AttributionInformation/AttributionInformation.tsx @@ -136,7 +136,7 @@ const AttributionInformation: React.FC = ({ titleText={{ text: (

- Attribution Info * + Attribution Information *

), id: 'attribution-info-id' diff --git a/src/components/Contribute/Knowledge/AuthorInformation/AuthorInformation.tsx b/src/components/Contribute/Knowledge/AuthorInformation/AuthorInformation.tsx index dcec4db7..2b98a346 100644 --- a/src/components/Contribute/Knowledge/AuthorInformation/AuthorInformation.tsx +++ b/src/components/Contribute/Knowledge/AuthorInformation/AuthorInformation.tsx @@ -58,7 +58,7 @@ const AuthorInformation: React.FC = ({ reset, knowledgeFormData, setDisab titleText={{ text: (

- Author Info * + Author Information *

), id: 'author-info-id' diff --git a/src/components/Contribute/Knowledge/DocumentInformation/DocumentInformation.tsx b/src/components/Contribute/Knowledge/DocumentInformation/DocumentInformation.tsx index 4b3f361c..50686478 100644 --- a/src/components/Contribute/Knowledge/DocumentInformation/DocumentInformation.tsx +++ b/src/components/Contribute/Knowledge/DocumentInformation/DocumentInformation.tsx @@ -212,7 +212,7 @@ const DocumentInformation: React.FC = ({ titleText={{ text: (

- Document Info * + Document Information *

), id: 'doc-info-id' diff --git a/src/components/Contribute/Knowledge/FilePathInformation/FilePathInformation.tsx b/src/components/Contribute/Knowledge/FilePathInformation/FilePathInformation.tsx index 71c3baf3..0282b484 100644 --- a/src/components/Contribute/Knowledge/FilePathInformation/FilePathInformation.tsx +++ b/src/components/Contribute/Knowledge/FilePathInformation/FilePathInformation.tsx @@ -18,7 +18,7 @@ const FilePathInformation: React.FC = ({ reset, path, setFilePath }) => { titleText={{ text: (

- File Path Info * + Taxonomy Directory Path *

), id: 'file-path-info-id' diff --git a/src/components/Contribute/Knowledge/KnowledgeInformation/KnowledgeInformation.tsx b/src/components/Contribute/Knowledge/KnowledgeInformation/KnowledgeInformation.tsx index d4d0e0f5..b86e669b 100644 --- a/src/components/Contribute/Knowledge/KnowledgeInformation/KnowledgeInformation.tsx +++ b/src/components/Contribute/Knowledge/KnowledgeInformation/KnowledgeInformation.tsx @@ -94,7 +94,7 @@ const KnowledgeInformation: React.FC = ({ titleText={{ text: (

- Knowledge Info * + Knowledge Information *

), id: 'knowledge-info-id' diff --git a/src/components/Contribute/Knowledge/KnowledgeQuestionAnswerPairs/KnowledgeQuestionAnswerPairs.tsx b/src/components/Contribute/Knowledge/KnowledgeQuestionAnswerPairs/KnowledgeQuestionAnswerPairs.tsx index e9ddb6db..118b2163 100644 --- a/src/components/Contribute/Knowledge/KnowledgeQuestionAnswerPairs/KnowledgeQuestionAnswerPairs.tsx +++ b/src/components/Contribute/Knowledge/KnowledgeQuestionAnswerPairs/KnowledgeQuestionAnswerPairs.tsx @@ -1,8 +1,7 @@ import React from 'react'; import { FormFieldGroupExpandable, FormFieldGroupHeader, FormGroup, FormHelperText } from '@patternfly/react-core/dist/dynamic/components/Form'; import { TextArea } from '@patternfly/react-core/dist/dynamic/components/TextArea'; -import { Button } from '@patternfly/react-core/dist/dynamic/components/Button'; -import { TrashIcon, PlusCircleIcon, ExclamationCircleIcon } from '@patternfly/react-icons/dist/dynamic/icons/'; +import { ExclamationCircleIcon } from '@patternfly/react-icons/dist/dynamic/icons/'; import { QuestionAndAnswerPair, SeedExample } from '..'; import { ValidatedOptions } from '@patternfly/react-core/dist/esm/helpers/constants'; import { HelperText } from '@patternfly/react-core/dist/dynamic/components/HelperText'; @@ -17,8 +16,6 @@ interface Props { handleQuestionBlur: (seedExampleIndex: number, questionAndAnswerIndex: number) => void; handleAnswerInputChange: (seedExampleIndex: number, questionAndAnswerIndex: number, answerValue: string) => void; handleAnswerBlur: (seedExampleIndex: number, questionAndAnswerIndex: number) => void; - deleteQuestionAnswerPair: (seedExampleIndex: number, questionAnswerIndex: number) => void; - addQuestionAnswerPair: (seedExampleIndex: number) => void; } const KnowledgeQuestionAnswerPairs: React.FC = ({ @@ -29,9 +26,7 @@ const KnowledgeQuestionAnswerPairs: React.FC = ({ handleQuestionInputChange, handleQuestionBlur, handleAnswerInputChange, - handleAnswerBlur, - deleteQuestionAnswerPair, - addQuestionAnswerPair + handleAnswerBlur }) => { return ( @@ -72,13 +67,6 @@ const KnowledgeQuestionAnswerPairs: React.FC = ({ ), id: 'nested-field-group1-titleText-id' }} - actions={ - !seedExample.questionAndAnswers[questionAnswerIndex].immutable && ( - - ) - } /> } > @@ -128,11 +116,6 @@ const KnowledgeQuestionAnswerPairs: React.FC = ({ ))} -
- -
); }; diff --git a/src/components/Contribute/Knowledge/KnowledgeSeedExample/KnowledgeSeedExample.tsx b/src/components/Contribute/Knowledge/KnowledgeSeedExample/KnowledgeSeedExample.tsx index 6952bfda..541ee916 100644 --- a/src/components/Contribute/Knowledge/KnowledgeSeedExample/KnowledgeSeedExample.tsx +++ b/src/components/Contribute/Knowledge/KnowledgeSeedExample/KnowledgeSeedExample.tsx @@ -1,7 +1,5 @@ import React from 'react'; import { FormFieldGroupExpandable, FormFieldGroupHeader } from '@patternfly/react-core/dist/dynamic/components/Form'; -import { Button } from '@patternfly/react-core/dist/dynamic/components/Button'; -import { TrashIcon, PlusCircleIcon } from '@patternfly/react-icons/dist/dynamic/icons/'; import KnowledgeQuestionAnswerPairs from '../KnowledgeQuestionAnswerPairs/KnowledgeQuestionAnswerPairs'; import { SeedExample } from '..'; @@ -13,10 +11,6 @@ interface Props { handleQuestionBlur: (seedExampleIndex: number, questionAndAnswerIndex: number) => void; handleAnswerInputChange: (seedExampleIndex: number, questionAndAnswerIndex: number, answerValue: string) => void; handleAnswerBlur: (seedExampleIndex: number, questionAndAnswerIndex: number) => void; - deleteQuestionAnswerPair: (seedExampleIndex: number, questionAnswerIndex: number) => void; - addQuestionAnswerPair: (seedExampleIndex: number) => void; - addSeedExample: () => void; - deleteSeedExample: (seedExampleIndex: number) => void; } const KnowledgeSeedExample: React.FC = ({ @@ -26,11 +20,7 @@ const KnowledgeSeedExample: React.FC = ({ handleQuestionInputChange, handleQuestionBlur, handleAnswerInputChange, - handleAnswerBlur, - deleteQuestionAnswerPair, - addQuestionAnswerPair, - addSeedExample, - deleteSeedExample + handleAnswerBlur }) => { return ( = ({ id: 'nested-field-group1-titleText-id' }} titleDescription="Please enter context and at least 3 Q&A pairs for the seed example." - actions={ - !seedExample.immutable && ( - - ) - } /> } > @@ -85,14 +68,9 @@ const KnowledgeSeedExample: React.FC = ({ handleQuestionBlur={handleQuestionBlur} handleAnswerInputChange={handleAnswerInputChange} handleAnswerBlur={handleAnswerBlur} - deleteQuestionAnswerPair={deleteQuestionAnswerPair} - addQuestionAnswerPair={addQuestionAnswerPair} /> ))} - ); }; diff --git a/src/components/Contribute/Knowledge/index.tsx b/src/components/Contribute/Knowledge/index.tsx index 2c718124..33b9c5aa 100644 --- a/src/components/Contribute/Knowledge/index.tsx +++ b/src/components/Contribute/Knowledge/index.tsx @@ -331,54 +331,6 @@ export const KnowledgeForm: React.FunctionComponent = ({ kno ); }; - const addQuestionAnswerPair = (seedExampleIndex: number): void => { - const newQuestionAnswerPair: QuestionAndAnswerPair = { - immutable: false, - question: '', - isQuestionValid: ValidatedOptions.default, - answer: '', - isAnswerValid: ValidatedOptions.default - }; - setSeedExamples( - seedExamples.map((seedExample: SeedExample, index: number) => - index === seedExampleIndex - ? { - ...seedExample, - questionAndAnswers: [...seedExample.questionAndAnswers, newQuestionAnswerPair] - } - : seedExample - ) - ); - setDisableAction(true); - }; - - const deleteQuestionAnswerPair = (seedExampleIndex: number, questionAnswerIndex: number): void => { - setSeedExamples( - seedExamples.map((seedExample: SeedExample, index: number) => - index === seedExampleIndex - ? { - ...seedExample, - questionAndAnswers: seedExample.questionAndAnswers.filter((_, i) => i !== questionAnswerIndex) - } - : seedExample - ) - ); - setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData)); - }; - - const addSeedExample = (): void => { - const seedExample = emptySeedExample; - seedExample.immutable = false; - seedExample.isExpanded = true; - setSeedExamples([...seedExamples, seedExample]); - setDisableAction(true); - }; - - const deleteSeedExample = (seedExampleIndex: number): void => { - setSeedExamples(seedExamples.filter((_, index: number) => index !== seedExampleIndex)); - setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData)); - }; - const onCloseActionGroupAlert = () => { setActionGroupAlertContent(undefined); }; @@ -485,10 +437,6 @@ export const KnowledgeForm: React.FunctionComponent = ({ kno handleQuestionBlur={handleQuestionBlur} handleAnswerInputChange={handleAnswerInputChange} handleAnswerBlur={handleAnswerBlur} - deleteQuestionAnswerPair={deleteQuestionAnswerPair} - addQuestionAnswerPair={addQuestionAnswerPair} - addSeedExample={addSeedExample} - deleteSeedExample={deleteSeedExample} /> { - if (index === lines.length - 1 && line === '' && hasTrailingNewline) { - return undefined; - } - // Preserve empty lines - if (line.trim() === '') return ''; - // Trim trailing spaces, preserving indentation - const match = line.match(/^(\s*)(.*)$/); - if (match) { - const [, indent, content] = match; - return indent + content.trimEnd(); - } + const trimmedLines = lines.map((line, index) => { + if (index === lines.length - 1 && line === '' && hasTrailingNewline) { return line; - }) - .filter((line) => line !== undefined); + } + // Preserve empty lines + if (line.trim() === '') return ''; + // Trim trailing spaces, preserving indentation + const match = line.match(/^(\s*)(.*)$/); + if (match) { + const [, indent, content] = match; + return indent + content.trimEnd(); + } + return line; + }); return trimmedLines.join('\n'); }