feedback improvements handleChange

This commit is contained in:
ronronscelestes 2022-06-23 17:16:57 +02:00
parent f723fa36c2
commit 5cbaf24336
6 changed files with 72 additions and 22 deletions

View File

@ -0,0 +1,41 @@
{
"kind": "collectionType",
"collectionName": "aanother_tests",
"info": {
"singularName": "aanother-test",
"pluralName": "aanother-tests",
"displayName": "Aanother test"
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"text": {
"type": "string",
"unique": true
},
"email": {
"type": "email",
"unique": true
},
"number": {
"unique": true,
"type": "integer"
},
"uid": {
"type": "uid"
},
"date": {
"unique": true,
"type": "date"
},
"enum": {
"type": "enumeration",
"enum": [
"this",
"or that"
]
}
}
}

View File

@ -0,0 +1,9 @@
'use strict';
/**
* aanother-test controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::aanother-test.aanother-test');

View File

@ -0,0 +1,9 @@
'use strict';
/**
* aanother-test router.
*/
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::aanother-test.aanother-test');

View File

@ -0,0 +1,9 @@
'use strict';
/**
* aanother-test service.
*/
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::aanother-test.aanother-test');

View File

@ -235,21 +235,12 @@ const EditViewDataManagerProvider = ({
// Allow to reset text, string, email, uid, select/enum, date // Allow to reset text, string, email, uid, select/enum, date
if ( if (
(type === 'text' || ['text', 'string', 'email', 'uid', 'select', 'select-one', 'number'].includes(type) &&
type === 'string' || !value
type === 'email' ||
type === 'uid' ||
type === 'select' ||
type === 'select-one') &&
value === ''
) { ) {
inputValue = null; inputValue = null;
} }
if (type === 'number' && !value) {
inputValue = null;
}
if (type === 'password' && !value) { if (type === 'password' && !value) {
dispatch({ dispatch({
type: 'REMOVE_PASSWORD_FIELD', type: 'REMOVE_PASSWORD_FIELD',
@ -259,6 +250,8 @@ const EditViewDataManagerProvider = ({
return; return;
} }
console.log({ name, inputValue });
dispatch({ dispatch({
type: 'ON_CHANGE', type: 'ON_CHANGE',
keys: name.split('.'), keys: name.split('.'),

View File

@ -110,16 +110,5 @@ describe('GenericInput', () => {
target: { name: 'number', type: 'number', value: 0 }, target: { name: 'number', type: 'number', value: 0 },
}); });
}); });
test('does call onChange callback with undefined on empty value', () => {
const spy = jest.fn();
const { input } = setupNumber({ value: 1, onChange: spy });
fireEvent.change(input, { target: { value: '' } });
expect(spy).toHaveBeenCalledWith({
target: { name: 'number', type: 'number', value: undefined },
});
});
}); });
}); });