Skip to content

Commit

Permalink
fix: the stepper header status in jsonforms
Browse files Browse the repository at this point in the history
  • Loading branch information
solittlework committed Jan 30, 2025
1 parent afc33ce commit 5fb34dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const FormStepperView = (props: CategorizationStepperLayoutRendererProps)
const submitForm = submitFormFunction && submitFormFunction();
const optionProps = (uischema.options as FormStepperOptionProps) || {};
const [isOpen, setIsOpen] = useState(false);
const [isSelected, setIsSelected] = useState(false);

const handleSubmit = () => {
if (submitForm) {
Expand All @@ -75,12 +76,12 @@ export const FormStepperView = (props: CategorizationStepperLayoutRendererProps)
<div data-testid="form-stepper-test-wrapper">
<Visible visible={visible}>
<div id={`${path || `goa`}-form-stepper`} className="formStepper">
{/* Need to force a refresh here, GoAFormStepper cant change dynamically unless completely re-rendered */}

<GoAFormStepper
testId={`form-stepper-headers-${uischema?.options?.testId}` || 'form-stepper-test'}
step={isSelected === false ? -1 : activeId + 1}
key="stepper-form-stepper-wrapper"
onChange={(step) => {
setIsSelected(true);
goToPage(step - 1);
}}
>
Expand Down Expand Up @@ -133,6 +134,7 @@ export const FormStepperView = (props: CategorizationStepperLayoutRendererProps)
if (element) {
element.scrollIntoView();
}

goToPage(activeId - 1, activeId);
}}
testId="prev-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const createStepperContextInitData = (
});

const activeId = props?.activeId || 0;
console.log(activeId);

return {
categories: categories,
Expand Down Expand Up @@ -82,7 +83,8 @@ export const JsonFormsStepperContextProvider = ({
return stepperState;
},
selectIsDisabled: () => {
return !stepperState.categories[stepperState.activeId]?.isEnabled;
const category = stepperState.categories?.[stepperState.activeId];
return category === undefined ? false : !category?.isEnabled;
},
selectIsActive: (id: number) => {
return id === stepperState.activeId;
Expand All @@ -96,7 +98,7 @@ export const JsonFormsStepperContextProvider = ({
goToPage: (id: number, updateCategoryId?: number) => {
ajv.validate(schema, ctx.core?.data || {});

if (updateCategoryId !== undefined) {
if (updateCategoryId !== undefined && updateCategoryId < stepperState.categories.length) {
stepperDispatch({
type: 'update/category',
payload: { errors: ctx?.core?.errors, id: updateCategoryId, ajv },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const stepperReducer = (state: StepperContextDataType, action: StepperAct
if (id > lastId) {
state.isOnReview = true;
state.hasNextButton = false;
state.hasPrevButton = false;
state.hasPrevButton = true;
return { ...state };
} else {
state.categories[id].isVisited = true;
Expand All @@ -77,6 +77,8 @@ export const stepperReducer = (state: StepperContextDataType, action: StepperAct
const errorsInCategory = getErrorsInScopes(errors, state.categories[id].scopes || []);
state.categories[id].isCompleted = incompletePaths?.length === 0;
state.categories[id].isValid = errorsInCategory.length === 0;
state.categories[id].isVisited = true;

return { ...state };
}
case 'validate/form': {
Expand Down

0 comments on commit 5fb34dd

Please sign in to comment.