From cebf0c3c1242aaee09e5d2f6b31ccd4aa2673b35 Mon Sep 17 00:00:00 2001 From: Antonio Sonis Date: Thu, 30 Nov 2023 20:13:54 +0100 Subject: [PATCH] feat: updating step for generating application Signed-off-by: Antonio Sonis --- .../steps/GeneratingApplication.jsx | 158 ++++++------------ .../steps/GeneratingApplication.module.css | 20 +-- 2 files changed, 54 insertions(+), 124 deletions(-) diff --git a/src/renderer/src/components/steps/GeneratingApplication.jsx b/src/renderer/src/components/steps/GeneratingApplication.jsx index fc65eb60..ce6a5b39 100644 --- a/src/renderer/src/components/steps/GeneratingApplication.jsx +++ b/src/renderer/src/components/steps/GeneratingApplication.jsx @@ -1,14 +1,14 @@ 'use strict' -import React, { useEffect } from 'react' +import React, { useEffect, useState } from 'react' import PropTypes from 'prop-types' import { BorderedBox, Button, Icons } from '@platformatic/ui-components' import commonStyles from '~/styles/CommonStyles.module.css' import typographyStyles from '~/styles/Typography.module.css' import styles from './GeneratingApplication.module.css' -import { MAIN_DARK_BLUE, WHITE, SMALL, MAIN_GREEN, TRANSPARENT, ERROR_RED, RICH_BLACK } from '@platformatic/ui-components/src/components/constants' +import { WHITE, TRANSPARENT, RICH_BLACK, OPACITY_30, OPACITY_100, SMALL } from '@platformatic/ui-components/src/components/constants' import useStackablesStore from '~/useStackablesStore' import Title from '~/components/ui/Title' -import { callCreateApp } from '~/api' +import { callCreateApp, logInfo } from '~/api' /* function dateDifferences(millisStartDate, millisEndDate) { const s = new Date(millisStartDate); @@ -20,120 +20,52 @@ import { callCreateApp } from '~/api' } */ // eslint-disable-next-line no-unused-vars -function StepCreation ({ step, index, concludedStep, /* startTime = 0, endTime = 0, */ indexError, externalUrl = '' }) { - let status = 'NOT_STARTED' - if (concludedStep >= 0) { - if (concludedStep >= index) { - status = 'COMPLETED' +function Step ({ label, index, currentStep }) { + const [active, setActive] = useState(false) + const [classNameLabel, setClassNameLabel] = useState(`${typographyStyles.desktopBody} ${typographyStyles.textWhite} ${typographyStyles.opacity70}`) + useEffect(() => { + if (currentStep === index) { + setActive(true) + setClassNameLabel(`${typographyStyles.desktopBody} ${typographyStyles.textWhite}`) } - } - - if (concludedStep + 1 === index) { - status = 'LOADING' - } - - let classes = `${commonStyles.mediumFlexRow} ${commonStyles.justifyBetween} ${commonStyles.smallPadding} ` - classes += concludedStep + 1 < index ? styles['apply-opacity-20'] : '' - - let cmp - - if (indexError === index) { - return ( - -
- - {step} - {externalUrl && Check progress} -
-
- Failed -
-
- ) - } - - switch (status) { - case 'LOADING': - cmp = ( - -
-
- {step} - {externalUrl && Check progress} -
-
- - Loading - -
-
- ) - break - - case 'COMPLETED': - cmp = ( - -
- - {step} -
-
- - Completed - -
-
- ) - break + }, [currentStep]) - default: - cmp = ( - -
- - {step} -
-
- - Not started - -
-
- ) - break - } - - return cmp + return ( + + {label} + {active ? : } + + ) } const GeneratingApplication = React.forwardRef(({ onClickComplete }, ref) => { const globalState = useStackablesStore() const { formData } = globalState + const [steps, setSteps] = useState([]) + const [currentStep, setCurrentStep] = useState() useEffect(() => { + if (formData.configuredServices.services) { + const tmpStep = [] + formData.configuredServices.services.forEach(service => { + tmpStep.push({ + label: `Generating ${service.name}`, + index: `${service.name}-${service.template}` + }) + }) + tmpStep.push({ label: 'App Created!', index: 'app-created' }) + setSteps([...tmpStep]) + } + }, [formData.configuredServices.services]) + + useEffect(() => { + logInfo((_, value) => setCurrentStep(value)) async function generateApplication () { try { const obj = { projectName: formData.createApplication.application, services: formData.configuredServices.services, ...formData.configureApplication } @@ -144,10 +76,9 @@ const GeneratingApplication = React.forwardRef(({ onClickComplete }, ref) => { } } generateApplication() - }, []) - + }, [steps.length > 0]) return ( -
+
{ We are generating your app. Once all the steps are done you will be able to complete and use your new application. </p> </div> + <div className={`${styles.content} ${commonStyles.halfWidth}`}> + <div className={`${commonStyles.smallFlexBlock} ${commonStyles.fullWidth}`}> + {steps.map(step => <Step {...step} key={step.index} currentStep={currentStep} />)} + </div> + </div> <div className={`${styles.buttonContainer} ${commonStyles.fullWidth}`}> <Button label='Complete' diff --git a/src/renderer/src/components/steps/GeneratingApplication.module.css b/src/renderer/src/components/steps/GeneratingApplication.module.css index 93117ab1..ec23f2c1 100644 --- a/src/renderer/src/components/steps/GeneratingApplication.module.css +++ b/src/renderer/src/components/steps/GeneratingApplication.module.css @@ -1,16 +1,10 @@ -.clockWiseRotation { - animation: rotationClockwise 2s infinite linear; +.content { + min-height: calc(100vH - 27rem); + max-height: calc(100vH - 27rem); } - -.apply-opacity-20 { - @apply opacity-20; +.buttonContainer { + @apply flex justify-end; } - -@keyframes rotationClockwise { - from { - transform: rotate(0deg); - } - to { - transform: rotate(359deg); - } +.paddingStep { + @apply p-4 } \ No newline at end of file