From c2e8ec78cd8f5fc560d68239117def89d366c7d8 Mon Sep 17 00:00:00 2001 From: Abhishek Katiyar Date: Wed, 15 Jul 2020 14:07:21 +0530 Subject: [PATCH] [infra-429] | Abhishek | Add support to create manifests by copying other manifests --- src/App.tsx | 11 ++++++--- src/components/manifest/Form.tsx | 23 +++++++++++++++++-- .../manifest/ShowDeploymentManifest.tsx | 3 +++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index fcb58dc..f1d2e85 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -50,16 +50,21 @@ function App() { -
- + /> + { const [formInitData, setFormInitData] = useState({}); const { cookies } = props; const manifestIdParam = props?.match?.params?.manifestId; + const isCopy = String(props.location.pathname).endsWith("copy"); const [csrfToken] = useState(cookies.get("XSRF-TOKEN")); const getManifestData = async (manifestId: number): Promise => { @@ -69,8 +70,26 @@ const Form = (props: any) => { }).then((res) => res.json()); }; + const getCopy = async (manifestId: number): Promise => { + console.log(`Fetching copy of manifest id ${manifestId}`); + return fetch(`/api/manifest/${manifestId}/copy`, { + method: "GET", + credentials: "include", + headers: { + "X-XSRF-TOKEN": props.csrfToken, + Accept: "application/json", + "Content-Type": "application/json", + }, + }).then((res) => res.json()); + }; + useEffect(() => { - if (manifestIdParam) { + if(isCopy) { + getCopy(manifestIdParam).then(res => { + setFormInitData(res); + }); + } + else if (manifestIdParam) { getManifestData(manifestIdParam).then((res) => { setFormInitData(res); }); @@ -103,7 +122,7 @@ const Form = (props: any) => { return (
diff --git a/src/components/manifest/ShowDeploymentManifest.tsx b/src/components/manifest/ShowDeploymentManifest.tsx index 60f9bf1..c0a16cf 100644 --- a/src/components/manifest/ShowDeploymentManifest.tsx +++ b/src/components/manifest/ShowDeploymentManifest.tsx @@ -46,6 +46,9 @@ export const PrettyPrintJson = (props: any) => { + ) : ( <>