mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
Merge pull request #6053 from strapi/fix/ctb-default-date-input
Fix/ctb default date input
This commit is contained in:
commit
d91c5f19c5
@ -40,6 +40,16 @@ const reducer = (state, action) => {
|
|||||||
value,
|
value,
|
||||||
oneThatIsCreatingARelationWithAnother,
|
oneThatIsCreatingARelationWithAnother,
|
||||||
} = action;
|
} = action;
|
||||||
|
const hasDefaultValue = Boolean(obj.getIn(['default']));
|
||||||
|
|
||||||
|
// There is no need to remove the default key if the default value isn't defined
|
||||||
|
if (hasDefaultValue && keys.length === 1 && keys.includes('type')) {
|
||||||
|
const previousType = obj.getIn(['type']);
|
||||||
|
|
||||||
|
if (previousType && ['date', 'datetime', 'time'].includes(previousType)) {
|
||||||
|
return obj.updateIn(keys, () => value).remove('default');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (keys.length === 1 && keys.includes('nature')) {
|
if (keys.length === 1 && keys.includes('nature')) {
|
||||||
return obj
|
return obj
|
||||||
|
@ -217,6 +217,49 @@ describe('CTB | containers | FormModal | reducer | actions', () => {
|
|||||||
|
|
||||||
expect(reducer(state, action)).toEqual(expected);
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should remove the default value if the type of date input type has been changed', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'short_movie_time',
|
||||||
|
type: 'time',
|
||||||
|
default: '00:30:00',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: 'ON_CHANGE',
|
||||||
|
keys: ['type'],
|
||||||
|
value: 'datetime',
|
||||||
|
};
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'name'], 'short_movie_time')
|
||||||
|
.setIn(['modifiedData', 'type'], 'datetime')
|
||||||
|
.removeIn(['modifiedData', 'default']);
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not remove the default value if the type of another input type has been changed', () => {
|
||||||
|
const state = initialState.setIn(
|
||||||
|
['modifiedData'],
|
||||||
|
fromJS({
|
||||||
|
name: 'number_of_movies',
|
||||||
|
type: 'integer',
|
||||||
|
default: '0',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const action = {
|
||||||
|
type: 'ON_CHANGE',
|
||||||
|
keys: ['type'],
|
||||||
|
value: 'biginteger',
|
||||||
|
};
|
||||||
|
const expected = state
|
||||||
|
.setIn(['modifiedData', 'name'], 'number_of_movies')
|
||||||
|
.setIn(['modifiedData', 'type'], 'biginteger');
|
||||||
|
|
||||||
|
expect(reducer(state, action)).toEqual(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ON_CHANGE_ALLOWED_TYPE', () => {
|
describe('ON_CHANGE_ALLOWED_TYPE', () => {
|
||||||
|
@ -488,10 +488,11 @@ const forms = {
|
|||||||
items.splice(0, 1, [
|
items.splice(0, 1, [
|
||||||
{
|
{
|
||||||
...fields.default,
|
...fields.default,
|
||||||
type: 'date',
|
type: data.type || 'date',
|
||||||
value: null,
|
value: null,
|
||||||
withDefaultValue: false,
|
withDefaultValue: false,
|
||||||
disabled: data.type !== 'date',
|
disabled: !data.type,
|
||||||
|
autoFocus: false,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
} else if (type === 'richtext') {
|
} else if (type === 'richtext') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user