mirror of
https://github.com/strapi/strapi.git
synced 2025-11-30 09:01:16 +00:00
Settings: Allow stages to be added even if the workflow doesn't have any yet
This commit is contained in:
parent
3db0779f8f
commit
932664a61f
@ -90,7 +90,7 @@ export function ReviewWorkflowsPage() {
|
||||
</Loader>
|
||||
)}
|
||||
|
||||
{formik.values?.stages && <Stages stages={formik.values.stages} />}
|
||||
<Stages stages={formik.values?.stages} />
|
||||
</ContentLayout>
|
||||
</Form>
|
||||
</FormikProvider>
|
||||
|
||||
@ -70,6 +70,7 @@ Stages.propTypes = {
|
||||
stages: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
id: PropTypes.number,
|
||||
__temp_key__: PropTypes.number,
|
||||
name: PropTypes.string.isRequired,
|
||||
})
|
||||
),
|
||||
|
||||
@ -56,13 +56,16 @@ export function reducer(state = initialState, action) {
|
||||
case ACTION_ADD_STAGE: {
|
||||
const { currentWorkflow } = state.clientState;
|
||||
|
||||
draft.clientState.currentWorkflow.data.stages = [
|
||||
...currentWorkflow.data.stages,
|
||||
{
|
||||
...payload,
|
||||
__temp_key__: currentWorkflow.data.stages.length + 1,
|
||||
},
|
||||
];
|
||||
if (!currentWorkflow.data) {
|
||||
draft.clientState.currentWorkflow.data = {
|
||||
stages: [],
|
||||
};
|
||||
}
|
||||
|
||||
draft.clientState.currentWorkflow.data.stages.push({
|
||||
...payload,
|
||||
__temp_key__: (currentWorkflow.data?.stages?.length ?? 0) + 1,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -133,6 +133,38 @@ describe('Admin | Settings | Review Workflows | reducer', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('ACTION_ADD_STAGE when there are not stages yet', () => {
|
||||
const action = {
|
||||
type: ACTION_ADD_STAGE,
|
||||
payload: { name: 'something' },
|
||||
};
|
||||
|
||||
state = {
|
||||
status: expect.any(String),
|
||||
serverState: expect.any(Object),
|
||||
clientState: {
|
||||
currentWorkflow: { data: null, isDirty: false },
|
||||
},
|
||||
};
|
||||
|
||||
expect(reducer(state, action)).toStrictEqual(
|
||||
expect.objectContaining({
|
||||
clientState: expect.objectContaining({
|
||||
currentWorkflow: expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
stages: expect.arrayContaining([
|
||||
{
|
||||
__temp_key__: 1,
|
||||
name: 'something',
|
||||
},
|
||||
]),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('ACTION_UPDATE_STAGE', () => {
|
||||
const action = {
|
||||
type: ACTION_UPDATE_STAGE,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user