import * as React from "react"; import Box from "@mui/material/Box"; import Stepper from "@mui/material/Stepper"; import Step from "@mui/material/Step"; import StepLabel from "@mui/material/StepLabel"; import Button from "@mui/material/Button"; import Typography from "@mui/material/Typography"; import { inputProps } from "../interface/inputfieldProps"; import { JsonFormsDispatch, useJsonForms, withJsonFormsControlProps, } from "@jsonforms/react"; import { useContext } from "react"; import { DataContext } from "../context/Context"; import RadioButtonCheckedIcon from "@mui/icons-material/RadioButtonChecked"; import CheckCircleIcon from "@mui/icons-material/CheckCircle"; import PendingIcon from "@mui/icons-material/Pending"; import _ from "lodash"; import { StepContent, Tooltip } from "@mui/material"; import ComponentWrapper from "../common/ComponentWrapper"; import { getComponentProps } from "../common/getComponentProps"; import { getFieldName } from "../permissions/getFieldName"; const ImpaktAppsStepper = React.memo(function (props: inputProps) { const { data, enabled, uischema, path, schema, rootSchema, renderers, cells, } = props; const uischemaData = uischema?.config?.main; const [labels, setLabels] = React.useState(data?.steps || uischemaData.steps); const [activeStep, setActiveStep] = React.useState(0); const [allowedStep, setallowedStep] = React.useState([]); React.useEffect(() => { if (data) { setActiveStep(data.active); setLabels(data.steps); } }, [data]); const handleNext = () => { setActiveStep((pre) => pre + 1); }; const handleBack = () => { setActiveStep((pre) => pre - 1); }; const handleReset = () => { setActiveStep(0); }; const ctx = useJsonForms(); const { theme, pageName, permissions, serviceProvider, setFormdata } = useContext(DataContext); const stepperHandler = (buttonType: string) => { serviceProvider( ctx, { ...uischemaData, [buttonType]: buttonType, onClick: buttonType, }, { event: { _reactName: buttonType }, path, ...uischemaData.additionalData, paramValue: { buttonType, handleNext, handleBack, handleReset, }, } ); }; function ColorlibStepIcon(props) { const { active, completed } = props; const icons = { 1: ( ), 2: ( ), 3: ( ), }; return ( <> {active && icons[2]} {completed && icons[1]} {!active && !completed && icons[3]} ); } const stepContentWithDispatch: React.FC = () => { const scopeArray: string[] = uischema.elements[allowedStep[activeStep]]?.scope?.split("/"); const actualElemPath: string = scopeArray?.[scopeArray?.length - 1] || undefined; const widget = _.cloneDeep(uischema.elements[allowedStep[activeStep]]); if (activeStep !== labels.length) { widget.config.main.additionalData = { ...widget?.config?.main?.additionalData, tableButtonPath: actualElemPath, }; } return (
{uischemaData.defaultButtonAvailable && (
)}
); }; const RenderCompletionContent = () => ( {uischemaData?.completeText ? ( {uischemaData.completeText} ) : ( All steps completed - you are finished )} {uischemaData?.resetButton && ( )} ); const fieldName = getFieldName(path); return ( {labels.map((item, index) => { const labelId = item?.id || index; allowedStep[index] = labelId; const label = item.label; const stepProps: { completed?: boolean } = {}; return ( {label} {uischemaData.orientation === "vertical" && ( {stepContentWithDispatch(0)} )} ); })} {activeStep === labels.length ? ( ) : ( <> {uischemaData.orientation !== "vertical" && ( {stepContentWithDispatch(0)} )} )} ); }); export default withJsonFormsControlProps(ImpaktAppsStepper);