diff --git a/frontend/src/components/CommitCard.tsx b/frontend/src/components/CommitCard.tsx index ab2e2443..ef3dfe51 100644 --- a/frontend/src/components/CommitCard.tsx +++ b/frontend/src/components/CommitCard.tsx @@ -16,7 +16,7 @@ import { Card, CardProps } from "react-daisyui"; export type ICommitCardProps = CardProps & { commit: ICommit; onActivate?: (commit: ICommit) => void; - onDeleteRequested?: (id: string) => void; + onDeleteRequested?: (section: ISection) => void; }; export default (props: ICommitCardProps) => { @@ -33,14 +33,17 @@ export default (props: ICommitCardProps) => { onClick={(e) => { e.stopPropagation(); if (props.onDeleteRequested) - return props.onDeleteRequested(props.commit.id); + return props.onDeleteRequested( + props.commit.section + ); }} className="px-1" icon={faTrashCan} /> - {props.commit.packages.length} packages + {props.commit.packages.length} package + {props.commit.packages.length == 1 ? "" : "s"} diff --git a/frontend/src/components/CommitDrawer.tsx b/frontend/src/components/CommitDrawer.tsx new file mode 100644 index 00000000..3fb5040f --- /dev/null +++ b/frontend/src/components/CommitDrawer.tsx @@ -0,0 +1,54 @@ +import { Button, Drawer, DrawerProps, Menu } from "react-daisyui"; +import CommitCard from "./CommitCard"; + +type CommitDrawerProps = DrawerProps & { + isOpen: boolean; + commits: ICommit[]; + onPush: (commits: ICommit[]) => void; + onCardActivate: (commit: ICommit) => void; + onCardDelete: (section: ISection) => void; +}; + +export default (props: CommitDrawerProps) => { + return ( + 0 && props.isOpen} + contentClassName="fm-content h-full" + className="h-full" + side={ +
+ + +
  • + Pending commits +
  • + {props.commits?.map((value) => { + return ( + + + + ); + })} +
    + +
    +
    + } + end={true} + /> + ); +}; diff --git a/frontend/src/components/CommitModal.tsx b/frontend/src/components/CommitModal.tsx index 5c5f573f..9ab654a0 100644 --- a/frontend/src/components/CommitModal.tsx +++ b/frontend/src/components/CommitModal.tsx @@ -13,34 +13,32 @@ import { } from "@fortawesome/free-solid-svg-icons"; import { toast } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; -import * as uuid from "uuid"; import { forwardRef, useCallback, useEffect, useState } from "react"; import { createPortal } from "react-dom"; import SectionSelect from "./SectionSelect"; +import Dropzone from "react-dropzone"; export type CommitModalProps = ModalProps & { isNew?: boolean; commit?: ICommit; sections?: ISection[]; onCommitSubmit?: (commit: ICommit) => void; - onCommitDelete?: (id: string) => void; + onCommitDelete?: (section: ISection) => void; + onPackageDrop?: (files: File[]) => void; }; export default forwardRef( (props: CommitModalProps, ref) => { const [commit, setCommit] = useState( - props.commit || { id: uuid.v4(), section: {}, packages: [] } + props.commit || { section: {}, packages: [] } ); useEffect( - () => - setCommit( - props.commit || { id: uuid.v4(), section: {}, packages: [] } - ), + () => setCommit(props.commit || { section: {}, packages: [] }), [props.commit] ); - const { id, section, packages } = commit; + const { section, packages } = commit; const { branch, repository, architecture } = section; @@ -55,57 +53,66 @@ export default forwardRef( Commit - -
    - - { - setCommit({ ...commit, section: section }); - }} - /> - + + {({ getRootProps, getInputProps }) => ( + + + + + { + setCommit({ + ...commit, + section: section + }); + }} + /> + - - - Name - - - - {props.commit?.packages.map((value) => { - return ( - - - - {value.signatureFile !== - undefined && ( - - )} - - {value.name} - - - - ); - })} - -
    - -
    + + + Name + + + + {props.commit?.packages.map((value) => { + return ( + + + + {value.signatureFile !== + undefined && ( + + )} + {value.name} + + + + ); + })} + +
    + +
    + )} +
    {props.isNew && ( @@ -118,7 +125,7 @@ export default forwardRef( } onClick={(e) => { if (props.onCommitDelete) - props.onCommitDelete(commit.id); + props.onCommitDelete(commit.section); }} type="button" color="error" diff --git a/frontend/src/definitions/commit.d.ts b/frontend/src/definitions/commit.d.ts index 3a39c60d..395f8b40 100644 --- a/frontend/src/definitions/commit.d.ts +++ b/frontend/src/definitions/commit.d.ts @@ -5,7 +5,6 @@ * */ interface ICommit { - id: string; section: ISection; packages: IPackageUpload[]; } diff --git a/frontend/src/pages/FileViewPage.tsx b/frontend/src/pages/FileViewPage.tsx index fa2cf302..59f1968e 100644 --- a/frontend/src/pages/FileViewPage.tsx +++ b/frontend/src/pages/FileViewPage.tsx @@ -11,8 +11,7 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { usePushCommitsHandler, useSections } from "../hooks/BxtHooks"; import Dropzone from "react-dropzone"; import CommitModal from "../components/CommitModal"; -import { Button, Drawer, Menu } from "react-daisyui"; -import CommitCard from "../components/CommitCard"; +import { Button } from "react-daisyui"; import { useFilesFromSections } from "../hooks/BxtFsHooks"; import { toast } from "react-toastify"; import SnapshotModal, { @@ -21,6 +20,9 @@ import SnapshotModal, { import { SnapshotAction, SnapToAction } from "../components/SnapshotAction"; import PackageModal, { PackageModalProps } from "../components/PackageModal"; import _ from "lodash"; +import CommitDrawer from "../components/CommitDrawer"; +import { faCodeCommit } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useFileActionHandler, useFolderChainForPath @@ -43,6 +45,18 @@ export default (props: any) => { useEffect(() => updateFiles(sections, path), [sections, path]); const [modalCommit, setModalCommit] = useState(); + + const appendModalCommit = useCallback( + (commit: ICommit) => { + if (modalCommit) { + setModalCommit({ + ...modalCommit, + packages: [...modalCommit?.packages, ...commit.packages] + }); + } + }, + [modalCommit, setModalCommit] + ); const commitModalRef = useRef(null); const [commits, setCommits] = useState([]); @@ -53,6 +67,8 @@ export default (props: any) => { const snapshotModalRef = useRef(null); const packageModalRef = useRef(null); + const [drawerOpened, setDrawerOpened] = useState(false); + const [snapshotModalProps, setSnapshotModalProps] = useState({ sections: sections @@ -79,15 +95,42 @@ export default (props: any) => { const openModalWithCommitHandler = (isNew: boolean) => { return (commit: ICommit) => { setIsCommitInModalNew(isNew); + + const currentCommit = commits.find((value) => + _.isEqual(value.section, commit.section) + ); + if (currentCommit) { + commit.packages = [ + ...currentCommit.packages, + ...commit.packages + ]; + } setModalCommit(commit); commitModalRef.current?.showModal(); }; }; - const deleteCommitById = (id: string) => { + const deleteCommitBySection = (section: ISection) => { + setCommits( + commits.filter((value) => _.isEqual(value.section, section)) + ); + commitModalRef.current?.close(); toast.success("Deleted!"); - setCommits(commits.filter((value) => value.id != id)); + }; + + const appendCommit = (commit: ICommit) => { + const currentCommit = commits.find((value) => + _.isEqual(value.section, commit.section) + ); + const currentCommits = commits.filter( + (value) => !_.isEqual(value.section, commit.section) + ); + if (currentCommit) { + commit.packages = [...currentCommit.packages, ...commit.packages]; + } + setCommits([...currentCommits, commit]); commitModalRef.current?.close(); + toast.success("Committed!"); }; const openSnapshotModalWithBranchHandler = useCallback( @@ -139,9 +182,18 @@ export default (props: any) => { commit={modalCommit} onCommitSubmit={(commit) => { commitModalRef.current?.close(); - setCommits([...commits, commit]); + appendCommit(commit); }} - onCommitDelete={deleteCommitById} + onCommitDelete={deleteCommitBySection} + onPackageDrop={usePackageDropHandler( + [ + "root", + modalCommit?.section?.branch!, + modalCommit?.section?.repository!, + modalCommit?.section?.architecture! + ], + appendModalCommit + )} /> { backdrop={true} /> - 0} - contentClassName="fm-content h-full" - className="h-full" - side={ -
    - - -
  • - Pending commits -
  • - {commits?.map((value) => { - return ( - - - - ); - })} -
    - -
    -
    - } - end={true} + { + setCommits([]); + updateSections(); + })} + onCardActivate={openModalWithCommitHandler(true)} + onCardDelete={deleteCommitBySection} + side={true} + onClickOverlay={() => setDrawerOpened(false)} > { )} -
    + {commits.length > 0 && ( + + )} + ); };