-
Notifications
You must be signed in to change notification settings - Fork 2
IS-11570 Add browser back/forward navigation to the HAAPI stepper #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aleixsuau
wants to merge
9
commits into
dev
Choose a base branch
from
feature/dev/IS-11570-haapi-stepper-history-navigation
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6609491
IS-11570 Add browser back/forward navigation to the HAAPI stepper.
aleixsuau 303e531
IS-11570 Mount HaapiStepperHistoryNavigation in the app.
aleixsuau 695cb32
IS-11570 Document what a non-reproducible step is.
aleixsuau 88fea55
Potential fix for pull request finding
aleixsuau b105f28
Improve navigation history docs
aleixsuau ff50345
IS-11570 Skip recording polling steps to avoid flooding browser history.
aleixsuau 439fb03
IS-11570 Fix stray brace left by the autofix commit.
aleixsuau cc90482
IS-11570 Mark R1 first-step-back test as skipped (deferred; sentinel …
aleixsuau fcfac34
IS-11570 Drop the deferred R1 first-step-back test (a comment documen…
aleixsuau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/haapi-react-app/src/shared/feature/history/HaapiStepperHistoryNavigation.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright (C) 2026 Curity AB. All rights reserved. | ||
| * | ||
| * The contents of this file are the property of Curity AB. | ||
| * You may not copy or use this file, in either source code | ||
| * or executable form, except in compliance with terms | ||
| * set by Curity AB. | ||
| * | ||
| * For further information, please contact Curity AB. | ||
| */ | ||
|
|
||
| import { useHaapiStepperHistoryNavigation } from './useHaapiStepperHistoryNavigation'; | ||
|
|
||
| /** | ||
| * Headless component that wires the browser's back/forward buttons to the HAAPI stepper history. | ||
| * Must be rendered inside `<HaapiStepper>` so it can access the stepper via `useHaapiStepper`. | ||
| */ | ||
| export function HaapiStepperHistoryNavigation() { | ||
| useHaapiStepperHistoryNavigation(); | ||
| return null; | ||
| } |
68 changes: 68 additions & 0 deletions
68
src/haapi-react-app/src/shared/feature/history/reproducible-action.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Copyright (C) 2026 Curity AB. All rights reserved. | ||
| * | ||
| * The contents of this file are the property of Curity AB. | ||
| * You may not copy or use this file, in either source code | ||
| * or executable form, except in compliance with terms | ||
| * set by Curity AB. | ||
| * | ||
| * For further information, please contact Curity AB. | ||
| */ | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
| import { HAAPI_ACTION_TYPES } from '@curity/haapi-react-sdk/haapi-stepper/data-access/types/haapi-action.types'; | ||
| import { HTTP_METHODS } from '@curity/haapi-react-sdk/haapi-stepper/data-access/types/haapi-form.types'; | ||
| import { | ||
| HAAPI_STEPPER_ELEMENT_TYPES, | ||
| HAAPI_STEPS, | ||
| } from '@curity/haapi-react-sdk/haapi-stepper/data-access/types/haapi-step.types'; | ||
| import type { | ||
| HaapiStepperClientOperationAction, | ||
| HaapiStepperFormAction, | ||
| HaapiStepperHistoryEntry, | ||
| HaapiStepperLink, | ||
| HaapiStepperNextStepAction, | ||
| } from '@curity/haapi-react-sdk/haapi-stepper/feature/stepper/haapi-stepper.types'; | ||
| import { isReproducibleAction, isReproducibleHistoryEntry } from './reproducible-action'; | ||
|
|
||
| const link = { href: '/next', type: HAAPI_STEPPER_ELEMENT_TYPES.LINK } as HaapiStepperLink; | ||
| const formWith = (method: HTTP_METHODS) => | ||
| ({ template: HAAPI_ACTION_TYPES.FORM, model: { method } }) as HaapiStepperFormAction; | ||
| const clientOperation = { template: HAAPI_ACTION_TYPES.CLIENT_OPERATION } as HaapiStepperClientOperationAction; | ||
|
|
||
| describe('isReproducibleAction', () => { | ||
| it('treats links as reproducible (always GET)', () => { | ||
| expect(isReproducibleAction(link)).toBe(true); | ||
| }); | ||
|
|
||
| it('treats GET form actions as reproducible', () => { | ||
| expect(isReproducibleAction(formWith(HTTP_METHODS.GET))).toBe(true); | ||
| }); | ||
|
|
||
| it('treats POST form actions as not reproducible', () => { | ||
| expect(isReproducibleAction(formWith(HTTP_METHODS.POST))).toBe(false); | ||
| }); | ||
|
|
||
| it('treats client operations as not reproducible', () => { | ||
| expect(isReproducibleAction(clientOperation)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| const entryFor = (action: HaapiStepperNextStepAction, stepType?: HAAPI_STEPS): HaapiStepperHistoryEntry => | ||
| ({ step: { type: stepType }, triggeredByAction: action, timestamp: new Date() }) as HaapiStepperHistoryEntry; | ||
|
|
||
| describe('isReproducibleHistoryEntry', () => { | ||
| it('is reproducible when the entry was produced by a reproducible action', () => { | ||
| expect(isReproducibleHistoryEntry(entryFor(link))).toBe(true); | ||
| expect(isReproducibleHistoryEntry(entryFor(formWith(HTTP_METHODS.GET)))).toBe(true); | ||
| }); | ||
|
|
||
| it('is not reproducible when the entry was produced by a non-reproducible action', () => { | ||
| expect(isReproducibleHistoryEntry(entryFor(formWith(HTTP_METHODS.POST)))).toBe(false); | ||
| expect(isReproducibleHistoryEntry(entryFor(clientOperation))).toBe(false); | ||
| }); | ||
|
|
||
| it('is not reproducible for a polling step even though its poll action is a GET form', () => { | ||
| expect(isReproducibleHistoryEntry(entryFor(formWith(HTTP_METHODS.GET), HAAPI_STEPS.POLLING))).toBe(false); | ||
| }); | ||
| }); |
60 changes: 60 additions & 0 deletions
60
src/haapi-react-app/src/shared/feature/history/reproducible-action.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright (C) 2026 Curity AB. All rights reserved. | ||
| * | ||
| * The contents of this file are the property of Curity AB. | ||
| * You may not copy or use this file, in either source code | ||
| * or executable form, except in compliance with terms | ||
| * set by Curity AB. | ||
| * | ||
| * For further information, please contact Curity AB. | ||
| */ | ||
|
|
||
| import { HAAPI_ACTION_TYPES } from '@curity/haapi-react-sdk/haapi-stepper/data-access/types/haapi-action.types'; | ||
| import { HTTP_METHODS } from '@curity/haapi-react-sdk/haapi-stepper/data-access/types/haapi-form.types'; | ||
| import { HAAPI_STEPS } from '@curity/haapi-react-sdk/haapi-stepper/data-access/types/haapi-step.types'; | ||
| import type { | ||
| HaapiStepperHistoryEntry, | ||
| HaapiStepperNextStepAction, | ||
| HaapiStepperNextStepPayload, | ||
| } from '@curity/haapi-react-sdk/haapi-stepper/feature/stepper/haapi-stepper.types'; | ||
|
|
||
| /** A reproducible step: the action (and payload) that re-opens it when navigating back/forward. */ | ||
| export interface ReproducibleStep { | ||
| action: HaapiStepperNextStepAction; | ||
| payload?: HaapiStepperNextStepPayload; | ||
| } | ||
|
|
||
| /** | ||
| * Whether an action can be safely re-issued to reconstruct the step it produced when navigating the | ||
| * history — i.e. whether the step it produced is a reproducible back/forward target: | ||
| * - **Links** are always GET → reproducible. | ||
| * - **Form actions** are reproducible only when their method is GET (a POST may have mutated backend | ||
| * state or consumed a one-time token). | ||
| * - **Client operations** (BankID, WebAuthn, external-browser-flow) resolve to single-use POST | ||
| * continue-actions → never reproducible. | ||
| * | ||
| * Steps produced by non-reproducible actions are still recorded, but are skipped when navigating back/forward. | ||
| */ | ||
| export function isReproducibleAction(action: HaapiStepperNextStepAction): boolean { | ||
| if ('href' in action) { | ||
| return true; | ||
| } | ||
|
|
||
| if (action.template === HAAPI_ACTION_TYPES.FORM) { | ||
| return action.model.method === HTTP_METHODS.GET; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Whether the step recorded in a history entry can be safely re-opened — i.e. whether the action that | ||
| * produced it is reproducible (see {@link isReproducibleAction}). | ||
| */ | ||
| export function isReproducibleHistoryEntry(entry: HaapiStepperHistoryEntry): boolean { | ||
| if (entry.step.type === HAAPI_STEPS.POLLING) { | ||
| return false; | ||
| } | ||
|
|
||
| return isReproducibleAction(entry.triggeredByAction); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.