Skip to content

Commit 23818d7

Browse files
authored
Merge pull request #530 from elkielki/issue475RemoveAttribution
Issue #475 - Removed attribution fields from native mode
2 parents c0a6cf4 + 963d198 commit 23818d7

File tree

22 files changed

+154
-246
lines changed

22 files changed

+154
-246
lines changed

src/app/api/native/pr/knowledge/route.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function POST(req: NextRequest) {
1818
const REPO_DIR = path.join(LOCAL_TAXONOMY_ROOT_DIR, '/taxonomy');
1919
try {
2020
// Extract the data from the request body
21-
const { action, branchName, content, attribution, name, email, submissionSummary, filePath, oldFilesPath } = await req.json();
21+
const { action, branchName, content, name, email, submissionSummary, filePath, oldFilesPath } = await req.json();
2222

2323
let knowledgeBranchName;
2424
if (action == 'update' && branchName != '') {
@@ -33,14 +33,6 @@ export async function POST(req: NextRequest) {
3333
// Convert the object to YAML
3434
const yamlString = dumpYaml(knowledgeData);
3535

36-
// Define branch name and file paths
37-
const attributionContent = `Title of work: ${attribution.title_of_work}
38-
Link to work: ${attribution.link_to_work}
39-
Revision: ${attribution.revision}
40-
License of the work: ${attribution.license_of_the_work}
41-
Creator names: ${attribution.creator_names}
42-
`;
43-
4436
// Set the flag if commit needs to be amended
4537
let amendCommit = false;
4638

@@ -56,38 +48,26 @@ Creator names: ${attribution.creator_names}
5648
await git.checkout({ fs, dir: REPO_DIR, ref: knowledgeBranchName });
5749

5850
const newYamlFilePath = path.join(KNOWLEDGE_DIR, filePath, 'qna.yaml');
59-
const newAttributionFilePath = path.join(KNOWLEDGE_DIR, filePath, 'attribution.txt');
6051

6152
// Write YAML file to the knowledge directory
6253
const yamlFilePath = path.join(REPO_DIR, newYamlFilePath);
6354
fs.mkdirSync(path.dirname(yamlFilePath), { recursive: true });
6455
fs.writeFileSync(yamlFilePath, yamlString);
6556

66-
// Write attribution file to the knowledge directory
67-
const attributionFilePath = path.join(REPO_DIR, newAttributionFilePath);
68-
fs.writeFileSync(attributionFilePath, attributionContent);
69-
7057
// Stage the files
7158
await git.add({ fs, dir: REPO_DIR, filepath: newYamlFilePath });
72-
await git.add({ fs, dir: REPO_DIR, filepath: newAttributionFilePath });
7359

7460
if (action == 'update') {
7561
// Define file paths
7662
const oldYamlFilePath = path.join(KNOWLEDGE_DIR, oldFilesPath, 'qna.yaml');
77-
const oldAttributionFilePath = path.join(KNOWLEDGE_DIR, oldFilesPath, 'attribution.txt');
7863

7964
if (oldYamlFilePath != newYamlFilePath) {
8065
console.log('File path for the knowledge contribution is updated, removing the old files.');
8166
// Write the QnA YAML file
8267
const yamlFilePath = path.join(REPO_DIR, oldYamlFilePath);
8368
fs.unlinkSync(yamlFilePath);
8469

85-
// Write the attribution text file
86-
const attributionFilePath = path.join(REPO_DIR, oldAttributionFilePath);
87-
fs.unlinkSync(attributionFilePath);
88-
8970
await git.remove({ fs, dir: REPO_DIR, filepath: oldYamlFilePath });
90-
await git.remove({ fs, dir: REPO_DIR, filepath: oldAttributionFilePath });
9171

9272
amendCommit = true;
9373
}

src/app/api/native/pr/skill/route.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as git from 'isomorphic-git';
55
import fs from 'fs';
66
import path from 'path';
77
import yaml from 'js-yaml';
8-
import { AttributionData, SkillYamlData } from '@/types';
8+
import { SkillYamlData } from '@/types';
99
import { dumpYaml } from '@/utils/yamlConfig';
1010

1111
// Define paths and configuration
@@ -17,7 +17,7 @@ export async function POST(req: NextRequest) {
1717
const REPO_DIR = path.join(LOCAL_TAXONOMY_ROOT_DIR, '/taxonomy');
1818
try {
1919
// Extract the QnA data from the request body TODO: what is documentOutline?
20-
const { action, branchName, content, attribution, name, email, submissionSummary, documentOutline, filePath, oldFilesPath } = await req.json(); // eslint-disable-line @typescript-eslint/no-unused-vars
20+
const { action, branchName, content, name, email, submissionSummary, documentOutline, filePath, oldFilesPath } = await req.json(); // eslint-disable-line @typescript-eslint/no-unused-vars
2121

2222
let skillBranchName;
2323
if (action == 'update' && branchName != '') {
@@ -27,14 +27,7 @@ export async function POST(req: NextRequest) {
2727
}
2828

2929
const skillData = yaml.load(content) as SkillYamlData;
30-
const attributionData = attribution as AttributionData;
31-
3230
const yamlString = dumpYaml(skillData);
33-
const attributionString = `
34-
Title of work: ${attributionData.title_of_work}
35-
License of the work: ${attributionData.license_of_the_work}
36-
Creator names: ${attributionData.creator_names}
37-
`;
3831

3932
// Set the flag if commit needs to be amended
4033
let amendCommit = false;
@@ -50,40 +43,28 @@ Creator names: ${attributionData.creator_names}
5043
// Checkout the new branch
5144
await git.checkout({ fs, dir: REPO_DIR, ref: skillBranchName });
5245

53-
// Define file paths
46+
// Define file path
5447
const newYamlFilePath = path.join(SKILLS_DIR, filePath, 'qna.yaml');
55-
const newAttributionFilePath = path.join(SKILLS_DIR, filePath, 'attribution.txt');
5648

5749
// Write the QnA YAML file
5850
const yamlFilePath = path.join(REPO_DIR, newYamlFilePath);
5951
fs.mkdirSync(path.dirname(yamlFilePath), { recursive: true });
6052
fs.writeFileSync(yamlFilePath, yamlString);
6153

62-
// Write the attribution text file
63-
const attributionFilePath = path.join(REPO_DIR, newAttributionFilePath);
64-
fs.writeFileSync(attributionFilePath, attributionString);
65-
66-
// Stage files
54+
// Stage file
6755
await git.add({ fs, dir: REPO_DIR, filepath: newYamlFilePath });
68-
await git.add({ fs, dir: REPO_DIR, filepath: newAttributionFilePath });
6956

7057
if (action == 'update') {
71-
// Define file paths
58+
// Define file path
7259
const oldYamlFilePath = path.join(SKILLS_DIR, oldFilesPath, 'qna.yaml');
73-
const oldAttributionFilePath = path.join(SKILLS_DIR, oldFilesPath, 'attribution.txt');
7460

7561
if (oldYamlFilePath != newYamlFilePath) {
7662
console.log('File path for the skill contribution is updated, removing the old files.');
7763
// Write the QnA YAML file
7864
const yamlFilePath = path.join(REPO_DIR, oldYamlFilePath);
7965
fs.unlinkSync(yamlFilePath);
8066

81-
// Write the attribution text file
82-
const attributionFilePath = path.join(REPO_DIR, oldAttributionFilePath);
83-
fs.unlinkSync(attributionFilePath);
84-
8567
await git.remove({ fs, dir: REPO_DIR, filepath: oldYamlFilePath });
86-
await git.remove({ fs, dir: REPO_DIR, filepath: oldAttributionFilePath });
8768

8869
amendCommit = true;
8970
}

src/components/Contribute/Knowledge/DownloadDropdown/DownloadDropdown.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import { DownloadIcon } from '@patternfly/react-icons';
88
interface Props {
99
knowledgeFormData: KnowledgeFormData;
1010
githubUsername: string | undefined;
11+
isGithubMode: boolean;
1112
}
1213

13-
export const DownloadDropdown: React.FunctionComponent<Props> = ({ knowledgeFormData, githubUsername }) => {
14+
export const DownloadDropdown: React.FunctionComponent<Props> = ({ knowledgeFormData, githubUsername, isGithubMode }) => {
1415
const [isOpen, setIsOpen] = React.useState(false);
1516

1617
const onToggleClick = () => {
@@ -47,7 +48,7 @@ export const DownloadDropdown: React.FunctionComponent<Props> = ({ knowledgeForm
4748
>
4849
<DropdownList>
4950
<DownloadYaml knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} />
50-
<DownloadAttribution knowledgeFormData={knowledgeFormData} />
51+
{isGithubMode && <DownloadAttribution knowledgeFormData={knowledgeFormData} />}
5152
</DropdownList>
5253
</Dropdown>
5354
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const Submit: React.FC<Props> = ({ disableAction, knowledgeFormData, setActionGr
2222

2323
const handleSubmit = async (event: React.FormEvent<HTMLButtonElement>) => {
2424
event.preventDefault();
25-
if (!validateFields(knowledgeFormData, setActionGroupAlertContent)) return;
25+
if (!validateFields(knowledgeFormData, setActionGroupAlertContent, false)) return;
2626

2727
// Strip leading slash and ensure trailing slash in the file path
2828
let sanitizedFilePath = knowledgeFormData.filePath!.startsWith('/') ? knowledgeFormData.filePath!.slice(1) : knowledgeFormData.filePath;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const Update: React.FC<Props> = ({ disableAction, knowledgeFormData, pullRequest
2525

2626
const handleUpdate = async (event: React.FormEvent<HTMLButtonElement>) => {
2727
event.preventDefault();
28-
if (!validateFields(knowledgeFormData, setActionGroupAlertContent)) return;
28+
if (!validateFields(knowledgeFormData, setActionGroupAlertContent, false)) return;
2929
if (session?.accessToken) {
3030
try {
3131
console.log(`Updating PR with number: ${pullRequestNumber}`);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ export const KnowledgeFormGithub: React.FunctionComponent<KnowledgeFormProps> =
688688
{
689689
id: 'review-submission',
690690
name: 'Review Submission',
691-
component: <ReviewSubmission knowledgeFormData={knowledgeFormData} />,
691+
component: <ReviewSubmission knowledgeFormData={knowledgeFormData} isGithubMode={true} />,
692692
footer: {
693693
isNextDisabled: true
694694
}
@@ -789,8 +789,8 @@ export const KnowledgeFormGithub: React.FunctionComponent<KnowledgeFormProps> =
789789
resetForm={resetForm}
790790
/>
791791
)}
792-
<DownloadDropdown knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} />
793-
<ViewDropdown knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} />
792+
<DownloadDropdown knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} isGithubMode={true} />
793+
<ViewDropdown knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} isGithubMode={true} />
794794
<Button variant="link" type="button" onClick={handleCancel}>
795795
Cancel
796796
</Button>

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// src/components/contribute/native/Knowledge/Submit/Submit.tsx
22
import React from 'react';
33
import { ActionGroupAlertContent } from '..';
4-
import { AttributionData, KnowledgeFormData, KnowledgeYamlData } from '@/types';
4+
import { KnowledgeFormData, KnowledgeYamlData } from '@/types';
55
import { KnowledgeSchemaVersion } from '@/types/const';
66
import { dumpYaml } from '@/utils/yamlConfig';
77
import { validateFields } from '@/components/Contribute/Knowledge/validation';
@@ -18,7 +18,7 @@ interface Props {
1818
const Submit: React.FC<Props> = ({ disableAction, knowledgeFormData, setActionGroupAlertContent, email, resetForm }) => {
1919
const handleSubmit = async (event: React.FormEvent<HTMLButtonElement>) => {
2020
event.preventDefault();
21-
if (!validateFields(knowledgeFormData, setActionGroupAlertContent)) return;
21+
if (!validateFields(knowledgeFormData, setActionGroupAlertContent, true)) return;
2222

2323
// Strip leading slash and ensure trailing slash in the file path
2424
let sanitizedFilePath = knowledgeFormData.filePath!.startsWith('/') ? knowledgeFormData.filePath!.slice(1) : knowledgeFormData.filePath;
@@ -45,14 +45,6 @@ const Submit: React.FC<Props> = ({ disableAction, knowledgeFormData, setActionGr
4545

4646
const yamlString = dumpYaml(knowledgeYamlData);
4747

48-
const attributionData: AttributionData = {
49-
title_of_work: knowledgeFormData.titleWork!,
50-
link_to_work: knowledgeFormData.linkWork!,
51-
revision: knowledgeFormData.revision!,
52-
license_of_the_work: knowledgeFormData.licenseWork!,
53-
creator_names: knowledgeFormData.creators!
54-
};
55-
5648
const waitForSubmissionAlert: ActionGroupAlertContent = {
5749
title: 'Knowledge contribution submission in progress!',
5850
message: `Once the submission is successful, it will provide the link to the newly created Pull Request.`,
@@ -74,7 +66,6 @@ const Submit: React.FC<Props> = ({ disableAction, knowledgeFormData, setActionGr
7466
action: 'submit',
7567
branch: '',
7668
content: yamlString,
77-
attribution: attributionData,
7869
name,
7970
email,
8071
submissionSummary,

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// src/components/contribute/Knowledge/Native/Update/Update.tsx
22
import React from 'react';
33
import { ActionGroupAlertContent } from '..';
4-
import { AttributionData, KnowledgeFormData, KnowledgeYamlData } from '@/types';
4+
import { KnowledgeFormData, KnowledgeYamlData } from '@/types';
55
import { KnowledgeSchemaVersion } from '@/types/const';
66
import { dumpYaml } from '@/utils/yamlConfig';
77
import { validateFields } from '@/components/Contribute/Knowledge/validation';
@@ -22,7 +22,7 @@ const Update: React.FC<Props> = ({ disableAction, knowledgeFormData, oldFilesPat
2222

2323
const handleUpdate = async (event: React.FormEvent<HTMLButtonElement>) => {
2424
event.preventDefault();
25-
if (!validateFields(knowledgeFormData, setActionGroupAlertContent)) return;
25+
if (!validateFields(knowledgeFormData, setActionGroupAlertContent, true)) return;
2626

2727
// Strip leading slash and ensure trailing slash in the file path
2828
let sanitizedFilePath = knowledgeFormData.filePath!.startsWith('/') ? knowledgeFormData.filePath!.slice(1) : knowledgeFormData.filePath;
@@ -49,14 +49,6 @@ const Update: React.FC<Props> = ({ disableAction, knowledgeFormData, oldFilesPat
4949

5050
const yamlString = dumpYaml(knowledgeYamlData);
5151

52-
const attributionData: AttributionData = {
53-
title_of_work: knowledgeFormData.titleWork!,
54-
link_to_work: knowledgeFormData.linkWork!,
55-
revision: knowledgeFormData.revision!,
56-
license_of_the_work: knowledgeFormData.licenseWork!,
57-
creator_names: knowledgeFormData.creators!
58-
};
59-
6052
const waitForSubmissionAlert: ActionGroupAlertContent = {
6153
title: 'Knowledge contribution submission in progress!',
6254
message: `Once the submission is successful, it will provide the link to the newly created Pull Request.`,
@@ -78,7 +70,6 @@ const Update: React.FC<Props> = ({ disableAction, knowledgeFormData, oldFilesPat
7870
action: 'update',
7971
branchName: branchName,
8072
content: yamlString,
81-
attribution: attributionData,
8273
name,
8374
email,
8475
submissionSummary,

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

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { FormType } from '@/components/Contribute/AuthorInformation';
88
import KnowledgeInformation from '@/components/Contribute/Knowledge/KnowledgeInformation/KnowledgeInformation';
99
import FilePathInformation from '@/components/Contribute/Knowledge/FilePathInformation/FilePathInformation';
1010
import DocumentInformation from '@/components/Contribute/Knowledge/Native/DocumentInformation/DocumentInformation';
11-
import AttributionInformation from '@/components/Contribute/Knowledge/AttributionInformation/AttributionInformation';
1211
import Submit from './Submit/Submit';
1312
import KnowledgeDescriptionContent from '@/components/Contribute/Knowledge/KnowledgeDescription/KnowledgeDescriptionContent';
1413
import KnowledgeSeedExampleNative from '@/components/Contribute/Knowledge/Native/KnowledgeSeedExampleNative/KnowledgeSeedExampleNative';
@@ -206,7 +205,7 @@ export const KnowledgeFormNative: React.FunctionComponent<KnowledgeFormProps> =
206205
}
207206
const tokens = contextStr.split(/\s+/);
208207
if (tokens.length > 0 && tokens.length <= 500) {
209-
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData));
208+
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData, true));
210209
return { msg: 'Valid Input', status: ValidatedOptions.success };
211210
}
212211
setDisableAction(true);
@@ -222,7 +221,7 @@ export const KnowledgeFormNative: React.FunctionComponent<KnowledgeFormProps> =
222221
}
223222
const tokens = questionStr.split(/\s+/);
224223
if (tokens.length > 0 && tokens.length < 250) {
225-
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData));
224+
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData, true));
226225
return { msg: 'Valid input', status: ValidatedOptions.success };
227226
}
228227
setDisableAction(true);
@@ -237,7 +236,7 @@ export const KnowledgeFormNative: React.FunctionComponent<KnowledgeFormProps> =
237236
}
238237
const tokens = answerStr.split(/\s+/);
239238
if (tokens.length > 0 && tokens.length < 250) {
240-
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData));
239+
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData, true));
241240
return { msg: 'Valid input', status: ValidatedOptions.success };
242241
}
243242
setDisableAction(true);
@@ -424,7 +423,7 @@ export const KnowledgeFormNative: React.FunctionComponent<KnowledgeFormProps> =
424423

425424
const deleteSeedExample = (seedExampleIndex: number): void => {
426425
setSeedExamples(seedExamples.filter((_, index: number) => index !== seedExampleIndex));
427-
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData));
426+
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData, true));
428427
};
429428

430429
const onCloseActionGroupAlert = () => {
@@ -539,7 +538,7 @@ export const KnowledgeFormNative: React.FunctionComponent<KnowledgeFormProps> =
539538
}, [seedExamples]);
540539

541540
useEffect(() => {
542-
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData));
541+
setDisableAction(!checkKnowledgeFormCompletion(knowledgeFormData, true));
543542
}, [knowledgeFormData]);
544543

545544
const handleCancel = () => {
@@ -645,32 +644,10 @@ export const KnowledgeFormNative: React.FunctionComponent<KnowledgeFormProps> =
645644
/>
646645
)
647646
},
648-
{
649-
id: 'attribution-info',
650-
name: 'Attribution Information',
651-
component: (
652-
<AttributionInformation
653-
reset={reset}
654-
isEditForm={knowledgeEditFormData?.isEditForm}
655-
knowledgeFormData={knowledgeFormData}
656-
setDisableAction={setDisableAction}
657-
titleWork={titleWork}
658-
setTitleWork={setTitleWork}
659-
linkWork={linkWork}
660-
setLinkWork={setLinkWork}
661-
revision={revision}
662-
setRevision={setRevision}
663-
licenseWork={licenseWork}
664-
setLicenseWork={setLicenseWork}
665-
creators={creators}
666-
setCreators={setCreators}
667-
/>
668-
)
669-
},
670647
{
671648
id: 'review-submission',
672649
name: 'Review Submission',
673-
component: <ReviewSubmission knowledgeFormData={knowledgeFormData} />,
650+
component: <ReviewSubmission knowledgeFormData={knowledgeFormData} isGithubMode={false} />,
674651
footer: {
675652
isNextDisabled: true
676653
}
@@ -771,8 +748,8 @@ export const KnowledgeFormNative: React.FunctionComponent<KnowledgeFormProps> =
771748
resetForm={resetForm}
772749
/>
773750
)}
774-
<DownloadDropdown knowledgeFormData={knowledgeFormData} githubUsername={email} />
775-
<ViewDropdown knowledgeFormData={knowledgeFormData} githubUsername={email} />
751+
<DownloadDropdown knowledgeFormData={knowledgeFormData} githubUsername={email} isGithubMode={false} />
752+
<ViewDropdown knowledgeFormData={knowledgeFormData} githubUsername={email} isGithubMode={false} />
776753
<Button variant="link" type="button" onClick={handleCancel}>
777754
Cancel
778755
</Button>

0 commit comments

Comments
 (0)