Skip to content

Commit

Permalink
Merge pull request #290 from orppst/287-expose-proposal-clone-functio…
Browse files Browse the repository at this point in the history
…nality-in-the-gui

Clone functionality now in GUI
  • Loading branch information
DJWalker42 authored Dec 13, 2024
2 parents e13dd7e + a7ef4e3 commit 10e8fc5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
66 changes: 46 additions & 20 deletions src/main/webui/src/ProposalEditorView/proposal/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useNavigate, useParams} from 'react-router-dom'
import {
fetchProposalResourceCloneObservingProposal,
fetchProposalResourceDeleteObservingProposal,
useProposalResourceGetObservingProposal,
useSupportingDocumentResourceGetSupportingDocuments,
Expand All @@ -12,7 +13,7 @@ import {
Group,
List, Stack,
Table,
Text
Text,
} from '@mantine/core';
import {
CalibrationObservation,
Expand All @@ -21,9 +22,9 @@ import {
RealQuantity, Target,
} from 'src/generated/proposalToolSchemas.ts';
import { IconNorthStar } from '@tabler/icons-react';
import { ReactElement, useRef } from 'react';
import {ReactElement, useRef} from 'react';
import downloadProposal from './downloadProposal.tsx';
import { DIMMED_FONT_WEIGHT, JSON_SPACES } from 'src/constants.tsx';
import {DIMMED_FONT_WEIGHT, JSON_SPACES} from 'src/constants.tsx';
import { TargetTable } from '../targets/TargetTable.tsx';
import { TechnicalGoalsTable } from '../technicalGoals/technicalGoalTable.tsx';
import {PreviewJustification} from "../justifications/justification.preview.tsx";
Expand All @@ -34,6 +35,7 @@ import DeleteButton from "../../commonButtons/delete.tsx";
import {PanelFrame, PanelHeader} from "../../commonPanel/appearance.tsx";
import {ExportButton} from "../../commonButtons/export.tsx";
import {modals} from "@mantine/modals";
import CloneButton from "../../commonButtons/clone.tsx";

/*
title -- string
Expand All @@ -58,9 +60,6 @@ import {modals} from "@mantine/modals";
General strategy:
list of strings use a List
list of objects use an Accordion
TODO: provide a means to download the 'proposal' as a zipped/tar balled file containing a PDF
of the overview plus the supporting document files
*/


Expand Down Expand Up @@ -513,6 +512,27 @@ function OverviewPanel(props: {forceUpdate: () => void}): ReactElement {
}





/**
* add download button for the proposal to be extracted as a tar ball.
*
* @return {ReactElement} the html which contains the download button.
* @constructor
*/
const ExportProposal = (): ReactElement => {
return ExportButton(
{
toolTipLabel: `Export to a file for download`,
disabled: false,
onClick: handleDownloadPdf,
label: "Export Proposal",
variant: "filled",
toolTipLabelPosition: "top"
});
}

/**
* generates the overview pdf and saves it to the users disk.
*
Expand Down Expand Up @@ -543,23 +563,27 @@ function OverviewPanel(props: {forceUpdate: () => void}): ReactElement {
}
};


/**
* add download button for the proposal to be extracted as a tar ball.
*
* @return {ReactElement} the html which contains the download button.
* @constructor
*/
const ExportProposal = (): ReactElement => {
return ExportButton(
const CloneProposal = (): ReactElement => {
return CloneButton(
{
toolTipLabel: `Export to a file for download`,
toolTipLabel: `creates a new proposal from a deep copy of this proposal`,
disabled: false,
onClick: handleDownloadPdf,
label: "Export Proposal",
onClick: handleCloneProposal,
label: "Clone proposal",
variant: "filled",
toolTipLabelPosition: "top"
});
}
)
}

const handleCloneProposal = (): void => {
fetchProposalResourceCloneObservingProposal({
pathParams: {proposalCode: Number(selectedProposalCode)}
})
.then(() => props.forceUpdate())
.then(() => notifySuccess("Clone Proposal Successful",
"you should now change the title of the cloned proposal to something more meaningful"))
.catch(error => notifyError("Clone Proposal Failed", getErrorMessage(error)));
}

const DeleteProposal = () : ReactElement => {
Expand All @@ -569,7 +593,8 @@ function OverviewPanel(props: {forceUpdate: () => void}): ReactElement {
disabled: false,
onClick: confirmDeleteProposal,
label: "Delete Proposal",
variant: "outline"
variant: "outline",
toolTipLabelPosition: "top"
}
)
}
Expand Down Expand Up @@ -625,6 +650,7 @@ function OverviewPanel(props: {forceUpdate: () => void}): ReactElement {
<Fieldset legend={"Proposal Services"}>
<Group grow>
<ExportProposal/>
<CloneProposal/>
<DeleteProposal/>
</Group>
</Fieldset>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webui/src/commonButtons/export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ExportButton(props: ClickButtonInterfaceProps) : ReactElement {
>
<Button
rightSection={<IconDownload size={ICON_SIZE}/>}
color={"blue.7"}
color={"grape.7"}
variant={props.variant ?? "subtle"}
onClick={props.onClick === undefined? props.onClickEvent : props.onClick}
disabled={props.disabled}>
Expand Down

0 comments on commit 10e8fc5

Please sign in to comment.