Skip to content

Commit ebbc471

Browse files
authored
Merge pull request #919 from rvsia/inheritSubstepOfTitle
fix(pf4): inherit substepOfTitle in wizard
2 parents 262656a + 160b19f commit ebbc471

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

packages/common/src/wizard/reducer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const createSchema = ({ formOptions, fields }) => {
1616
name: field.name,
1717
title: field.title,
1818
substepOf: field.substepOf?.name || field.substepOf,
19-
substepOfTitle: field.substepOf?.title || field.substepOf,
19+
substepOfTitle:
20+
(field.substepOf === schema[schema.length - 1]?.substepOf && schema[schema.length - 1]?.substepOfTitle) ||
21+
field.substepOf?.title ||
22+
field.substepOf,
2023
index,
2124
primary: !schema[schema.length - 1] || !field.substepOf || field.substepOf !== schema[schema.length - 1].substepOf
2225
}

packages/pf4-component-mapper/src/tests/wizard/wizard.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as enterHandle from '@data-driven-forms/common/src/wizard/enter-handler
99

1010
import { componentMapper, FormTemplate } from '../../index';
1111
import reducer from '../../files/wizard/reducer';
12+
import commonReducer from '@data-driven-forms/common/src/wizard/reducer';
1213
import WizardToggle from '../../files/wizard/wizard-toggle';
1314

1415
describe('<Wizard />', () => {
@@ -1874,5 +1875,64 @@ describe('<Wizard />', () => {
18741875
const initialState = { openNav: false };
18751876
expect(reducer(initialState, { type: 'openNav' })).toEqual({ openNav: true });
18761877
});
1878+
1879+
it('common reducer - correctly assigns substepOf title when node', () => {
1880+
const initialState = {};
1881+
const formOptions = { getState: () => ({}) };
1882+
const customTitle = <span>Custom title</span>;
1883+
const fields = [
1884+
{
1885+
name: 'security',
1886+
title: 'Security',
1887+
nextStep: 'credentials',
1888+
substepOf: { name: 'Configuration', title: customTitle },
1889+
fields: []
1890+
},
1891+
{
1892+
name: 'credentials',
1893+
title: 'Credentials',
1894+
nextStep: 'summary',
1895+
substepOf: 'Configuration',
1896+
fields: []
1897+
},
1898+
{
1899+
name: 'summary',
1900+
title: 'Summary',
1901+
nextStep: 'pepa-step',
1902+
fields: []
1903+
},
1904+
{
1905+
name: 'pepa-step',
1906+
nextStep: 'pepa-step-2',
1907+
title: 'title',
1908+
substepOf: { name: 'pepa', title: 'pepa-title' },
1909+
fields: []
1910+
},
1911+
{
1912+
name: 'pepa-step-2',
1913+
title: 'title 2',
1914+
fields: [],
1915+
substepOf: 'pepa'
1916+
}
1917+
];
1918+
1919+
expect(commonReducer(initialState, { type: 'finishLoading', payload: { formOptions, fields } })).toEqual({
1920+
loading: false,
1921+
navSchema: [
1922+
{ index: 0, name: 'security', primary: true, substepOf: 'Configuration', substepOfTitle: customTitle, title: 'Security' },
1923+
{
1924+
index: 1,
1925+
name: 'credentials',
1926+
primary: false,
1927+
substepOf: 'Configuration',
1928+
substepOfTitle: customTitle,
1929+
title: 'Credentials'
1930+
},
1931+
{ index: 2, name: 'summary', primary: true, substepOf: undefined, substepOfTitle: undefined, title: 'Summary' },
1932+
{ index: 3, name: 'pepa-step', primary: true, substepOf: 'pepa', substepOfTitle: 'pepa-title', title: 'title' },
1933+
{ index: 4, name: 'pepa-step-2', primary: false, substepOf: 'pepa', substepOfTitle: 'pepa-title', title: 'title 2' }
1934+
]
1935+
});
1936+
});
18771937
});
18781938
});

0 commit comments

Comments
 (0)