Skip to content

Commit

Permalink
Merge pull request #255 from aevo98765/feature/#240/allow-download-of…
Browse files Browse the repository at this point in the history
…-partial-completed-knowledge-and-skills

Allowing the download of partial completed knowledge and skills attributions and skills.
  • Loading branch information
aevo98765 authored Oct 15, 2024
2 parents 799de87 + dbdab28 commit b782678
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React from 'react';
import { validateFields } from '../validation';
import { ActionGroupAlertContent, KnowledgeFormData } from '..';
import { KnowledgeFormData } from '..';
import { DropdownItem } from '@patternfly/react-core/dist/esm/components/Dropdown/DropdownItem';
import FileIcon from '@patternfly/react-icons/dist/esm/icons/file-icon';

interface Props {
disableAction: boolean;
knowledgeFormData: KnowledgeFormData;
setActionGroupAlertContent: React.Dispatch<React.SetStateAction<ActionGroupAlertContent | undefined>>;
}

const DownloadAttribution: React.FC<Props> = ({ disableAction, knowledgeFormData, setActionGroupAlertContent }) => {
const DownloadAttribution: React.FC<Props> = ({ knowledgeFormData }) => {
const handleDownloadAttribution = () => {
// Because I have overly complicated the validatedFields function all fields are being checked and not just the attribution ones here. Not ideal.
if (!validateFields(knowledgeFormData, setActionGroupAlertContent)) return;

const attributionContent = `Title of work: ${knowledgeFormData.titleWork}
Link to work: ${knowledgeFormData.linkWork}
Expand All @@ -33,7 +29,7 @@ const DownloadAttribution: React.FC<Props> = ({ disableAction, knowledgeFormData
};

return (
<DropdownItem key="DownloadAttribution" to="#default-link6" isDisabled={disableAction} onClick={handleDownloadAttribution}>
<DropdownItem key="DownloadAttribution" to="#default-link6" onClick={handleDownloadAttribution}>
<FileIcon /> Attribution File
</DropdownItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ import { DropdownList } from '@patternfly/react-core/dist/dynamic/components/Dro
import { MenuToggle, MenuToggleElement } from '@patternfly/react-core/dist/dynamic/components/MenuToggle';
import DownloadYaml from '../DownloadYaml/DownloadYaml';
import DownloadAttribution from '../DownloadAttribution/DownloadAttribution';
import { ActionGroupAlertContent, KnowledgeFormData } from '..';
import { KnowledgeFormData } from '..';
import DownloadIcon from '@patternfly/react-icons/dist/esm/icons/download-icon';

interface Props {
disableAction: boolean;
knowledgeFormData: KnowledgeFormData;
setActionGroupAlertContent: React.Dispatch<React.SetStateAction<ActionGroupAlertContent | undefined>>;
githubUsername: string | undefined;
}

export const DownloadDropdown: React.FunctionComponent<Props> = ({
disableAction,
knowledgeFormData,
setActionGroupAlertContent,
githubUsername
}) => {
export const DownloadDropdown: React.FunctionComponent<Props> = ({ knowledgeFormData, githubUsername }) => {
const [isOpen, setIsOpen] = React.useState(false);

const onToggleClick = () => {
Expand All @@ -45,17 +38,8 @@ export const DownloadDropdown: React.FunctionComponent<Props> = ({
shouldFocusToggleOnSelect
>
<DropdownList>
<DownloadYaml
disableAction={disableAction}
knowledgeFormData={knowledgeFormData}
setActionGroupAlertContent={setActionGroupAlertContent}
githubUsername={githubUsername}
/>
<DownloadAttribution
disableAction={disableAction}
knowledgeFormData={knowledgeFormData}
setActionGroupAlertContent={setActionGroupAlertContent}
/>
<DownloadYaml knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} />
<DownloadAttribution knowledgeFormData={knowledgeFormData} />
</DropdownList>
</Dropdown>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import React from 'react';
import { validateFields } from '../validation';
import { ActionGroupAlertContent, KnowledgeFormData } from '..';
import { KnowledgeFormData } from '..';
import { KnowledgeYamlData } from '@/types';
import { KnowledgeSchemaVersion } from '@/types/const';
import { dumpYaml } from '@/utils/yamlConfig';
import { DropdownItem } from '@patternfly/react-core/dist/esm/components/Dropdown/DropdownItem';
import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon';

interface Props {
disableAction: boolean;
knowledgeFormData: KnowledgeFormData;
setActionGroupAlertContent: React.Dispatch<React.SetStateAction<ActionGroupAlertContent | undefined>>;
githubUsername: string | undefined;
}

const DownloadYaml: React.FC<Props> = ({ disableAction, knowledgeFormData, setActionGroupAlertContent, githubUsername }) => {
const DownloadYaml: React.FC<Props> = ({ knowledgeFormData, githubUsername }) => {
const handleDownloadYaml = () => {
if (!validateFields(knowledgeFormData, setActionGroupAlertContent)) return;

const yamlData: KnowledgeYamlData = {
created_by: githubUsername!,
version: KnowledgeSchemaVersion,
Expand Down Expand Up @@ -48,7 +43,7 @@ const DownloadYaml: React.FC<Props> = ({ disableAction, knowledgeFormData, setAc
document.body.removeChild(a);
};
return (
<DropdownItem key="Download Yaml" to="#default-link6" isDisabled={disableAction} onClick={handleDownloadYaml}>
<DropdownItem key="Download Yaml" to="#default-link6" onClick={handleDownloadYaml}>
<CodeIcon /> Yaml File
</DropdownItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import FileIcon from '@patternfly/react-icons/dist/dynamic/icons/file-icon';
import EyeIcon from '@patternfly/react-icons/dist/esm/icons/eye-icon';

interface Props {
disableAction: boolean;
knowledgeFormData: KnowledgeFormData;
githubUsername: string | undefined;
}

export const ViewDropdown: React.FunctionComponent<Props> = ({ disableAction, knowledgeFormData, githubUsername }) => {
export const ViewDropdown: React.FunctionComponent<Props> = ({ knowledgeFormData, githubUsername }) => {
const [isOpen, setIsOpen] = useState<boolean>(false);
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const [modalContent, setModalContent] = useState<string>('');
Expand Down Expand Up @@ -86,10 +85,10 @@ export const ViewDropdown: React.FunctionComponent<Props> = ({ disableAction, kn
shouldFocusToggleOnSelect
>
<DropdownList>
<DropdownItem key="view yaml" isDisabled={disableAction} onClick={handleViewYaml}>
<DropdownItem key="view yaml" onClick={handleViewYaml}>
<CodeIcon /> YAML Content
</DropdownItem>
<DropdownItem key="view yaml" isDisabled={disableAction} onClick={handleViewAttribution}>
<DropdownItem key="view yaml" onClick={handleViewAttribution}>
<FileIcon /> Attribution Content
</DropdownItem>
</DropdownList>
Expand Down
9 changes: 2 additions & 7 deletions src/components/Contribute/Knowledge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,8 @@ export const KnowledgeForm: React.FunctionComponent<KnowledgeFormProps> = ({ kno
resetForm={resetForm}
/>
)}
<DownloadDropdown
disableAction={disableAction}
knowledgeFormData={knowledgeFormData}
setActionGroupAlertContent={setActionGroupAlertContent}
githubUsername={githubUsername}
/>
<ViewDropdown disableAction={disableAction} knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} />
<DownloadDropdown knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} />
<ViewDropdown knowledgeFormData={knowledgeFormData} githubUsername={githubUsername} />
<Button variant="link" type="button" onClick={handleCancel}>
Cancel
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React from 'react';
import { validateFields } from '../validation';
import { ActionGroupAlertContent, SkillFormData } from '..';
import { SkillFormData } from '..';
import { DropdownItem } from '@patternfly/react-core/dist/esm/components/Dropdown/DropdownItem';
import FileIcon from '@patternfly/react-icons/dist/esm/icons/file-icon';

interface Props {
disableAction: boolean;
skillFormData: SkillFormData;
setActionGroupAlertContent: React.Dispatch<React.SetStateAction<ActionGroupAlertContent | undefined>>;
}

const DownloadAttribution: React.FC<Props> = ({ disableAction, skillFormData, setActionGroupAlertContent }) => {
const DownloadAttribution: React.FC<Props> = ({ skillFormData }) => {
const handleDownloadAttribution = () => {
// Because I have overly complicated the validatedFields function all fields are being checked and not just the attribution ones here. Not ideal.
if (!validateFields(skillFormData, setActionGroupAlertContent)) return;

const attributionContent = `Title of work: ${skillFormData.titleWork}
License of the work: ${skillFormData.licenseWork}
Expand All @@ -31,7 +27,7 @@ const DownloadAttribution: React.FC<Props> = ({ disableAction, skillFormData, se
};

return (
<DropdownItem key="DownloadAttribution" to="#default-link6" isDisabled={disableAction} onClick={handleDownloadAttribution}>
<DropdownItem key="DownloadAttribution" to="#default-link6" onClick={handleDownloadAttribution}>
<FileIcon /> Attribution File
</DropdownItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import { DropdownList } from '@patternfly/react-core/dist/dynamic/components/Dro
import { MenuToggle, MenuToggleElement } from '@patternfly/react-core/dist/dynamic/components/MenuToggle';
import DownloadYaml from '../DownloadYaml/DownloadYaml';
import DownloadAttribution from '../DownloadAttribution/DownloadAttribution';
import { ActionGroupAlertContent, SkillFormData } from '..';
import { SkillFormData } from '..';
import DownloadIcon from '@patternfly/react-icons/dist/esm/icons/download-icon';

interface Props {
disableAction: boolean;
skillFormData: SkillFormData;
setActionGroupAlertContent: React.Dispatch<React.SetStateAction<ActionGroupAlertContent | undefined>>;
githubUsername: string | undefined;
}

export const DownloadDropdown: React.FunctionComponent<Props> = ({ disableAction, skillFormData, setActionGroupAlertContent, githubUsername }) => {
export const DownloadDropdown: React.FunctionComponent<Props> = ({ skillFormData, githubUsername }) => {
const [isOpen, setIsOpen] = React.useState(false);

const onToggleClick = () => {
Expand All @@ -40,13 +38,8 @@ export const DownloadDropdown: React.FunctionComponent<Props> = ({ disableAction
shouldFocusToggleOnSelect
>
<DropdownList>
<DownloadYaml
disableAction={disableAction}
skillFormData={skillFormData}
setActionGroupAlertContent={setActionGroupAlertContent}
githubUsername={githubUsername}
/>
<DownloadAttribution disableAction={disableAction} skillFormData={skillFormData} setActionGroupAlertContent={setActionGroupAlertContent} />
<DownloadYaml skillFormData={skillFormData} githubUsername={githubUsername} />
<DownloadAttribution skillFormData={skillFormData} />
</DropdownList>
</Dropdown>
);
Expand Down
11 changes: 3 additions & 8 deletions src/components/Contribute/Skill/DownloadYaml/DownloadYaml.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import React from 'react';
import { validateFields } from '../validation';
import { ActionGroupAlertContent, SkillFormData } from '..';
import { SkillFormData } from '..';
import { SkillYamlData } from '@/types';
import { dumpYaml } from '@/utils/yamlConfig';
import { DropdownItem } from '@patternfly/react-core/dist/esm/components/Dropdown/DropdownItem';
import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon';
import { SkillSchemaVersion } from '@/types/const';

interface Props {
disableAction: boolean;
skillFormData: SkillFormData;
setActionGroupAlertContent: React.Dispatch<React.SetStateAction<ActionGroupAlertContent | undefined>>;
githubUsername: string | undefined;
}

const DownloadYaml: React.FC<Props> = ({ disableAction, skillFormData, setActionGroupAlertContent, githubUsername }) => {
const DownloadYaml: React.FC<Props> = ({ skillFormData, githubUsername }) => {
const handleDownloadYaml = () => {
if (!validateFields(skillFormData, setActionGroupAlertContent)) return;

const yamlData: SkillYamlData = {
created_by: githubUsername!,
version: SkillSchemaVersion,
Expand All @@ -40,7 +35,7 @@ const DownloadYaml: React.FC<Props> = ({ disableAction, skillFormData, setAction
document.body.removeChild(a);
};
return (
<DropdownItem key="Download Yaml" to="#default-link6" isDisabled={disableAction} onClick={handleDownloadYaml}>
<DropdownItem key="Download Yaml" to="#default-link6" onClick={handleDownloadYaml}>
<CodeIcon /> Yaml File
</DropdownItem>
);
Expand Down
7 changes: 3 additions & 4 deletions src/components/Contribute/Skill/ViewDropdown/ViewDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import FileIcon from '@patternfly/react-icons/dist/dynamic/icons/file-icon';
import EyeIcon from '@patternfly/react-icons/dist/esm/icons/eye-icon';

interface Props {
disableAction: boolean;
skillFormData: SkillFormData;
githubUsername: string | undefined;
}

export const ViewDropdown: React.FunctionComponent<Props> = ({ disableAction, skillFormData, githubUsername }) => {
export const ViewDropdown: React.FunctionComponent<Props> = ({ skillFormData, githubUsername }) => {
const [isOpen, setIsOpen] = useState<boolean>(false);
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const [modalContent, setModalContent] = useState<string>('');
Expand Down Expand Up @@ -77,10 +76,10 @@ export const ViewDropdown: React.FunctionComponent<Props> = ({ disableAction, sk
shouldFocusToggleOnSelect
>
<DropdownList>
<DropdownItem key="view yaml" isDisabled={disableAction} onClick={handleViewYaml}>
<DropdownItem key="view yaml" onClick={handleViewYaml}>
<CodeIcon /> YAML Content
</DropdownItem>
<DropdownItem key="view yaml" isDisabled={disableAction} onClick={handleViewAttribution}>
<DropdownItem key="view yaml" onClick={handleViewAttribution}>
<FileIcon /> Attribution Content
</DropdownItem>
</DropdownList>
Expand Down
9 changes: 2 additions & 7 deletions src/components/Contribute/Skill/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,8 @@ export const SkillForm: React.FunctionComponent<SkillFormProps> = ({ skillEditFo
resetForm={resetForm}
/>
)}
<DownloadDropdown
disableAction={disableAction}
skillFormData={skillFormData}
setActionGroupAlertContent={setActionGroupAlertContent}
githubUsername={githubUsername}
/>
<ViewDropdown disableAction={disableAction} skillFormData={skillFormData} githubUsername={githubUsername} />
<DownloadDropdown skillFormData={skillFormData} githubUsername={githubUsername} />
<ViewDropdown skillFormData={skillFormData} githubUsername={githubUsername} />
<Button variant="link" type="button" onClick={handleCancel}>
Cancel
</Button>
Expand Down

0 comments on commit b782678

Please sign in to comment.