diff --git a/web/packages/teleport/src/components/Wizard/Navigation/StepItem.tsx b/web/packages/teleport/src/components/Wizard/Navigation/StepItem.tsx index 4236d85471209..67e96bc14085f 100644 --- a/web/packages/teleport/src/components/Wizard/Navigation/StepItem.tsx +++ b/web/packages/teleport/src/components/Wizard/Navigation/StepItem.tsx @@ -57,7 +57,11 @@ export function StepItem(props: { return ( - + {props.view.title} diff --git a/web/packages/teleport/src/components/Wizard/flow.test.tsx b/web/packages/teleport/src/components/Wizard/flow.test.tsx index b89b884007d71..2ffcdc597744d 100644 --- a/web/packages/teleport/src/components/Wizard/flow.test.tsx +++ b/web/packages/teleport/src/components/Wizard/flow.test.tsx @@ -42,9 +42,11 @@ test('computeViewChildrenSize', async () => { }, { title: 'Banana', + hide: true, }, ]; expect(computeViewChildrenSize(nestedViews)).toBe(3); + expect(computeViewChildrenSize(nestedViews, true)).toBe(2); const notNestedViews = [ { diff --git a/web/packages/teleport/src/components/Wizard/flow.tsx b/web/packages/teleport/src/components/Wizard/flow.tsx index c00f4d16ba7d4..59c9553d29e42 100644 --- a/web/packages/teleport/src/components/Wizard/flow.tsx +++ b/web/packages/teleport/src/components/Wizard/flow.tsx @@ -17,8 +17,12 @@ */ export type BaseView = T & { + // whether to hide the view from the list of views hide?: boolean; + // current step index in the wizard index?: number; + // current visible step index in the wizard (ignoring hidden steps) + displayIndex?: number; views?: BaseView[]; title: string; }; @@ -26,15 +30,24 @@ export type BaseView = T & { /** * computeViewChildrenSize calculates how many children a view has, without counting the first * child. This is because the first child shares the same index with its parent, so we don't - * need to count it as it's not taking up a new index + * need to count it as it's not taking up a new index. + * + * If `constrainToVisible` is true, then we only count the visible views. */ -export function computeViewChildrenSize(views: BaseView[]) { +export function computeViewChildrenSize( + views: BaseView[], + constrainToVisible = false +) { let size = 0; for (const view of views) { + if (constrainToVisible && view.hide) { + continue; + } + if (view.views) { - size += computeViewChildrenSize(view.views); + size += computeViewChildrenSize(view.views, constrainToVisible); } else { - size += 1; + size++; } } @@ -48,7 +61,8 @@ export function computeViewChildrenSize(views: BaseView[]) { */ export function addIndexToViews( views: BaseView[], - index = 0 + index = 0, + displayIndex = 1 ): BaseView[] { const result: BaseView[] = []; @@ -60,11 +74,17 @@ export function addIndexToViews( }; if (view.views) { - copy.views = addIndexToViews(view.views, index); - + copy.views = addIndexToViews(view.views, index, displayIndex); index += computeViewChildrenSize(view.views); } else { - index += 1; + index++; + } + + if (!view.hide) { + copy.displayIndex = displayIndex; + displayIndex += view.views + ? computeViewChildrenSize(view.views, true) + : 1; } result.push(copy);