diff --git a/cypress/fixtures/sims.json b/cypress/fixtures/sims.json index 5deba54ba..1fd09a0ad 100644 --- a/cypress/fixtures/sims.json +++ b/cypress/fixtures/sims.json @@ -17,7 +17,7 @@ { "uri": "uri1-bis", "url": "http://google.fr?q=url-1", - "updatedDate": "01/01/2019", + "lastRefresh": "01/01/2019", "labelLg1": "labelLg1-0", "labelLg2": "labelLg2-0", "lang": "fr", @@ -27,7 +27,7 @@ { "uri": "uri2-bis", "url": "http://google.fr?q=url-2", - "updatedDate": "01/02/2019", + "lastRefresh": "01/02/2019", "labelLg1": "labelLg1-1", "labelLg2": "labelLg2-1", "descriptionLg1": "descriptionLg1-2", diff --git a/cypress/integration/home.spec.js b/cypress/integration/home.spec.js index 0cfa64674..7dcf8c850 100644 --- a/cypress/integration/home.spec.js +++ b/cypress/integration/home.spec.js @@ -1,9 +1,7 @@ describe('Home Page', function() { it(`Should go to the Concepts page and come back`, function() { cy.server().visit(`/`); - cy.get('.img-block a:nth-child(1)') - .first() - .click(); + cy.get('li:nth-child(1) a').click(); cy.url().should('match', /\/concepts$/); cy.go('back'); @@ -14,10 +12,7 @@ describe('Home Page', function() { it(`Should go to the Nomenclatures page and come back`, function() { cy.server().visit(`/`); - //cy.get('a[href="/classifications"]'); - cy.get('.img-block a:nth-child(2)') - .first() - .click(); + cy.get('li:nth-child(2) a').click(); cy.url().should('match', /\/classifications$/); cy.go('back'); cy.get('.page-title').contains( @@ -26,13 +21,15 @@ describe('Home Page', function() { }); it(`Should go to the Operations page and come back`, function() { cy.server().visit(`/`); - cy.get('.img-block a:nth-child(3)') - .first() - .click(); + cy.get('li:nth-child(3) a').click(); cy.url().should('match', /\/operations\/series$/); cy.go('back'); cy.get('.page-title').contains( 'Application de gestion des métadonnées de référence' ); }); + it(`Should contain a footer`, function() { + cy.server().visit(`/`); + cy.get('footer').should('exist'); + }); }); diff --git a/src/js/actions/operations/documents/list.js b/src/js/actions/operations/documents/list.js index a5fb8d92b..a991eb948 100644 --- a/src/js/actions/operations/documents/list.js +++ b/src/js/actions/operations/documents/list.js @@ -1,4 +1,4 @@ -import api from 'js/remote-api/operations-api'; +import api from 'js/remote-api/api'; import * as A from 'js/actions/constants'; import { sortArray } from 'js/utils/array-utils'; @@ -16,64 +16,10 @@ export default () => dispatch => { payload: { results: sortByLabel(results) }, }), err => { - const results = [ - { - uri: 'uri1-bis', - url: 'http://google.fr?q=url-1', - updatedDate: '01/01/2019', - lang: 'fr', - labelLg1: 'Document 1 - label en Langue 1', - labelLg2: 'Document 1 - label en Langue 2', - descriptionLg1: 'Description 1 en Langue 1', - descriptionLg2: 'Description 1 en Langue 2', - }, - { - uri: 'uri2-bis', - url: 'http://google.fr?q=url-2', - updatedDate: '01/02/2019', - labelLg1: 'Document 2 - label en Langue 1', - labelLg2: 'Document 2 - label en Langue 2', - descriptionLg1: 'Description 2 en Langue 1', - descriptionLg2: 'Description 2 en Langue 2', - }, - { - uri: 'uri3-bis', - url: 'http://google.fr?q=url-2', - labelLg1: 'Document 3 - label en Langue 1', - labelLg2: 'Document 3 - label en Langue 2', - descriptionLg1: 'Description 3 en Langue 1', - descriptionLg2: 'Description 3 en Langue 2', - lang: 'fr', - }, - - { - uri: 'uri5-bis', - url: 'http://google.fr?q=url-2', - labelLg1: 'Document 5 - label en Langue 1', - labelLg2: 'Document 5 - label en Langue 2', - descriptionLg1: 'Description 5 en Langue 1', - descriptionLg2: 'Description 5 en Langue 2', - lang: 'fr', - }, - { - uri: 'uri4-bis', - url: 'http://google.fr?q=url-2', - updatedDate: '01/02/2019', - labelLg1: 'Document 4 - label en Langue 1', - labelLg2: 'Document 4 - label en Langue 2', - descriptionLg1: 'Description 4 en Langue 1', - descriptionLg2: 'Description 4 en Langue 2', - }, - ]; dispatch({ - type: A.LOAD_OPERATIONS_DOCUMENTS_SUCCESS, - payload: { results: sortByLabel(results) }, - }); - - /*dispatch({ type: A.LOAD_OPERATIONS_DOCUMENTS_FAILURE, payload: { err }, - })*/ + }) } ); }; diff --git a/src/js/actions/operations/series/item.js b/src/js/actions/operations/series/item.js index 9b8035db4..9d8e82ce1 100644 --- a/src/js/actions/operations/series/item.js +++ b/src/js/actions/operations/series/item.js @@ -13,7 +13,7 @@ export const saveSerie = (series, callback) => dispatch => { type: A.SAVE_OPERATIONS_SERIE_SUCCESS, payload: { ...series, - id + id, }, }); callback(id); diff --git a/src/js/actions/operations/sims/item.js b/src/js/actions/operations/sims/item.js index 86ff18b2b..bd24e5e8d 100644 --- a/src/js/actions/operations/sims/item.js +++ b/src/js/actions/operations/sims/item.js @@ -109,7 +109,7 @@ export default id => (dispatch, getState) => { { uri: 'uri1-bis', url: 'http://google.fr?q=url-1', - updatedDate: '01/01/2019', + lastRefresh: '01/01/2019', lang: 'fr', labelLg1: 'Document 1 - label en Langue 1', labelLg2: 'Document 1 - label en Langue 2', @@ -119,7 +119,7 @@ export default id => (dispatch, getState) => { { uri: 'uri2-bis', url: 'http://google.fr?q=url-2', - updatedDate: '01/02/2019', + lastRefresh: '01/02/2019', labelLg1: 'Document 2 - label en Langue 1', labelLg2: 'Document 2 - label en Langue 2', descriptionLg1: 'Description 2 en Langue 1', diff --git a/src/js/components/operations/msd/documents/documents-bloc/index.js b/src/js/components/operations/msd/documents/documents-bloc/index.js index cb76db4ac..232baf81d 100644 --- a/src/js/components/operations/msd/documents/documents-bloc/index.js +++ b/src/js/components/operations/msd/documents/documents-bloc/index.js @@ -5,15 +5,19 @@ import D from 'js/i18n'; import loadDocuments from 'js/actions/operations/documents/list'; import './style.scss'; import { getLang } from 'js/i18n/build-dictionary'; -import { LOADED, NOT_LOADED } from 'js/constants'; +import { NOT_LOADED } from 'js/constants'; +import { + getOperationsDocumentsStatus, + getOperationsDocuments, +} from 'js/reducers/operations/selector'; /** * @typedef {Object} DocumentsBlocProps - * @property {import('js/actions/operations/sims/item').SimsDocuments[]=} documents + * @property {import('js/types').SimsDocuments[]=} documents * @property {String=} localPrefix * @property {Boolean=} editMode * @property {(string) => void } deleteHandler * @property {(string) => void } addHandler - * @property {import('js/actions/operations/sims/item').SimsDocuments[]} documentStores + * @property {import('js/types').SimsDocuments[]} documentStores */ /** @@ -32,6 +36,7 @@ export function DocumentsBloc({ }) { const currentDocuments = sortArray(`label${localPrefix}`)(documents); const currentDocumentsIds = currentDocuments.map(doc => doc.uri); + const otherDocuments = sortArray(`label${localPrefix}`)( documentStores.filter( document => !currentDocumentsIds.includes(document.uri) @@ -41,13 +46,13 @@ export function DocumentsBloc({ const [panelStatus, setPanelStatus] = useState(false); function addAsideToTheDocument(document) { - let updatedDate; - if (document.updatedDate) { - updatedDate = new Intl.DateTimeFormat(getLang()).format( - new Date(document.updatedDate) + let lastRefresh; + if (document.lastRefresh) { + lastRefresh = new Intl.DateTimeFormat(getLang()).format( + new Date(document.lastRefresh) ); } - const aside = [document.lang, updatedDate].filter(val => !!val).join('-'); + const aside = [document.lang, lastRefresh].filter(val => !!val).join('-'); return { ...document, aside, @@ -69,17 +74,21 @@ export function DocumentsBloc({ document, btnBlocFunction = defaultBtnBlocFunction ) { + const label = + document[`label${localPrefix}`] || document.labelLg1 || document.labelLg2; return ( -
  • - - {document[`label${localPrefix}`]} - - ({document.aside}) +
  • + + + {label} + + ({document.aside}) + {editMode && !isSecondLang && btnBlocFunction(document)}
  • ); @@ -93,8 +102,7 @@ export function DocumentsBloc({ .map(document => displayHTMLForDocument(document))} )} - - {editMode && !isSecondLang && otherDocuments.length > 0 && ( + {editMode && !isSecondLang && (
    {panelStatus && ( @@ -146,11 +154,7 @@ class DocumentsBlocContainer extends Component { } } render() { - return ( - this.props.documentStoresStatus === LOADED && ( - - ) - ); + return ; } } @@ -160,8 +164,8 @@ const mapDispatchToProps = { const mapStateToProps = state => { return { - documentStoresStatus: state.operationsDocuments.status, - documentStores: state.operationsDocuments.results, + documentStoresStatus: getOperationsDocumentsStatus(state), + documentStores: getOperationsDocuments(state), }; }; diff --git a/src/js/components/operations/msd/documents/documents-bloc/index.spec.js b/src/js/components/operations/msd/documents/documents-bloc/index.spec.js index ada0d0164..ecd70639d 100644 --- a/src/js/components/operations/msd/documents/documents-bloc/index.spec.js +++ b/src/js/components/operations/msd/documents/documents-bloc/index.spec.js @@ -10,7 +10,7 @@ const documents = [ { uri: 'uri1-bis', url: 'http://google.fr?q=url-1', - updatedDate: '2019-03-04T10:00:00.000Z', + lastRefresh: '2019-03-04T10:00:00.000Z', labelLg1: 'B labelLg1-0', labelLg2: 'B labelLg2-0', lang: 'fr', @@ -23,7 +23,7 @@ const documents = [ { uri: 'uri2-bis', url: 'http://google.fr?q=url-2', - updatedDate: '2019-04-04T10:00:00.000Z', + lastRefresh: '2019-04-04T10:00:00.000Z', labelLg1: 'A labelLg1-1', labelLg2: 'A labelLg2-1', descriptionLg1: 'descriptionLg1-2', @@ -69,11 +69,11 @@ describe('DocumentsBloc', () => { general.find('li').forEach((li, i) => { expect(li.html()).toEqual( - `
  • ${ orderedList[i].labelLg1 - }(${orderedList[i].aside})
  • ` + }(${orderedList[i].aside})` ); }); }); @@ -89,11 +89,11 @@ describe('DocumentsBloc', () => { general.find('li').forEach((li, i) => { expect(li.html()).toEqual( - `
  • ${ orderedList[i].labelLg2 - }(${orderedList[i].aside})
  • ` + }(${orderedList[i].aside})` ); }); }); @@ -130,7 +130,7 @@ describe('DocumentsBloc', () => { }); }); - it('should not display the Add Document button if there is not more document to add', () => { + it('should display the Add Document button if there is not more document to add', () => { const general = shallow( { /> ); - expect(general.find('.documentsbloc__add')).toHaveLength(0); + expect(general.find('.documentsbloc__add')).toHaveLength(1); }); it('should display the Add Document button if there is more than on document available', () => { const general = shallow( @@ -158,7 +158,7 @@ describe('DocumentsBloc', () => { /> ); - expect(general.find('.documentsbloc__add')).toHaveLength(0); + expect(general.find('.documentsbloc__add')).toHaveLength(1); }); it('should not display the Add Document button for Lg2', () => { diff --git a/src/js/components/operations/msd/documents/documents-bloc/style.scss b/src/js/components/operations/msd/documents/documents-bloc/style.scss index 9eab727b1..02963b961 100644 --- a/src/js/components/operations/msd/documents/documents-bloc/style.scss +++ b/src/js/components/operations/msd/documents/documents-bloc/style.scss @@ -15,3 +15,11 @@ padding-left: 0; } } + +.documentbloc__item { + display: flex; + + span { + flex: 2 1 auto; + } +} diff --git a/src/js/components/operations/msd/index.js b/src/js/components/operations/msd/index.js index 75ecb5c14..73da9a31f 100644 --- a/src/js/components/operations/msd/index.js +++ b/src/js/components/operations/msd/index.js @@ -39,7 +39,6 @@ export const DUPLICATE = 'DUPLICATE'; const mapToParentType = { operation: { load: 'loadOperation', - path: 'operation', }, series: { load: 'loadSerie' }, indicator: { load: 'loadIndicator' }, @@ -196,13 +195,19 @@ const mapStateToProps = (state, ownProps) => { function getCurrentParent(parentType) { if (parentType === 'operation') { - return select.getOperation(state); + return [ + select.getOperation(state), + state.operationsIndicatorCurrentStatus, + ]; } if (parentType === 'series') { - return select.getSerie(state); + return [select.getSerie(state), state.operationsSeriesCurrentStatus]; } if (parentType === 'indicator') { - return select.getIndicator(state); + return [ + select.getIndicator(state), + state.operationsIndicatorCurrentStatus, + ]; } } @@ -217,11 +222,12 @@ const mapStateToProps = (state, ownProps) => { case CREATE: idParent = extractIdParent(ownProps); parentType = ownProps.match.params[0]; - const currentParent = getCurrentParent(parentType); + const [currentParent, currentParentStatus] = getCurrentParent(parentType); currentSims = { ...getLabelsFromParent(currentParent, parentType), }; - isParentLoaded = currentParent.id === idParent; + isParentLoaded = + currentParentStatus !== NOT_LOADED || currentParent.id === idParent; break; default: currentSims = select.getOperationsSimsCurrent(state); diff --git a/src/js/reducers/index.js b/src/js/reducers/index.js index 65ec45347..1e7738af7 100755 --- a/src/js/reducers/index.js +++ b/src/js/reducers/index.js @@ -107,10 +107,9 @@ export const getLangs = state => { export const getStatus = (state, op) => remoteCallsSelectors.getStatus(state.remoteCalls, op); -export const getError = (state, op) => +export const getError = (state, op) => remoteCallsSelectors.getError(state.remoteCalls, op); - export const getNewlyCreatedId = state => remoteCallsSelectors.getNewlyCreatedId(state.remoteCalls); diff --git a/src/js/reducers/operations/loadStatus.js b/src/js/reducers/operations/loadStatus.js index a50d3df2f..32f800051 100644 --- a/src/js/reducers/operations/loadStatus.js +++ b/src/js/reducers/operations/loadStatus.js @@ -21,22 +21,48 @@ export const operationsSimsCurrentStatus = function( } }; +function trackStatus(LOAD_SUCCESS, SAVE, SAVE_SUCCESS, LOAD) { + return (state = NOT_LOADED, action) => { + switch (action.type) { + case LOAD_SUCCESS: + case SAVE: + return LOADED; + case SAVE_SUCCESS: + return NOT_LOADED; + case LOAD: + return LOADING; + default: + return state; + } + }; +} + /** * Track the loading of an operation. Used to avoid sending multiple request simultaneously */ -export const operationsOperationCurrentStatus = function( - state = NOT_LOADED, - action -) { - switch (action.type) { - case A.LOAD_OPERATIONS_OPERATION_SUCCESS: - case A.SAVE_OPERATIONS_OPERATION: - return LOADED; - case A.SAVE_OPERATIONS_OPERATION_SUCCESS: - return NOT_LOADED; - case A.LOAD_OPERATIONS_OPERATION: - return LOADING; - default: - return state; - } -}; +export const operationsOperationCurrentStatus = trackStatus( + A.LOAD_OPERATIONS_OPERATION_SUCCESS, + A.SAVE_OPERATIONS_OPERATION, + A.SAVE_OPERATIONS_OPERATION_SUCCESS, + A.LOAD_OPERATIONS_OPERATION +); + +/** + * Track the loading of an indicator. Used to avoid sending multiple request simultaneously + */ +export const operationsIndicatorCurrentStatus = trackStatus( + A.LOAD_OPERATIONS_INDICATOR_SUCCESS, + A.SAVE_OPERATIONS_INDICATOR, + A.SAVE_OPERATIONS_INDICATOR_SUCCESS, + A.LOAD_OPERATIONS_INDICATOR +); + +/** + * Track the loading of an series. Used to avoid sending multiple request simultaneously + */ +export const operationsSeriesCurrentStatus = trackStatus( + A.LOAD_OPERATIONS_SERIE_SUCCESS, + A.SAVE_OPERATIONS_SERIE, + A.SAVE_OPERATIONS_SERIE_SUCCESS, + A.LOAD_OPERATIONS_SERIE +); diff --git a/src/js/reducers/operations/selector.js b/src/js/reducers/operations/selector.js index 78f1f09cf..10c7af6a3 100644 --- a/src/js/reducers/operations/selector.js +++ b/src/js/reducers/operations/selector.js @@ -7,3 +7,11 @@ export const getOperationsCodesList = state => { const operationsCodesList = state.operationsCodesList || {}; return operationsCodesList.results || []; }; + +export const getOperationsDocuments = state => { + return state.operationsDocuments.results || []; +}; + +export const getOperationsDocumentsStatus = state => { + return state.operationsDocuments.status; +}; diff --git a/src/js/remote-api/api.js b/src/js/remote-api/api.js index 6ed46449e..aebc3cf26 100755 --- a/src/js/remote-api/api.js +++ b/src/js/remote-api/api.js @@ -10,6 +10,8 @@ const api = { }, res => res, ], + getDocumentsList: () => ['documents'], + getDissStatusList: () => ['disseminationStatus'], getStampList: () => ['stamps'], getRoleList: () => ['roles'], diff --git a/src/js/remote-api/operations-api.js b/src/js/remote-api/operations-api.js index 6a225d70c..08a088746 100644 --- a/src/js/remote-api/operations-api.js +++ b/src/js/remote-api/operations-api.js @@ -9,7 +9,6 @@ const api = { getSeriesList: () => ['series'], getOperationsList: () => ['operations'], getFamiliesList: () => ['families'], - getDocumentsList: () => ['documents'], getMetadataStructureList: () => ['metadataStructureDefinition'], getMetadataAttributesList: () => ['metadataAttributes'], diff --git a/src/js/types/index.js b/src/js/types/index.js index ec833e291..cc1b7e70b 100644 --- a/src/js/types/index.js +++ b/src/js/types/index.js @@ -31,7 +31,7 @@ * @typedef {Object} SimsDocuments * @property {string} uri * @property {string} url - * @property {string=} updatedDate + * @property {string=} lastRefresh * @property {string} labelLg1 * @property {string} labelLg2 * @property {string=} lang