Skip to content

Commit

Permalink
[#open-formulieren/open-forms#3835] Process PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Feb 9, 2024
1 parent 5caec81 commit da1c668
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
9 changes: 9 additions & 0 deletions src/api-mocks/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ const SUBMISSION_DETAILS = {
completed: false,
canSubmit: true,
},
{
id: 'a0ff2cfe-e59a-4881-88de-e1b0a76af8d3',
name: 'Step 2',
url: `${BASE_URL}submissions/458b29ae-5baa-4132-a0d7-8c7071b8152a/steps/98980oi8-e5a4-4abf-b64a-76j3j3ki897`,
formStep: `${BASE_URL}forms/mock/steps/98980oi8-e5a4-4abf-b64a-76j3j3ki897`,
isApplicable: false,
completed: false,
canSubmit: false,
},
],
submissionAllowed: 'yes',
isAuthenticated: false,
Expand Down
36 changes: 35 additions & 1 deletion src/components/App.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {
uuid: '98980oi8-e5a4-4abf-b64a-76j3j3ki897',
slug: 'step-2',
formDefinition: 'Step 2',
index: 0,
index: 1,
literals: {
previousText: {resolved: 'Previous', value: ''},
saveText: {resolved: 'Save', value: ''},
Expand Down Expand Up @@ -203,6 +203,40 @@ export const ActiveSubmission = {
},
};

export const NonApplicableStepActiveSubmission = {
...Default,
name: 'Active submission with non-applicable step hidden',
args: {
hideNonApplicableSteps: true,
},
argTypes: {
submissionAllowed: {table: {disable: true}},
},
parameters: {
msw: {
handlers: [
mockSubmissionPost(),
mockSubmissionGet(),
mockSubmissionStepGet(),
mockSubmissionCheckLogicPost(),
mockLanguageInfoGet([
{code: 'nl', name: 'Nederlands'},
{code: 'en', name: 'English'},
]),
mockLanguageChoicePut,
mockAnalyticsToolConfigGet(),
],
},
},

play: async ({canvasElement}) => {
const canvas = within(canvasElement);

const beginButton = await canvas.findByRole('button', {name: 'Begin'});
await userEvent.click(beginButton);
},
};

export const SeveralStepsInMobileViewport = {
render,
args: {
Expand Down
33 changes: 9 additions & 24 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,31 +292,16 @@ const Form = () => {
{formName, activeStepTitle}
);

// Add slug and label to the submission steps.
// We need to show the items in the ProgressIndicator according to the
// submission data, as we may have logic rules which have been applied to them.
const updatedSubmissionSteps = submission?.steps.map(subStep => {
const updatedSubStep = {...subStep};

for (const formStep of steps) {
if (formStep.uuid === subStep.id) {
updatedSubStep['slug'] = formStep.slug;
updatedSubStep['formDefinition'] = formStep.formDefinition;
}
}
return updatedSubStep;
});
// process the form/submission steps information into step data that can be passed
// to the progress indicator.
// If the form is marked to not display non-applicable steps at all, filter them out.
const showNonApplicableSteps = !form.hideNonApplicableSteps;
const updatedSteps =
// first, process all the form steps in a format suitable for the PI
getStepsInfo(steps, submission, currentPathname)
// then, filter out the non-applicable steps if they should not be displayed
.filter(step => showNonApplicableSteps || step.isApplicable);

// Show only applicable steps when this is set in the admin.
let applicableSteps = form.hideNonApplicableSteps
? (updatedSubmissionSteps || steps).filter(step => step.isApplicable)
: [];

const updatedSteps = getStepsInfo(
applicableSteps.length > 0 ? applicableSteps : updatedSubmissionSteps || form.steps,
submission,
currentPathname
);
const stepsToRender = addFixedSteps(
intl,
updatedSteps,
Expand Down

0 comments on commit da1c668

Please sign in to comment.