diff --git a/deploy-web/src/components/newDeploymentWizard/ManifestEdit.tsx b/deploy-web/src/components/newDeploymentWizard/ManifestEdit.tsx index e17ca11f6..d6d6e13b7 100644 --- a/deploy-web/src/components/newDeploymentWizard/ManifestEdit.tsx +++ b/deploy-web/src/components/newDeploymentWizard/ManifestEdit.tsx @@ -324,10 +324,12 @@ export const ManifestEdit: React.FunctionComponent = ({ editedManifest, s {parsingError && {parsingError}} - - {selectedSdlEditMode === "yaml" && } - {selectedSdlEditMode === "builder" && } - + {selectedSdlEditMode === "yaml" && ( + + + + )} + {selectedSdlEditMode === "builder" && } {isDepositingDeployment && ( (({ sdlString, setEditedManifest }, ref) => { const [error, setError] = useState(null); const formRef = useRef(); - const [isLoading, setIsLoading] = useState(true); + const [isInit, setIsInit] = useState(false); const { control, trigger, watch, setValue } = useForm({ defaultValues: { services: [{ ...defaultService }] @@ -45,6 +46,11 @@ export const SdlBuilder = React.forwardRef(({ sdlStrin })); useEffect(() => { + const { unsubscribe } = watch(data => { + const sdl = generateSdl({ services: data.services as Service[] }); + setEditedManifest(sdl); + }); + try { const services = createAndValidateSdl(sdlString); setValue("services", services as Service[]); @@ -52,17 +58,10 @@ export const SdlBuilder = React.forwardRef(({ sdlStrin setError("Error importing SDL"); } - setIsLoading(false); - }, []); - - useEffect(() => { - const subscription = watch(data => { - const sdl = generateSdl({ services: data.services as Service[] }); - setEditedManifest(sdl); - }); + setIsInit(true); return () => { - subscription.unsubscribe(); + unsubscribe(); }; }, [watch]); @@ -101,8 +100,8 @@ export const SdlBuilder = React.forwardRef(({ sdlStrin }; return ( - <> - {isLoading ? ( + + {!isInit ? ( @@ -138,6 +137,6 @@ export const SdlBuilder = React.forwardRef(({ sdlStrin )} - + ); }); diff --git a/deploy-web/src/components/newDeploymentWizard/TemplateList.tsx b/deploy-web/src/components/newDeploymentWizard/TemplateList.tsx index 8c758a71b..330381b96 100644 --- a/deploy-web/src/components/newDeploymentWizard/TemplateList.tsx +++ b/deploy-web/src/components/newDeploymentWizard/TemplateList.tsx @@ -34,9 +34,10 @@ const previewTemplateIds = [ type Props = { setSelectedTemplate: Dispatch; + setEditedManifest: Dispatch; }; -export const TemplateList: React.FunctionComponent = ({ setSelectedTemplate }) => { +export const TemplateList: React.FunctionComponent = ({ setSelectedTemplate, setEditedManifest }) => { const { templates } = useTemplates(); const { classes } = useStyles(); const router = useRouter(); @@ -52,6 +53,7 @@ export const TemplateList: React.FunctionComponent = ({ setSelectedTempla function selectTemplate(template) { setSelectedTemplate(template); + setEditedManifest(template.content); router.push(UrlService.newDeployment({ step: RouteStepKeys.editDeployment })); } @@ -71,6 +73,7 @@ export const TemplateList: React.FunctionComponent = ({ setSelectedTempla description: "Custom uploaded file", content: event.target.result as string }); + setEditedManifest(event.target.result as string); router.push(UrlService.newDeployment({ step: RouteStepKeys.editDeployment })); }; diff --git a/deploy-web/src/pages/new-deployment/index.tsx b/deploy-web/src/pages/new-deployment/index.tsx index 6ea7263d8..2f9122583 100644 --- a/deploy-web/src/pages/new-deployment/index.tsx +++ b/deploy-web/src/pages/new-deployment/index.tsx @@ -54,9 +54,11 @@ const NewDeploymentPage: React.FunctionComponent = ({}) => { if (redeployTemplate) { // If it's a redeploy, set the template from local storage setSelectedTemplate(redeployTemplate); + setEditedManifest(redeployTemplate.content); } else if (galleryTemplate) { // If it's a deploy from the template gallery, load from template data setSelectedTemplate(galleryTemplate as TemplateCreation); + setEditedManifest(galleryTemplate.content); } const _activeStep = getStepIndexByParam(router.query.step); @@ -68,10 +70,6 @@ const NewDeploymentPage: React.FunctionComponent = ({}) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [router.query, templates]); - useEffect(() => { - setEditedManifest(selectedTemplate?.content || ""); - }, [selectedTemplate]); - const getRedeployTemplate = () => { let template = null; if (router.query.redeploy) { @@ -148,7 +146,7 @@ const NewDeploymentPage: React.FunctionComponent = ({}) => { - {activeStep === 0 && setSelectedTemplate(c)} />} + {activeStep === 0 && } {activeStep === 1 && } {activeStep === 2 && }