diff --git a/src/state/component-repository/component-repositories/actions.js b/src/state/component-repository/component-repositories/actions.js index 72be06d0a..871c69ebd 100644 --- a/src/state/component-repository/component-repositories/actions.js +++ b/src/state/component-repository/component-repositories/actions.js @@ -1,4 +1,3 @@ -import { initialize } from 'redux-form'; import { addToast, addErrors, TOAST_SUCCESS, TOAST_ERROR } from '@entando/messages'; import { toggleLoading } from 'state/loading/actions'; @@ -59,15 +58,12 @@ export const fetchComponentRepositories = (page = { page: 1, pageSize: 10 }, par }) ); -export const fetchComponentRepository = (id, initForm = false) => dispatch => ( +export const fetchComponentRepository = id => dispatch => ( new Promise((resolve) => { getComponentRepository(id).then((response) => { response.json().then((data) => { if (response.ok) { dispatch(setSelectedComponentRepository(data.payload)); - if (initForm) { - dispatch(initialize('ecrSettings', data.payload)); - } } else { dispatch(addErrors(data.errors.map(err => err.message))); data.errors.forEach(err => dispatch(addToast(err.message, TOAST_ERROR))); diff --git a/src/state/content-template/actions.js b/src/state/content-template/actions.js index 5dc83d668..2a50a4452 100644 --- a/src/state/content-template/actions.js +++ b/src/state/content-template/actions.js @@ -1,6 +1,5 @@ import { convertToQueryString, FILTER_OPERATORS } from '@entando/utils'; import { addErrors, addToast, clearErrors, TOAST_ERROR } from '@entando/messages'; -import { initialize } from 'redux-form'; import { setPage } from 'state/pagination/actions'; import { NAMESPACE_CONTENT_TEMPLATES } from 'state/pagination/const'; import { @@ -144,7 +143,6 @@ export const fetchContentTemplate = id => dispatch => new Promise(resolve => ( response.json().then((json) => { if (response.ok) { dispatch(setContentTemplate(json.payload)); - dispatch(initialize('contenttemplateform', json.payload)); resolve(json.payload); } else { dispatch(addErrors(json.errors.map(err => err.message))); diff --git a/src/state/content-type/actions.js b/src/state/content-type/actions.js index d3fac913e..b1b000d18 100644 --- a/src/state/content-type/actions.js +++ b/src/state/content-type/actions.js @@ -35,7 +35,6 @@ import { getActionModeContentTypeSelectedAttribute, getContentTypeAttributesIdList, getMonolistAttributeType, - getFormTypeValue, getSelectedAttributeType, getContentTypeSelectedAttributeType, getContentTypeSelectedAttribute, @@ -46,7 +45,6 @@ import { getNewAttributeComposite, getSelectedContentType, } from 'state/content-type/selectors'; -import { initialize } from 'redux-form'; import { TYPE_MONOLIST, @@ -231,18 +229,12 @@ export const fetchContentTypeListPaged = ( .catch(() => {}); }); -export const fetchContentType = ( - contentTypeCode, - initForm = true, -) => dispatch => new Promise((resolve, reject) => { +export const fetchContentType = contentTypeCode => dispatch => new Promise((resolve, reject) => { getContentType(contentTypeCode) .then((response) => { response.json().then((json) => { if (response.ok) { dispatch(setSelectedContentType(json.payload)); - if (initForm) { - dispatch(initialize('ContentType', json.payload)); - } resolve(json.payload); } else { dispatch(addErrors(json.errors.map(err => err.message))); @@ -380,16 +372,14 @@ export const fetchContentTypeAttributeRef = ( contentTypeAttributeCode, routeFunc, selectedAttributeType = '', - formName, ) => (dispatch, getState) => new Promise((resolve) => { - let typeAttribute = contentTypeAttributeCode; + const typeAttribute = contentTypeAttributeCode; const checkCompositeSubAttribute = selectedAttributeType === TYPE_COMPOSITE || (selectedAttributeType === TYPE_MONOLIST && getMonolistAttributeType(getState()) === TYPE_COMPOSITE); if (checkCompositeSubAttribute) { - typeAttribute = getFormTypeValue(getState(), formName); dispatch(setActionMode(MODE_ADD_ATTRIBUTE_COMPOSITE)); const selectedAttr = getContentTypeSelectedAttribute(getState()); dispatch(pushParentSelectedAttribute(selectedAttr)); @@ -403,32 +393,6 @@ export const fetchContentTypeAttributeRef = ( response.json().then((json) => { if (response.ok) { dispatch(setSelectedAttributeRef(json.payload)); - switch (actionMode) { - case MODE_ADD_ATTRIBUTE_COMPOSITE: { - dispatch(initialize(formName, { - type: json.payload.code, - compositeAttributeType: TYPE_COMPOSITE, - code: '', - name: '', - })); - break; - } - case MODE_ADD_SUB_ATTRIBUTE_MONOLIST_COMPOSITE: { - dispatch(initialize(formName, { type: json.payload.code })); - break; - } - case MODE_ADD_MONOLIST_ATTRIBUTE_COMPOSITE: { - const nestedAttribute = { - ...json.payload, - type: json.payload.code, - compositeAttributeType: TYPE_COMPOSITE, - }; - dispatch(initialize(formName, { nestedAttribute })); - break; - } - default: - break; - } if (routeFunc && actionMode !== MODE_ADD_ATTRIBUTE_COMPOSITE) { routeFunc(); } @@ -517,7 +481,6 @@ export const fetchAttributeFromContentType = (formName, contentTypeCode, attribu } const actionMode = getActionModeContentTypeSelectedAttribute(getState()); if (actionMode !== MODE_ADD_ATTRIBUTE_COMPOSITE) { - dispatch(initialize(formName, payload)); dispatch(setSelectedContentTypeAttribute(json.payload)); dispatch(fetchContentTypeAttributeRef( contentTypeCode, @@ -585,10 +548,6 @@ export const sendPutAttributeFromContentType = ( type === TYPE_MONOLIST && getIsMonolistCompositeAttributeType(getState()) )) { - dispatch(initialize('attribute', { - ...json.payload, - compositeAttributeType: TYPE_COMPOSITE, - })); if (mode === MODE_ADD_ATTRIBUTE_COMPOSITE || mode === MODE_ADD_MONOLIST_ATTRIBUTE_COMPOSITE) { history.push(routeConverter(ROUTE_CMS_CONTENT_TYPE_ATTRIBUTE_EDIT, { diff --git a/src/state/content-type/selectors.js b/src/state/content-type/selectors.js index ee1a671e0..941cfb2e5 100644 --- a/src/state/content-type/selectors.js +++ b/src/state/content-type/selectors.js @@ -1,5 +1,4 @@ import { createSelector } from 'reselect'; -import { formValueSelector } from 'redux-form'; import { get, isEmpty, @@ -252,7 +251,6 @@ export const getNewAttributeComposite = createSelector( sel => sel.newAttributeComposite, ); -export const getFormTypeValue = (state, formName) => formValueSelector(formName)(state, 'type'); export const getShapeMethodsByAttributeType = (type) => { switch (type) { diff --git a/src/state/data-models/actions.js b/src/state/data-models/actions.js index cd0b65c71..b29d55f18 100644 --- a/src/state/data-models/actions.js +++ b/src/state/data-models/actions.js @@ -1,4 +1,3 @@ -import { initialize } from 'redux-form'; import { addToast, addErrors, TOAST_SUCCESS, TOAST_ERROR } from '@entando/messages'; import { getDataModels, getDataModel, postDataModel, putDataModel, deleteDataModel } from 'api/dataModels'; @@ -38,9 +37,7 @@ export const fetchDataModelListPaged = (page = { page: 1, pageSize: 10 }, params export const fetchDataModel = dataModelId => dispatch => new Promise((resolve) => { getDataModel(dataModelId).then((response) => { response.json().then((json) => { - if (response.ok) { - dispatch(initialize('dataModel', json.payload)); - } else { + if (!response.ok) { dispatch(addErrors(json.errors.map(err => err.message))); json.errors.forEach(err => dispatch(addToast(err.message, TOAST_ERROR))); } diff --git a/src/state/data-types/actions.js b/src/state/data-types/actions.js index 4ef4f9347..f8192e30c 100644 --- a/src/state/data-types/actions.js +++ b/src/state/data-types/actions.js @@ -3,9 +3,8 @@ import { addToast, addErrors, clearErrors, TOAST_SUCCESS, TOAST_ERROR } from '@e import { routeConverter } from '@entando/utils'; import { setPage } from 'state/pagination/actions'; import { toggleLoading } from 'state/loading/actions'; -import { initialize } from 'redux-form'; + import { isUndefined } from 'lodash'; -import moment from 'moment'; import { history, @@ -54,7 +53,6 @@ import { getDataTypeSelectedAttributeType, getSelectedDataType, getSelectedAttributeType, - getFormTypeValue, getAttributeSelectFromDataType, getActionModeDataTypeSelectedAttribute, getNewAttributeComposite, @@ -288,7 +286,6 @@ export const fetchDataType = dataTypeCode => dispatch => ( response.json().then((json) => { if (response.ok) { dispatch(setSelectedDataType(json.payload)); - dispatch(initialize('DataType', json.payload)); } else { dispatch(addErrors(json.errors.map(err => err.message))); json.errors.forEach(err => dispatch(addToast(err.message, TOAST_ERROR))); @@ -319,10 +316,10 @@ export const fetchDataTypes = (page = { page: 1, pageSize: 10 }, params = '') => ); export const fetchDataTypeAttribute = - (dataTypeAttributeCode, route, selectedAttributeType = '', formName) => + (dataTypeAttributeCode, route, selectedAttributeType = '') => (dispatch, getState) => ( new Promise((resolve) => { - let typeAttribute = dataTypeAttributeCode; + const typeAttribute = dataTypeAttributeCode; const checkCompositeSubAttribute = selectedAttributeType === TYPE_COMPOSITE || @@ -330,7 +327,6 @@ export const fetchDataTypeAttribute = getMonolistAttributeType(getState()) === TYPE_COMPOSITE); if (checkCompositeSubAttribute) { - typeAttribute = getFormTypeValue(getState(), formName); dispatch(setActionMode(MODE_ADD_ATTRIBUTE_COMPOSITE)); } const actionMode = getActionModeDataTypeSelectedAttribute(getState()); @@ -341,26 +337,6 @@ export const fetchDataTypeAttribute = response.json().then((json) => { if (response.ok) { dispatch(setSelectedAttribute(json.payload)); - switch (actionMode) { - case MODE_ADD_ATTRIBUTE_COMPOSITE: { - dispatch(initialize(formName, { type: json.payload.code, code: '', name: '' })); - break; - } - case MODE_ADD_SUB_ATTRIBUTE_MONOLIST_COMPOSITE: { - dispatch(initialize(formName, { type: json.payload.code })); - break; - } - case MODE_ADD_MONOLIST_ATTRIBUTE_COMPOSITE: { - const nestedAttribute = { - ...json.payload, - type: json.payload.code, - compositeAttributeType: TYPE_COMPOSITE, - }; - dispatch(initialize(formName, { nestedAttribute })); - break; - } - default: break; - } if (route && actionMode !== MODE_ADD_ATTRIBUTE_COMPOSITE) { history.push(routeConverter(route.route, route.params)); } @@ -374,53 +350,14 @@ export const fetchDataTypeAttribute = }) ); -const fmtDateDDMMYYY = (date) => { - let d = new Date(date); - d = `${d.getDate()}/${d.getMonth() + 1}/${d.getFullYear()}`; - return moment(d, 'DD/MM/YYYY').format('DD/MM/YYYY'); -}; - export const fetchAttributeFromDataType = (formName, dataTypeCode, attributeCode) => (dispatch, getState) => ( new Promise((resolve) => { getAttributeFromDataType(dataTypeCode, attributeCode).then((response) => { response.json().then((json) => { if (response.ok) { - const joinRoles = json.payload.roles ? json.payload.roles.map(role => (role.code)) : []; - let payload = { - ...json.payload, - joinRoles, - joinAllowedOptions: joinRoles, - compositeAttributeType: TYPE_COMPOSITE, - }; - if (json.payload.type === TYPE_DATE) { - let { - rangeStartDate, rangeEndDate, equalDate, - rangeStartDateAttribute, rangeEndDateAttribute, equalDateAttribute, - } = json.payload.validationRules; - rangeStartDate = rangeStartDate && fmtDateDDMMYYY(rangeStartDate); - rangeEndDate = rangeEndDate && fmtDateDDMMYYY(rangeEndDate); - equalDate = equalDate && fmtDateDDMMYYY(equalDate); - rangeStartDateAttribute = - rangeStartDateAttribute && fmtDateDDMMYYY(rangeStartDateAttribute); - rangeEndDateAttribute = - rangeEndDateAttribute && fmtDateDDMMYYY(rangeEndDateAttribute); - equalDateAttribute = equalDateAttribute && fmtDateDDMMYYY(equalDateAttribute); - payload = { - ...payload, - validationRules: { - rangeStartDate, - rangeEndDate, - equalDate, - rangeStartDateAttribute, - rangeEndDateAttribute, - equalDateAttribute, - }, - }; - } const actionMode = getActionModeDataTypeSelectedAttribute(getState()); if (actionMode !== MODE_ADD_ATTRIBUTE_COMPOSITE) { - dispatch(initialize(formName, payload)); dispatch(setSelectedAttributeDataType(json.payload)); dispatch(fetchDataTypeAttribute(getSelectedAttributeType(getState()))); } @@ -484,7 +421,6 @@ export const sendPutAttributeFromDataType = ( dispatch(setSelectedAttributeDataType(json.payload)); const { type, code } = attributeObject; if (type === TYPE_COMPOSITE) { - dispatch(initialize('attribute', { ...json.payload, compositeAttributeType: TYPE_COMPOSITE })); history.push(routeConverter( ROUTE_DATA_TYPE_ATTRIBUTE_EDIT, { entityCode, attributeCode: code }, diff --git a/src/state/data-types/selectors.js b/src/state/data-types/selectors.js index 9d2da034e..855c289a0 100644 --- a/src/state/data-types/selectors.js +++ b/src/state/data-types/selectors.js @@ -1,5 +1,4 @@ import { createSelector } from 'reselect'; -import { formValueSelector } from 'redux-form'; import { get, isEmpty, isUndefined } from 'lodash'; import { TYPE_MONOLIST, @@ -115,4 +114,3 @@ export const getIsMonolistComposteAttributeType = export const getNewAttributeComposite = createSelector([getSelectedDataType], sel => sel.newAttributeComposite); -export const getFormTypeValue = (state, formName) => formValueSelector(formName)(state, 'type'); diff --git a/src/state/edit-content/actions.js b/src/state/edit-content/actions.js index 8adef75ec..657f9e570 100644 --- a/src/state/edit-content/actions.js +++ b/src/state/edit-content/actions.js @@ -1,5 +1,4 @@ import { addErrors, addToast, clearErrors, TOAST_ERROR } from '@entando/messages'; -import { initialize, formValueSelector, change } from 'redux-form'; import moment from 'moment'; import { isEmpty, pickBy, isObject, cloneDeep } from 'lodash'; @@ -60,15 +59,6 @@ export const fetchContent = params => dispatch => new Promise((resolve, reject) const content = json.payload; dispatch(setContentEntry(content)); dispatch(setJoinedCategories(content.categories)); - const { - mainGroup, groups, description, status, - } = content; - dispatch(initialize('editcontentform', { - mainGroup, - groups, - description, - ...(status !== 'PUBLIC' && { status }), - })); } else { dispatch(addErrors(json.errors.map(err => err.message))); reject(); @@ -105,9 +95,7 @@ export const copyAttributeEngValue = (attribute, attributeType) => (dispatch, ge } }; -export const duplicateEngFieldValues = () => (dispatch, getState) => { - const state = getState(); - +export const duplicateEngFieldValues = () => (dispatch) => { const traverseAttributes = (attributeValues, attributeList) => { const mappedAttributes = attributeList.reduce( (curr, attribute) => ({ ...curr, [attribute.code]: attribute }), @@ -143,17 +131,6 @@ export const duplicateEngFieldValues = () => (dispatch, getState) => { } }); }; - - const mainAttributeValues = formValueSelector('editcontentform')(state, 'attributes'); - - dispatch(change( - 'editcontentform', - 'attributes', - traverseAttributes( - mainAttributeValues, - getSelectedContentTypeAttributes(state), - ), - )); }; export const setOwnerGroupDisable = disabled => ({ diff --git a/src/state/file-browser/actions.js b/src/state/file-browser/actions.js index fbd8b8c73..9c5a87332 100644 --- a/src/state/file-browser/actions.js +++ b/src/state/file-browser/actions.js @@ -1,5 +1,4 @@ import { addToast, addErrors, TOAST_SUCCESS, TOAST_ERROR } from '@entando/messages'; -import { initialize } from 'redux-form'; import { getFileBrowser, getFile, postFile, putFile, postCreateFolder, deleteFolder, deleteFile } from 'api/fileBrowser'; import { toggleLoading } from 'state/loading/actions'; @@ -54,9 +53,7 @@ export const fetchFile = (filename, extensions = ['.txt']) => (dispatch, getStat const queryString = `?protectedFolder=${protectedFolder === null ? false : protectedFolder}¤tPath=${currentPath}/${filename}`; getFile(queryString).then((response) => { response.json().then((json) => { - if (response.ok) { - dispatch(initialize('CreateTextFileForm', { content: window.atob(json.payload.base64) })); - } else { + if (!response.ok) { dispatch(addErrors(json.errors.map(e => e.message))); json.errors.forEach(err => dispatch(addToast(err.message, TOAST_ERROR))); history.push(ROUTE_FILE_BROWSER); diff --git a/src/state/forms/selectors.js b/src/state/forms/selectors.js deleted file mode 100644 index 76db7fbb9..000000000 --- a/src/state/forms/selectors.js +++ /dev/null @@ -1,5 +0,0 @@ -import { getFormValues } from 'redux-form'; - -export const getPageForm = getFormValues('page'); -export const getPageTemplateForm = getFormValues('pageTemplate'); -export const getUserProfileForm = getFormValues('UserProfile'); diff --git a/src/state/page-templates/selectors.js b/src/state/page-templates/selectors.js index a95766c34..26852958d 100644 --- a/src/state/page-templates/selectors.js +++ b/src/state/page-templates/selectors.js @@ -1,8 +1,12 @@ import { createSelector } from 'reselect'; import { get } from 'lodash'; -import { validatePageTemplate, getCellMap, convertPageTemplateForm } from 'state/page-templates/helpers'; -import { getPageTemplateForm } from 'state/forms/selectors'; +import { + // validatePageTemplate, + getCellMap, + // convertPageTemplateForm +} from 'state/page-templates/helpers'; +// import { getPageTemplateForm } from 'state/forms/selectors'; import { getLocale } from 'state/locale/selectors'; export const getPageTemplates = state => state.pageTemplates; @@ -45,27 +49,6 @@ export const getSelectedPageTemplateDefaultConfig = createSelector( }, ); -export const getFormPageTemplate = createSelector( - [getPageTemplateForm], - pageTemplateForm => convertPageTemplateForm(pageTemplateForm), -); - -export const getPageTemplateFormCellMap = createSelector( - [getFormPageTemplate], - getCellMap, -); - -export const getPageTemplateFormErrors = createSelector( - [getFormPageTemplate], - (formPageTemplate) => { - const errors = validatePageTemplate(formPageTemplate); - if (errors && errors.length) { - return errors; - } - return []; - }, -); - export const getSelectedPageTemplatePageRefs = createSelector( [getSelectedPageTemplate], pageTemplate => pageTemplate && pageTemplate.pageReferences, diff --git a/src/state/pages/actions.js b/src/state/pages/actions.js index 434ad3dac..c5811f69e 100644 --- a/src/state/pages/actions.js +++ b/src/state/pages/actions.js @@ -1,4 +1,3 @@ -import { initialize } from 'redux-form'; import { addToast, addErrors, TOAST_SUCCESS, TOAST_ERROR } from '@entando/messages'; import { setPage } from 'state/pagination/actions'; @@ -39,15 +38,6 @@ const INVALID_PAGE_POSITION_STATUS_CODE = 422; const INVALID_PAGE_CHILD_POSITION_ERROR = { id: 'page.invalidChildPositionError' }; const INVALID_PAGE_CHILD_POSITION_STATUS_CODE = 400; -const RESET_FOR_CLONE = { - code: '', - titles: '', - parentCode: '', - fullTitles: '', - fullPath: '', - status: '', - references: {}, -}; const noopPromise = arg => Promise.resolve(arg); @@ -440,13 +430,8 @@ export const fetchFreePages = () => async (dispatch) => { } }; -export const clonePage = (page, redirectTo = null) => async (dispatch) => { +export const clonePage = (page, redirectTo = null) => async () => { try { - const json = await fetchPage(page.code)(dispatch); - dispatch(initialize('page', { - ...json.payload, - ...RESET_FOR_CLONE, - })); let pageCloneUrl = `${ROUTE_PAGE_CLONE}?pageCode=${page.code}`; if (redirectTo) { pageCloneUrl += `&redirectTo=${redirectTo}`; @@ -463,9 +448,7 @@ export const fetchPageSettings = () => async (dispatch) => { const response = await getPageSettings(); const json = await response.json(); dispatch(toggleLoading('pageSettings')); - if (response.ok) { - dispatch(initialize('settings', json.payload)); - } else { + if (!response.ok) { dispatch(addErrors(json.errors.map(e => e.message))); json.errors.forEach(err => dispatch(addToast(err.message, TOAST_ERROR))); } @@ -635,11 +618,9 @@ export const fetchSearchPages = (page = { page: 1, pageSize: 10 }, params = '') export const clearSearchPage = () => (dispatch) => { dispatch(clearSearch()); - dispatch(initialize('pageSearch', {})); }; -export const initPageForm = (pageData, redirectTo = null) => (dispatch) => { - dispatch(initialize('page', pageData)); +export const initPageForm = (pageData, redirectTo = null) => () => { let pageAddUrl = `${ROUTE_PAGE_ADD}?parentCode=${pageData.parentCode}`; if (redirectTo) { pageAddUrl += `&redirectTo=${redirectTo}`; diff --git a/src/state/profile-types/actions.js b/src/state/profile-types/actions.js index 93c9108e3..4903edeb1 100644 --- a/src/state/profile-types/actions.js +++ b/src/state/profile-types/actions.js @@ -1,4 +1,3 @@ -import { initialize } from 'redux-form'; import { METHODS } from '@entando/apimanager'; import { routeConverter } from '@entando/utils'; import moment from 'moment'; @@ -334,7 +333,6 @@ export const fetchProfileType = profileTypeCode => dispatch => ( response.json().then((json) => { if (response.ok) { dispatch(setSelectedProfileType(json.payload)); - dispatch(initialize('ProfileType', json.payload)); } else { dispatch(addErrors(json.errors.map(err => err.message))); json.errors.forEach(err => dispatch(addToast(err.message, TOAST_ERROR))); @@ -352,7 +350,6 @@ export const fetchMyProfileType = () => dispatch => ( response.json().then((json) => { if (response.ok) { dispatch(setSelectedProfileType(json.payload)); - dispatch(initialize('ProfileType', json.payload)); } else { dispatch(addErrors(json.errors.map(err => err.message))); json.errors.forEach(err => dispatch(addToast(err.message, TOAST_ERROR))); @@ -417,10 +414,6 @@ export const sendPutAttributeFromProfileType = ( [TYPE_MONOLIST, TYPE_LIST].includes(json.payload.type) && getIsMonolistCompositeAttributeType(getState()) )) { - dispatch(initialize('attribute', { - ...json.payload, - compositeAttributeType: TYPE_COMPOSITE, - })); if (mode === MODE_ADD_ATTRIBUTE_COMPOSITE || mode === MODE_ADD_MONOLIST_ATTRIBUTE_COMPOSITE ) { @@ -512,7 +505,6 @@ export const fetchProfileTypeAttribute = ( profileTypeAttributeCode, routeFunc, selectedAttributeType = '', - formName, ) => (dispatch, getState) => new Promise((resolve) => { const typeAttribute = profileTypeAttributeCode; @@ -533,26 +525,6 @@ export const fetchProfileTypeAttribute = ( response.json().then((json) => { if (response.ok) { dispatch(setSelectedAttribute(json.payload)); - switch (actionMode) { - case MODE_ADD_ATTRIBUTE_COMPOSITE: { - break; - } - case MODE_ADD_SUB_ATTRIBUTE_MONOLIST_COMPOSITE: { - dispatch(initialize(formName, { type: json.payload.code })); - break; - } - case MODE_ADD_MONOLIST_ATTRIBUTE_COMPOSITE: { - const nestedAttribute = { - ...json.payload, - type: json.payload.code, - compositeAttributeType: TYPE_COMPOSITE, - }; - dispatch(initialize(formName, { nestedAttribute })); - break; - } - default: - break; - } if (routeFunc && actionMode !== MODE_ADD_ATTRIBUTE_COMPOSITE) { routeFunc(); } @@ -636,7 +608,6 @@ export const fetchAttributeFromProfileType = (formName, profileTypeCode, attribu } const actionMode = getActionModeProfileTypeSelectedAttribute(getState()); if (actionMode !== MODE_ADD_ATTRIBUTE_COMPOSITE) { - dispatch(initialize(formName, payload)); dispatch(setSelectedAttributeProfileType(json.payload)); dispatch(fetchProfileTypeAttribute( profileTypeCode, diff --git a/src/state/profile-types/selectors.js b/src/state/profile-types/selectors.js index e8b14bd7a..9ef4516b0 100644 --- a/src/state/profile-types/selectors.js +++ b/src/state/profile-types/selectors.js @@ -1,5 +1,4 @@ import { createSelector } from 'reselect'; -import { formValueSelector } from 'redux-form'; import { get, isEmpty, difference, xor, union, isUndefined } from 'lodash'; import { TYPE_MONOLIST, @@ -169,7 +168,6 @@ export const getIsMonolistCompositeAttributeType = createSelector( ), ); -export const getFormTypeValue = (state, formName) => formValueSelector(formName)(state, 'type'); const getProfileTypeReferences = state => state.profileTypes.references; diff --git a/src/state/roles/actions.js b/src/state/roles/actions.js index f71cd0ddd..3926c0e56 100644 --- a/src/state/roles/actions.js +++ b/src/state/roles/actions.js @@ -1,4 +1,3 @@ -import { initialize } from 'redux-form'; import { addToast, addErrors, TOAST_ERROR, TOAST_SUCCESS } from '@entando/messages'; import { @@ -65,7 +64,6 @@ export const fetchRole = roleCode => dispatch => getRole(roleCode).then((response) => { response.json().then((data) => { if (response.ok) { - dispatch(initialize('role', data.payload)); dispatch(setSelected(data.payload)); } else { dispatch(addErrors(data.errors.map(err => err.message))); diff --git a/src/state/user-profile/actions.js b/src/state/user-profile/actions.js index e4f120524..18f05c112 100644 --- a/src/state/user-profile/actions.js +++ b/src/state/user-profile/actions.js @@ -1,12 +1,8 @@ import { addToast, addErrors, TOAST_ERROR, TOAST_SUCCESS } from '@entando/messages'; -import { getUsername } from '@entando/apimanager'; - -import { initialize } from 'redux-form'; - import { getUserProfile, putUserProfile, getMyUserProfile, putMyUserProfile } from 'api/userProfile'; import { SET_USER_PROFILE } from 'state/user-profile/types'; import { fetchProfileType, fetchMyProfileType } from 'state/profile-types/actions'; -import { getPayloadForForm, getPayloadForApi } from 'helpers/entities'; +import { getPayloadForApi } from 'helpers/entities'; import { getSelectedProfileTypeAttributes } from 'state/profile-types/selectors'; import { getDefaultLanguage, getActiveLanguages } from 'state/languages/selectors'; @@ -19,19 +15,12 @@ export const setUserProfile = profile => ({ }, }); -export const fetchUserProfile = username => (dispatch, getState) => new Promise((resolve) => { +export const fetchUserProfile = username => dispatch => new Promise((resolve) => { getUserProfile(username).then((response) => { response.json().then((json) => { if (response.ok) { dispatch(setUserProfile(json.payload)); dispatch(fetchProfileType(json.payload.typeCode)).then(() => { - const state = getState(); - dispatch(initialize('UserProfile', getPayloadForForm( - username, json.payload, - getSelectedProfileTypeAttributes(state), - getDefaultLanguage(state), - getActiveLanguages(state), - ))); resolve(); }); } else { @@ -72,19 +61,12 @@ export const updateUserProfile = (profile, successRedirect = true) => }); -export const fetchMyUserProfile = () => (dispatch, getState) => new Promise((resolve) => { +export const fetchMyUserProfile = () => dispatch => new Promise((resolve) => { getMyUserProfile().then((response) => { response.json().then((json) => { if (response.ok) { dispatch(setUserProfile(json.payload)); dispatch(fetchMyProfileType(json.payload.typeCode)).then(() => { - const state = getState(); - dispatch(initialize('UserProfile', getPayloadForForm( - getUsername(state), json.payload, - getSelectedProfileTypeAttributes(state), - getDefaultLanguage(state), - getActiveLanguages(state), - ))); resolve(); }); } else { diff --git a/src/state/user-settings/actions.js b/src/state/user-settings/actions.js index 4f039566e..7188f2799 100644 --- a/src/state/user-settings/actions.js +++ b/src/state/user-settings/actions.js @@ -1,6 +1,4 @@ -import { initialize } from 'redux-form'; import { addToast, addErrors, TOAST_ERROR, TOAST_SUCCESS } from '@entando/messages'; - import { getUserSettings, putUserSettings } from 'api/userSettings'; import { SET_USER_SETTINGS } from 'state/user-settings/types'; import { toggleLoading } from 'state/loading/actions'; @@ -18,7 +16,6 @@ export const fetchUserSettings = () => dispatch => new Promise((resolve) => { response.json().then((json) => { if (response.ok) { dispatch(setUserSettings(json.payload)); - dispatch(initialize('user-restrictions', json.payload)); } else { dispatch(addErrors(json.errors.map(err => err.message))); dispatch(addToast(json.errors[0].message, TOAST_ERROR)); diff --git a/src/state/users/actions.js b/src/state/users/actions.js index 7dffe8b82..1f4f57795 100644 --- a/src/state/users/actions.js +++ b/src/state/users/actions.js @@ -1,4 +1,3 @@ -import { initialize, reset } from 'redux-form'; import { addToast, addErrors, clearErrors, TOAST_SUCCESS, TOAST_ERROR } from '@entando/messages'; import { getUsername } from '@entando/apimanager'; @@ -122,8 +121,7 @@ export const fetchUserForm = username => dispatch => ( getUser(username).then((response) => { dispatch(toggleLoading('form')); if (response.ok) { - response.json().then((json) => { - dispatch(initialize('user', json.payload)); + response.json().then(() => { dispatch(toggleLoading('form')); resolve(); }); @@ -286,7 +284,6 @@ export const sendPostMyPassword = data => dispatch => new Promise(async (resolve TOAST_SUCCESS, )); dispatch(clearErrors()); - dispatch(reset('myprofile-account')); dispatch(setVisibleModal('')); } else { dispatch(addErrors(json.errors.map(e => e.message))); diff --git a/src/state/widgets/actions.js b/src/state/widgets/actions.js index 18210673b..df169661f 100644 --- a/src/state/widgets/actions.js +++ b/src/state/widgets/actions.js @@ -1,4 +1,3 @@ -import { initialize } from 'redux-form'; import { get, pick } from 'lodash'; import { addToast, addErrors, TOAST_ERROR, TOAST_SUCCESS } from '@entando/messages'; import { routeConverter } from '@entando/utils'; @@ -102,22 +101,11 @@ export const getSingleWidgetInfo = widgetCode => dispatch => ( )).catch(() => {}) ); -export const initNewUserWidget = (widgetCode, isCloning = false) => (dispatch) => { +export const initNewUserWidget = widgetCode => (dispatch) => { toggleLoading('fetchWidget'); dispatch(getSingleWidgetInfo(widgetCode)).then(({ ok, json }) => { if (ok) { - const config = get(json.payload, 'parameters', []) - .reduce((acc, curr) => ({ - ...acc, - [curr.code]: '', - }), {}); dispatch(setSelectedParentWidget(json.payload)); - if (!isCloning) { - dispatch(initialize('widget', { - parentType: json.payload.code, - config, - })); - } } else { dispatch(removeParentWidget()); } @@ -132,7 +120,6 @@ export const fetchWidget = widgetCode => dispatch => new Promise((resolve) => { newPayload.configUi = !newPayload.configUi ? '' : JSON.stringify(newPayload.configUi, null, 2); newPayload.group = newPayload.group || FREE_ACCESS_GROUP_VALUE; const userWidgetInitDispatches = () => { - dispatch(initialize('widget', newPayload)); dispatch(setSelectedWidget(json.payload)); toggleLoading('fetchWidget'); resolve(); diff --git a/src/ui/component-repository/settings/edit/SettingsEditFormContainer.js b/src/ui/component-repository/settings/edit/SettingsEditFormContainer.js index cc3c4e1a6..55428c95b 100644 --- a/src/ui/component-repository/settings/edit/SettingsEditFormContainer.js +++ b/src/ui/component-repository/settings/edit/SettingsEditFormContainer.js @@ -9,7 +9,7 @@ export const mapStateToProps = (state, { match: { params } }) => ({ }); export const mapDispatchToProps = dispatch => ({ - onWillMount: (id) => { dispatch(fetchComponentRepository(id, true)); }, + onWillMount: (id) => { dispatch(fetchComponentRepository(id)); }, onSubmit: (data) => { dispatch(sendPutComponentRepository(data)); }, }); diff --git a/src/ui/profile-types/attributes/AddFormContainer.js b/src/ui/profile-types/attributes/AddFormContainer.js index 4ffa34fbe..12b8aac6c 100644 --- a/src/ui/profile-types/attributes/AddFormContainer.js +++ b/src/ui/profile-types/attributes/AddFormContainer.js @@ -91,7 +91,6 @@ export const mapDispatchToProps = (dispatch, { match: { params }, history }) => entityCode: params.entityCode, })), code, - 'addAttribute', )); }, onClickDelete: (attributeCode) => { diff --git a/src/ui/profile-types/attributes/EditFormContainer.js b/src/ui/profile-types/attributes/EditFormContainer.js index fea21b868..0eb8fd5ae 100644 --- a/src/ui/profile-types/attributes/EditFormContainer.js +++ b/src/ui/profile-types/attributes/EditFormContainer.js @@ -104,7 +104,6 @@ export const mapDispatchToProps = (dispatch, { match: { params }, history }) => entityCode: profileTypeAttributeCode, })), selectedAttributeType, - 'attribute', )); }, onClickDelete: (attributeCode, isMonolistCompositeType) => { diff --git a/src/ui/profile-types/attributes/monolist/FormContainer.js b/src/ui/profile-types/attributes/monolist/FormContainer.js index f914c99e2..79bbd3599 100644 --- a/src/ui/profile-types/attributes/monolist/FormContainer.js +++ b/src/ui/profile-types/attributes/monolist/FormContainer.js @@ -64,7 +64,6 @@ export const mapDispatchToProps = (dispatch, { match: { params }, history }) => })) ), '', - 'attribute', )); } else { dispatch(fetchAttributeFromProfileType('attribute', profileTypeCode, attributeCode)); @@ -95,7 +94,6 @@ export const mapDispatchToProps = (dispatch, { match: { params }, history }) => entityCode: profileTypeCode, })), type, - 'addAttribute', )); }, onClickDelete: (attributeCode) => { diff --git a/src/ui/users/my-profile/MyProfileEditForm.js b/src/ui/users/my-profile/MyProfileEditForm.js index 198a38248..6d5e3f72e 100644 --- a/src/ui/users/my-profile/MyProfileEditForm.js +++ b/src/ui/users/my-profile/MyProfileEditForm.js @@ -330,14 +330,6 @@ MyProfileEditFormBody.propTypes = { })).isRequired, intl: intlShape.isRequired, userEmail: PropTypes.string, - userProfileForm: PropTypes.shape({ - email: PropTypes.string, - fullname: PropTypes.string, - id: PropTypes.string, - typeCode: PropTypes.string, - typeDescription: PropTypes.string, - profilepicture: PropTypes.string, - }), onChangeProfilePicture: PropTypes.func.isRequired, isValid: PropTypes.bool.isRequired, }; @@ -345,7 +337,6 @@ MyProfileEditFormBody.propTypes = { MyProfileEditFormBody.defaultProps = { profileTypesAttributes: [], userEmail: undefined, - userProfileForm: {}, values: {}, }; diff --git a/src/ui/users/my-profile/MyProfileEditFormContainer.js b/src/ui/users/my-profile/MyProfileEditFormContainer.js index 05e3f16a8..9f7d51dae 100644 --- a/src/ui/users/my-profile/MyProfileEditFormContainer.js +++ b/src/ui/users/my-profile/MyProfileEditFormContainer.js @@ -8,7 +8,7 @@ import { getSelectedProfileTypeAttributes } from 'state/profile-types/selectors' import MyProfileEditForm from 'ui/users/my-profile/MyProfileEditForm'; import { getPayloadForForm } from 'helpers/entities'; import { getUserProfile, getUserEmail } from 'state/user-profile/selectors'; -import { getUserProfileForm } from 'state/forms/selectors'; +// import { getUserProfileForm } from 'state/forms/selectors'; export const mapStateToProps = state => ({ username: getUsername(state), @@ -22,7 +22,6 @@ export const mapStateToProps = state => ({ getActiveLanguages(state), ), userEmail: getUserEmail(state), - userProfileForm: getUserProfileForm(state), }); export const mapDispatchToProps = dispatch => ({ diff --git a/src/ui/widget-forms/publish-single-content-config/SingleContentConfigContainer.js b/src/ui/widget-forms/publish-single-content-config/SingleContentConfigContainer.js index db06d4322..70699059b 100644 --- a/src/ui/widget-forms/publish-single-content-config/SingleContentConfigContainer.js +++ b/src/ui/widget-forms/publish-single-content-config/SingleContentConfigContainer.js @@ -100,7 +100,7 @@ export const mapDispatchToProps = (dispatch, ownProps) => { submitForm(); }, loadContentTypeDetails: (contentTypeCode, setFieldValue) => - dispatch(fetchContentType(contentTypeCode, false)) + dispatch(fetchContentType(contentTypeCode)) .then((ctype) => { setFieldValue(putPrefixField('chosenContentType'), ctype); }), diff --git a/src/ui/widgets/clone/CloneWidgetFormContainer.js b/src/ui/widgets/clone/CloneWidgetFormContainer.js index d91bed39e..aaa1c62a8 100644 --- a/src/ui/widgets/clone/CloneWidgetFormContainer.js +++ b/src/ui/widgets/clone/CloneWidgetFormContainer.js @@ -65,7 +65,7 @@ export const mapDispatchToProps = (dispatch, { history, match: { params } }) => } else { dispatch(initWidgetConfigPageWithConfigData(pageCode, parentCode, parseInt(frameId, 10))); } - dispatch(initNewUserWidget(parentCode, true)); + dispatch(initNewUserWidget(parentCode)); }, onSubmit: (values, saveType) => { const { config: configFields, parentType } = values; diff --git a/test/state/component-repository/component-repositories/actions.test.js b/test/state/component-repository/component-repositories/actions.test.js index 4578c1b8b..9c6d1c1c7 100644 --- a/test/state/component-repository/component-repositories/actions.test.js +++ b/test/state/component-repository/component-repositories/actions.test.js @@ -92,7 +92,8 @@ describe('state/component-repository/component-repositories/actions', () => { describe('fetchComponentRepositories', () => { beforeEach(() => { - getComponentRepositories.mockImplementation(mockApi({ payload: LIST_COMPONENT_REPOSITORIES_OK })); + getComponentRepositories + .mockImplementation(mockApi({ payload: LIST_COMPONENT_REPOSITORIES_OK })); }); it('fetchComponentRepositories calls setComponentRepositories and setPage actions', (done) => { @@ -147,13 +148,11 @@ describe('state/component-repository/component-repositories/actions', () => { }); it('prepopulates the form if initForm is true', (done) => { - store.dispatch(fetchComponentRepository(12, true)).then(() => { + store.dispatch(fetchComponentRepository(12)).then(() => { expect(getComponentRepository).toHaveBeenCalledWith(12); const actions = store.getActions(); - expect(actions).toHaveLength(2); + expect(actions).toHaveLength(1); expect(actions[0]).toHaveProperty('type', SET_SELECTED_COMPONENT_REPOSITORY); - expect(actions[1]).toHaveProperty('type', '@@redux-form/INITIALIZE'); - expect(actions[1]).toHaveProperty('meta.form', 'ecrSettings'); done(); }).catch(done.fail); }); diff --git a/test/state/content-type/actions.test.js b/test/state/content-type/actions.test.js index b6a221dd8..26e011dd6 100644 --- a/test/state/content-type/actions.test.js +++ b/test/state/content-type/actions.test.js @@ -498,7 +498,7 @@ describe('state/content-type/actions ', () => { .dispatch(fetchContentType('AAA')) .then(() => { const actions = store.getActions(); - expect(actions).toHaveLength(2); + expect(actions).toHaveLength(1); expect(actions[0]).toHaveProperty('type', SET_SELECTED_CONTENT_TYPE); expect(actions[0]).toHaveProperty('payload'); expect(actions[0].payload).toMatchObject({ @@ -596,9 +596,8 @@ describe('state/content-type/actions ', () => { .then(() => { expect(getAttributeFromContentType).toHaveBeenCalled(); const actions = store.getActions(); - expect(actions).toHaveLength(2); - expect(actions[0]).toHaveProperty('type', '@@redux-form/INITIALIZE'); - expect(actions[1]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE_FOR_CONTENTTYPE); + expect(actions).toHaveLength(1); + expect(actions[0]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE_FOR_CONTENTTYPE); done(); }) .catch(done.fail); @@ -638,10 +637,10 @@ describe('state/content-type/actions ', () => { .dispatch(fetchAttributeFromContentType('attribute', 'AAA', 'mlstc')) .then(() => { const actions = store.getActions(); - expect(actions).toHaveLength(2); - expect(actions[1]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE_FOR_CONTENTTYPE); - expect(actions[1].payload.attribute.type).toEqual('Date'); - expect(actions[1].payload.attribute.code).toEqual('mlstc'); + expect(actions).toHaveLength(1); + expect(actions[0]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE_FOR_CONTENTTYPE); + expect(actions[0].payload.attribute.type).toEqual('Date'); + expect(actions[0].payload.attribute.code).toEqual('mlstc'); done(); }) .catch(done.fail); @@ -893,9 +892,9 @@ describe('state/content-type/actions ', () => { store .dispatch(fetchContentTypeAttributeRef('AA1', 'TYPE_COMPOSITE', routeFunc, TYPE_COMPOSITE)) .then(() => { - expect(getContentTypeAttribute).not.toHaveBeenCalled(); + expect(getContentTypeAttribute).toHaveBeenCalled(); const actions = store.getActions(); - expect(actions).toHaveLength(2); + expect(actions).toHaveLength(3); expect(actions[0]).toHaveProperty('type', SET_ACTION_MODE); expect(actions[0]).toHaveProperty('payload', { actionMode: MODE_ADD_ATTRIBUTE_COMPOSITE, @@ -919,9 +918,8 @@ describe('state/content-type/actions ', () => { .then(() => { const actions = store.getActions(MODE_ADD_ATTRIBUTE_COMPOSITE); expect(getContentTypeAttribute).toHaveBeenCalled(); - expect(actions).toHaveLength(2); + expect(actions).toHaveLength(1); expect(actions[0]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE); - expect(actions[1]).toHaveProperty('type', '@@redux-form/INITIALIZE'); done(); }) .catch(done.fail); diff --git a/test/state/data-models/actions.test.js b/test/state/data-models/actions.test.js index 07fbf5a4c..4105a4712 100644 --- a/test/state/data-models/actions.test.js +++ b/test/state/data-models/actions.test.js @@ -84,9 +84,6 @@ describe('state/data-models/actions', () => { it('fetchDataModel calls initialize ', (done) => { store.dispatch(fetchDataModel(1)).then(() => { expect(getDataModel).toHaveBeenCalledWith(1); - const actions = store.getActions(); - expect(actions).toHaveLength(1); - expect(actions[0]).toHaveProperty('type', '@@redux-form/INITIALIZE'); done(); }).catch(done.fail); }); diff --git a/test/state/data-types/actions.test.js b/test/state/data-types/actions.test.js index a97a2b245..a17daf7a5 100644 --- a/test/state/data-types/actions.test.js +++ b/test/state/data-types/actions.test.js @@ -403,7 +403,7 @@ describe('state/data-types/actions ', () => { getDataType.mockImplementationOnce(mockApi({ payload: DATA_TYPES })); store.dispatch(fetchDataType('AAA')).then(() => { const actions = store.getActions(); - expect(actions).toHaveLength(2); + expect(actions).toHaveLength(1); expect(actions[0]).toHaveProperty('type', SET_SELECTED_DATA_TYPE); expect(actions[0]).toHaveProperty('payload'); expect(actions[0].payload).toMatchObject({ dataType: DATA_TYPES }); @@ -470,9 +470,8 @@ describe('state/data-types/actions ', () => { store.dispatch(fetchAttributeFromDataType('attribute', 'AAA', 'Text')).then(() => { expect(getAttributeFromDataType).toHaveBeenCalled(); const actions = store.getActions(); - expect(actions).toHaveLength(2); - expect(actions[0]).toHaveProperty('type', '@@redux-form/INITIALIZE'); - expect(actions[1]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE_FOR_DATATYPE); + expect(actions).toHaveLength(1); + expect(actions[0]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE_FOR_DATATYPE); done(); }).catch(done.fail); }); @@ -655,9 +654,9 @@ describe('state/data-types/actions ', () => { getFormTypeValue.mockReturnValue(TYPE_COMPOSITE); getActionModeDataTypeSelectedAttribute.mockReturnValue(MODE_ADD_ATTRIBUTE_COMPOSITE); store.dispatch(fetchDataTypeAttribute('TYPE_COMPOSITE', ROUTE, TYPE_COMPOSITE)).then(() => { - expect(getDataTypeAttribute).not.toHaveBeenCalled(); + expect(getDataTypeAttribute).toHaveBeenCalled(); const actions = store.getActions(); - expect(actions).toHaveLength(1); + expect(actions).toHaveLength(2); expect(actions[0]).toHaveProperty('type', SET_ACTION_MODE); expect(actions[0]).toHaveProperty('payload', { actionMode: MODE_ADD_ATTRIBUTE_COMPOSITE }); done(); @@ -672,9 +671,8 @@ describe('state/data-types/actions ', () => { store.dispatch(fetchDataTypeAttribute('attribute_code', ROUTE)).then(() => { const actions = store.getActions(MODE_ADD_ATTRIBUTE_COMPOSITE); expect(getDataTypeAttribute).toHaveBeenCalled(); - expect(actions).toHaveLength(2); + expect(actions).toHaveLength(1); expect(actions[0]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE); - expect(actions[1]).toHaveProperty('type', '@@redux-form/INITIALIZE'); done(); }).catch(done.fail); }); diff --git a/test/state/edit-content/actions.test.js b/test/state/edit-content/actions.test.js index 80ce8e0d7..03e77cef7 100644 --- a/test/state/edit-content/actions.test.js +++ b/test/state/edit-content/actions.test.js @@ -213,7 +213,13 @@ describe('editContent thunks', () => { editContent: { workMode: WORK_MODE_ADD, contentType: { typeCode: 'NEWS', typeDescription: 'News' } }, languages, currentUser: { username: 'admin' }, - form: { editcontentform: { values: {} } }, + contentType: { + selected: { + type: 'List', + compositeAttributes: {}, + attributes: [{ type: 'Boolean' }], + }, + }, }); store .dispatch(saveContent({ attributes: [{ value: 'test' }] })).then(() => done()); diff --git a/test/state/file-browser/actions.test.js b/test/state/file-browser/actions.test.js index 02f243e14..9d7bb31eb 100644 --- a/test/state/file-browser/actions.test.js +++ b/test/state/file-browser/actions.test.js @@ -92,10 +92,9 @@ describe('state/file-browser/actions', () => { store.dispatch(fetchFile('file.txt', ['.txt'])).then(() => { expect(getFile).toHaveBeenCalled(); const actions = store.getActions(); - expect(actions).toHaveLength(3); + expect(actions).toHaveLength(2); expect(actions[0]).toHaveProperty('type', TOGGLE_LOADING); - expect(initialize).toHaveBeenCalledWith('CreateTextFileForm', { content: window.atob('base64') }); - expect(actions[2]).toHaveProperty('type', TOGGLE_LOADING); + expect(actions[1]).toHaveProperty('type', TOGGLE_LOADING); done(); }).catch(done.fail); }); diff --git a/test/state/forms/selectors.test.js b/test/state/forms/selectors.test.js deleted file mode 100644 index 20ce10641..000000000 --- a/test/state/forms/selectors.test.js +++ /dev/null @@ -1,16 +0,0 @@ - -import { getPageForm, getPageTemplateForm } from 'state/forms/selectors'; - -jest.unmock('state/forms/selectors'); - -describe('state/forms/selectors', () => { - it('getPageForm should get the "page" form data', () => { - const result = getPageForm({}); - expect(result.form).toBe('page'); - }); - - it('getPageTemplateForm should get the "pageTemplate" form data', () => { - const result = getPageTemplateForm({}); - expect(result.form).toBe('pageTemplate'); - }); -}); diff --git a/test/state/page-templates/selectors.test.js b/test/state/page-templates/selectors.test.js index 1c7b06e44..ccf32219d 100644 --- a/test/state/page-templates/selectors.test.js +++ b/test/state/page-templates/selectors.test.js @@ -170,60 +170,53 @@ describe('state/page-templates/selectors', () => { }); }); - describe('getFormPageTemplate', () => { - it('if there is no page template form data, returns null', () => { - getPageTemplateForm.mockReturnValue(null); - expect(getFormPageTemplate({})).toEqual(null); - }); - - it('if configuration is not a valid json, returns a default configuration', () => { - getPageTemplateForm.mockReturnValue({ - code: 'page_model', - configuration: 'definitely not a valid json', - }); - expect(getFormPageTemplate({})).toEqual({ - code: 'page_model', - configuration: { frames: [] }, - }); - }); - - it('if configuration is a valid json, returns the parsed configuration', () => { - getPageTemplateForm.mockReturnValue({ - code: 'page_model', - configuration: '{ "frames": [{ "pos": 0 }] }', - }); - expect(getFormPageTemplate({})).toEqual({ - code: 'page_model', - configuration: { frames: [{ pos: 0 }] }, - }); - }); - }); - - describe('getPageTemplateFormCellMap', () => { - it('returns a cell map from the form page template', () => { - getPageTemplateForm.mockReturnValue(toFormData(SINGLE_CELL_PAYLOAD)); - expect(getPageTemplateFormCellMap({})).toEqual(SINGLE_CELL_CELL_MAP); - }); - }); - - describe('getPageTemplateFormErrors', () => { - it('if there are no errors, returns an empty array', () => { - getPageTemplateForm.mockReturnValue(toFormData(SINGLE_CELL_PAYLOAD)); - expect(getPageTemplateFormErrors({})).toEqual([]); - }); - - it('if there are errors, returns the page template errors', () => { - getPageTemplateForm.mockReturnValue(toFormData(OVERLAPPING_FRAMES_PAYLOAD)); - expect(getPageTemplateFormErrors({})).toHaveLength(1); - }); - }); - - describe('getPageTemplateFormCellMap', () => { - it('returns a cell map from the form page template', () => { - getPageTemplateForm.mockReturnValue(toFormData(SINGLE_CELL_PAYLOAD)); - expect(getPageTemplateFormCellMap({})).toEqual(SINGLE_CELL_CELL_MAP); - }); - }); + // describe('getFormPageTemplate', () => { + // it('if there is no page template form data, returns null', () => { + // getPageTemplateForm.mockReturnValue(null); + // expect(getFormPageTemplate({})).toEqual(null); + // }); + + // it('if configuration is not a valid json, returns a default configuration', () => { + // getPageTemplateForm.mockReturnValue({ + // code: 'page_model', + // configuration: 'definitely not a valid json', + // }); + // expect(getFormPageTemplate({})).toEqual({ + // code: 'page_model', + // configuration: { frames: [] }, + // }); + // }); + + // it('if configuration is a valid json, returns the parsed configuration', () => { + // getPageTemplateForm.mockReturnValue({ + // code: 'page_model', + // configuration: '{ "frames": [{ "pos": 0 }] }', + // }); + // expect(getFormPageTemplate({})).toEqual({ + // code: 'page_model', + // configuration: { frames: [{ pos: 0 }] }, + // }); + // }); + // }); + + // describe('getPageTemplateFormCellMap', () => { + // it('returns a cell map from the form page template', () => { + // getPageTemplateForm.mockReturnValue(toFormData(SINGLE_CELL_PAYLOAD)); + // expect(getPageTemplateFormCellMap({})).toEqual(SINGLE_CELL_CELL_MAP); + // }); + // }); + + // describe('getPageTemplateFormErrors', () => { + // it('if there are no errors, returns an empty array', () => { + // getPageTemplateForm.mockReturnValue(toFormData(SINGLE_CELL_PAYLOAD)); + // expect(getPageTemplateFormErrors({})).toEqual([]); + // }); + + // it('if there are errors, returns the page template errors', () => { + // getPageTemplateForm.mockReturnValue(toFormData(OVERLAPPING_FRAMES_PAYLOAD)); + // expect(getPageTemplateFormErrors({})).toHaveLength(1); + // }); + // }); describe('getSelectedPageTemplatePageRefs', () => { it('returns the selected page template pageReferences', () => { diff --git a/test/state/pages/actions.test.js b/test/state/pages/actions.test.js index c5d42b9d9..48018bc8d 100644 --- a/test/state/pages/actions.test.js +++ b/test/state/pages/actions.test.js @@ -611,7 +611,6 @@ describe('state/pages/actions', () => { getPageSettings.mockImplementation(mockApi({ payload: { a: 'b' } })); store.dispatch(fetchPageSettings()).then(() => { expect(getPageSettings).toHaveBeenCalled(); - expect(initialize).toHaveBeenCalledWith('settings', { a: 'b' }); done(); }).catch(done.fail); }); @@ -835,9 +834,8 @@ describe('clearSearchPage', () => { it('calls action clearSearch and initialize form search ', () => { store.dispatch(clearSearchPage()); const actions = store.getActions(); - expect(actions).toHaveLength(2); + expect(actions).toHaveLength(1); expect(actions[0]).toHaveProperty('type', CLEAR_SEARCH); - expect(initialize).toHaveBeenCalled(); }); }); @@ -883,9 +881,8 @@ describe('clonePage', () => { it('when clonePage succeeds, should call router PAGE_ADD and initialize FORM', (done) => { store.dispatch(clonePage('page')).then(() => { const actions = store.getActions(); - expect(actions).toHaveLength(1); + expect(actions).toHaveLength(0); expect(history.push).toHaveBeenCalledWith(`${ROUTE_PAGE_CLONE}?pageCode=undefined`); - expect(initialize).toHaveBeenCalled(); done(); }).catch(done.fail); }); diff --git a/test/state/profile-types/actions.test.js b/test/state/profile-types/actions.test.js index e26817bc6..982266bc0 100644 --- a/test/state/profile-types/actions.test.js +++ b/test/state/profile-types/actions.test.js @@ -327,7 +327,7 @@ describe('state/profile-types/actions ', () => { getProfileType.mockImplementationOnce(mockApi({ payload: PROFILE_TYPES })); store.dispatch(fetchProfileType('AAA')).then(() => { const actions = store.getActions(); - expect(actions).toHaveLength(2); + expect(actions).toHaveLength(1); expect(actions[0]).toHaveProperty('type', SET_SELECTED_PROFILE_TYPE); expect(actions[0]).toHaveProperty('payload'); expect(actions[0].payload).toMatchObject({ profileType: PROFILE_TYPES }); @@ -392,9 +392,8 @@ describe('state/profile-types/actions ', () => { store.dispatch(fetchAttributeFromProfileType('attribute', 'AAA', 'Date')).then(() => { expect(getAttributeFromProfileType).toHaveBeenCalled(); const actions = store.getActions(); - expect(actions).toHaveLength(2); - expect(actions[0]).toHaveProperty('type', '@@redux-form/INITIALIZE'); - expect(actions[1]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE_FOR_PROFILETYPE); + expect(actions).toHaveLength(1); + expect(actions[0]).toHaveProperty('type', SET_SELECTED_ATTRIBUTE_FOR_PROFILETYPE); done(); }).catch(done.fail); }); diff --git a/test/state/user-profile/actions.test.js b/test/state/user-profile/actions.test.js index a6d23e06b..2195dcab3 100644 --- a/test/state/user-profile/actions.test.js +++ b/test/state/user-profile/actions.test.js @@ -66,11 +66,9 @@ describe('fetchUserProfile', () => { expect(getUserProfile).toHaveBeenCalledWith(USER_NAME); const actions = store.getActions(); - expect(actions).toHaveLength(4); + expect(actions).toHaveLength(2); expect(actions[0]).toHaveProperty('type', SET_USER_PROFILE); expect(actions[1]).toHaveProperty('type', SET_SELECTED_PROFILE_TYPE); - expect(actions[2]).toHaveProperty('type', '@@redux-form/INITIALIZE'); - expect(actions[3]).toHaveProperty('type', '@@redux-form/INITIALIZE'); done(); }).catch(done.fail); }); diff --git a/test/state/user-settings/actions.test.js b/test/state/user-settings/actions.test.js index 718536324..73a2e9fb1 100644 --- a/test/state/user-settings/actions.test.js +++ b/test/state/user-settings/actions.test.js @@ -50,11 +50,10 @@ describe('state/user-settings/actions', () => { store.dispatch(fetchUserSettings()).then(() => { const actions = store.getActions(); expect(getUserSettings).toHaveBeenCalled(); - expect(actions).toHaveLength(4); + expect(actions).toHaveLength(3); expect(actions[0]).toHaveProperty('type', TOGGLE_LOADING); expect(actions[1]).toHaveProperty('type', SET_USER_SETTINGS); - expect(actions[2]).toHaveProperty('type', '@@redux-form/INITIALIZE'); - expect(actions[3]).toHaveProperty('type', TOGGLE_LOADING); + expect(actions[2]).toHaveProperty('type', TOGGLE_LOADING); done(); }).catch(done.fail); }); diff --git a/test/state/users/actions.test.js b/test/state/users/actions.test.js index 2e680b5f6..6b3f21730 100644 --- a/test/state/users/actions.test.js +++ b/test/state/users/actions.test.js @@ -362,11 +362,10 @@ describe('state/users/actions', () => { store.dispatch(sendPostMyPassword({})).then(() => { expect(postMyPassword).toHaveBeenCalledWith({}); const actions = store.getActions(); - expect(actions).toHaveLength(4); + expect(actions).toHaveLength(3); expect(actions[0]).toHaveProperty('type', ADD_TOAST); expect(actions[1]).toHaveProperty('type', CLEAR_ERRORS); - expect(actions[2]).toHaveProperty('type', '@@redux-form/RESET'); - expect(actions[3]).toHaveProperty('type', SET_VISIBLE_MODAL); + expect(actions[2]).toHaveProperty('type', SET_VISIBLE_MODAL); done(); }).catch(done.fail); }); diff --git a/test/state/widgets/actions.test.js b/test/state/widgets/actions.test.js index fb66b2ca3..de5f5e386 100644 --- a/test/state/widgets/actions.test.js +++ b/test/state/widgets/actions.test.js @@ -200,19 +200,7 @@ describe('state/widgets/actions', () => { getWidget.mockImplementationOnce(mockApi({ payload: WIDGET })); store.dispatch(fetchWidget()).then(() => { const actions = store.getActions(); - expect(actions).toHaveLength(3); - expect(initialize).toHaveBeenCalled(); - const initializeAction = actions[1]; - expect(initializeAction).toHaveProperty('type', '@@redux-form/INITIALIZE'); - expect(initializeAction).toHaveProperty('payload'); - expect(initializeAction.payload).toEqual({ - code: WIDGET.code, - titles: WIDGET.titles, - group: WIDGET.group, - configUi: '', - customUi: WIDGET.guiFragments[0].customUi, - icon: WIDGET.icon, - }); + expect(actions).toHaveLength(2); done(); }).catch(done.fail); }); @@ -221,19 +209,7 @@ describe('state/widgets/actions', () => { getWidget.mockImplementationOnce(mockApi({ payload: WIDGET_NULL_GROUP })); store.dispatch(fetchWidget()).then(() => { const actions = store.getActions(); - expect(actions).toHaveLength(3); - expect(initialize).toHaveBeenCalled(); - const initializeAction = actions[1]; - expect(initializeAction).toHaveProperty('type', '@@redux-form/INITIALIZE'); - expect(initializeAction).toHaveProperty('payload'); - expect(initializeAction.payload).toEqual({ - code: WIDGET_NULL_GROUP.code, - titles: WIDGET_NULL_GROUP.titles, - group: FREE_ACCESS_GROUP_VALUE, - configUi: '', - customUi: WIDGET_NULL_GROUP.guiFragments[0].customUi, - icon: WIDGET.icon, - }); + expect(actions).toHaveLength(2); done(); }).catch(done.fail); }); @@ -242,8 +218,8 @@ describe('state/widgets/actions', () => { getWidget.mockImplementationOnce(mockApi({ payload: WIDGET })); store.dispatch(fetchWidget()).then(() => { const actions = store.getActions(); - expect(actions).toHaveLength(3); - const selectWidgetAction = actions[2]; + expect(actions).toHaveLength(2); + const selectWidgetAction = actions[1]; expect(selectWidgetAction).toHaveProperty('type', SET_SELECTED_WIDGET); expect(selectWidgetAction).toHaveProperty('payload'); expect(selectWidgetAction.payload).toMatchObject({ widget: WIDGET }); diff --git a/test/ui/component-repository/settings/edit/SettingsEditFormContainer.test.js b/test/ui/component-repository/settings/edit/SettingsEditFormContainer.test.js index d65fbefbf..dd9f7b464 100644 --- a/test/ui/component-repository/settings/edit/SettingsEditFormContainer.test.js +++ b/test/ui/component-repository/settings/edit/SettingsEditFormContainer.test.js @@ -45,7 +45,7 @@ describe('SettingsListContainer', () => { it('should dispatch an action if onWillMount is called', () => { props.onWillMount(12); expect(dispatchMock).toHaveBeenCalled(); - expect(fetchComponentRepository).toHaveBeenCalledWith(12, true); + expect(fetchComponentRepository).toHaveBeenCalledWith(12); }); it('should dispatch an action if onSubmit is called', () => {