diff --git a/grails-app/conf/runtime.groovy b/grails-app/conf/runtime.groovy index 29bc35a4b03..950ea7e45fd 100644 --- a/grails-app/conf/runtime.groovy +++ b/grails-app/conf/runtime.groovy @@ -630,6 +630,10 @@ openboxes { [ widgetId: "discrepancy", order : 6 + ], + [ + widgetId: "overdueInbound", + order : 7 ] ] } @@ -676,6 +680,10 @@ openboxes { [ widgetId: "discrepancy", order : 6 + ], + [ + widgetId: "overdueInbound", + order : 7 ] ] } @@ -1005,6 +1013,15 @@ openboxes { endpoint = "/api/dashboard/discrepancy" timeFilter = true } + overdueInbound { + enabled = true + title = "react.dashboard.overdueInbound.title.label" + info = "react.dashboard.overdueInbound.info.label" + graphType = "table" + type = 'graph' + endpoint = "/api/shipments/exceptions/overdue?max=5" + responseAdapter = "overdueInboundShipments" + } delayedShipments { enabled = true title = "react.dashboard.delayedShipments.title.label" diff --git a/grails-app/i18n/messages.properties b/grails-app/i18n/messages.properties index eccb253c8c1..e15ff3da948 100644 --- a/grails-app/i18n/messages.properties +++ b/grails-app/i18n/messages.properties @@ -4548,6 +4548,12 @@ react.dashboard.discrepancy.title.label=Items received with a discrepancy react.dashboard.discrepancy.info.label=List of shipments where there was any discrepancy between shipped and received, filterable by month react.dashboard.delayedShipments.title.label=Delayed Incoming Stock Movements react.dashboard.delayedShipments.info.label=Air shipments not received 30 days after ship date; Sea shipments not received 60 days after ship date; land shipments not received 7 days after ship date +react.dashboard.overdueInbound.title.label=Overdue inbound +react.dashboard.overdueInbound.info.label=Inbound shipments whose expected delivery date has passed and that have not been received yet, most overdue first +react.dashboard.overdueInbound.column.shipment.label=Shipment +react.dashboard.overdueInbound.column.origin.label=Origin +react.dashboard.overdueInbound.column.daysLate.label=Days late +react.dashboard.overdueInbound.empty.label=No overdue inbound shipments react.dashboard.lossCausedByExpiry.title.label=Value of Stock Lost to Expiry react.dashboard.percentageAdHoc.title.label=Stock vs ad-hoc requests last month react.dashboard.percentageAdHoc.info.label=Requests in the previous month broken down by stock vs ad hoc diff --git a/src/js/actions/index.js b/src/js/actions/index.js index 892a8f80284..b1b387de5e0 100644 --- a/src/js/actions/index.js +++ b/src/js/actions/index.js @@ -1,7 +1,7 @@ /* eslint no-param-reassign: ["error", { "props": false }] */ import _ from 'lodash'; import queryString from 'query-string'; -import { addTranslationForLanguage } from 'react-localize-redux'; +import { addTranslationForLanguage, getTranslate } from 'react-localize-redux'; import { ADD_EMPTY_ROW, @@ -85,7 +85,9 @@ import RoleType from 'consts/roleType'; import { UnitOfMeasureType } from 'consts/UnitOfMeasureType'; import apiClient, { parseResponse } from 'utils/apiClient'; import { removeBinLocationData } from 'utils/cycleCountUtils'; +import dashboardResponseAdapters from 'utils/dashboard-response-adapters'; import { fetchBins, getLotNumbersByProductIds, mapShipmentTypes } from 'utils/option-utils'; +import { translateWithDefaultMessage } from 'utils/Translate'; export function showSpinner() { return { @@ -304,16 +306,27 @@ function getParameterList(params = '', locationId = '', userId = '') { return listParams; } +function getTranslateFromState(getState) { + return translateWithDefaultMessage(getTranslate(getState().localize)); +} + +function adaptIndicatorResponse(indicatorConfig, responseData, translate) { + const adapter = dashboardResponseAdapters[indicatorConfig.responseAdapter]; + return adapter ? adapter(responseData, translate) : responseData; +} + function fetchGraphIndicator( dispatch, indicatorConfig, locationId = '', params = '', + translate = (id, defaultMessage) => defaultMessage || id, ) { const id = indicatorConfig.order; const listParams = getParameterList(params, locationId); - const url = `${indicatorConfig.endpoint}?${listParams}`; + const separator = indicatorConfig.endpoint.includes('?') ? '&' : '?'; + const url = `${indicatorConfig.endpoint}${separator}${listParams}`; dispatch({ type: FETCH_GRAPHS, @@ -328,7 +341,7 @@ function fetchGraphIndicator( }); apiClient.get(url).then((res) => { - const indicatorData = res.data; + const indicatorData = adaptIndicatorResponse(indicatorConfig, res.data, translate); dispatch({ type: FETCH_GRAPHS, payload: { @@ -400,14 +413,27 @@ function fetchNumberIndicator( } export function reloadIndicator(indicatorConfig, params, locationId) { - return (dispatch) => { + return (dispatch, getState) => { // new reference so that the original config is not modified const indicatorConfigData = JSON.parse(JSON.stringify(indicatorConfig)); - fetchGraphIndicator(dispatch, indicatorConfigData, locationId, params); + fetchGraphIndicator( + dispatch, + indicatorConfigData, + locationId, + params, + getTranslateFromState(getState), + ); }; } -function getData(dispatch, dashboardConfig, locationId, config = 'personal', userId = '') { +function getData( + dispatch, + dashboardConfig, + locationId, + config = 'personal', + userId = '', + translate, +) { // new reference so that the original config is not modified const dashboard = dashboardConfig.dashboard[config] || {}; @@ -423,7 +449,7 @@ function getData(dispatch, dashboardConfig, locationId, config = 'personal', use _.forEach(visibleWidgets, (widgetConfig) => { if (widgetConfig.type === 'graph') { - fetchGraphIndicator(dispatch, widgetConfig, locationId, ''); + fetchGraphIndicator(dispatch, widgetConfig, locationId, '', translate); } else if (widgetConfig.type === 'number') { fetchNumberIndicator(dispatch, widgetConfig, locationId, userId); } @@ -436,7 +462,7 @@ export function fetchIndicators( locationId, userId, ) { - return (dispatch) => { + return (dispatch, getState) => { dispatch({ type: SET_ACTIVE_CONFIG, payload: { @@ -444,7 +470,7 @@ export function fetchIndicators( }, }); - getData(dispatch, configData, locationId, config, userId); + getData(dispatch, configData, locationId, config, userId, getTranslateFromState(getState)); }; } @@ -455,9 +481,15 @@ export function resetIndicators() { } export function addToIndicators(widgetConfig, locationId, userId = '') { - return (dispatch) => { + return (dispatch, getState) => { if (widgetConfig.type === 'graph') { - fetchGraphIndicator(dispatch, widgetConfig, locationId, ''); + fetchGraphIndicator( + dispatch, + widgetConfig, + locationId, + '', + getTranslateFromState(getState), + ); } else if (widgetConfig.type === 'number') { fetchNumberIndicator(dispatch, widgetConfig, locationId, userId); } @@ -478,8 +510,8 @@ export function reorderIndicators({ oldIndex, newIndex }, e, type) { } // eslint-disable-next-line default-param-last -export function fetchConfigAndData(locationId, config = 'personal', userId, id, filterSelected) { - return (dispatch) => { +export function fetchConfigAndData(locationId, config = 'personal', userId, id) { + return (dispatch, getState) => { apiClient.get(`/api/dashboard/${id}/config`).then((res) => { dispatch({ type: FETCH_CONFIG_AND_SET_ACTIVE, @@ -488,7 +520,7 @@ export function fetchConfigAndData(locationId, config = 'personal', userId, id, activeConfig: config, }, }); - getData(dispatch, res.data, locationId, config, userId, filterSelected); + getData(dispatch, res.data, locationId, config, userId, getTranslateFromState(getState)); }); }; } diff --git a/src/js/components/dashboard/TableCard.jsx b/src/js/components/dashboard/TableCard.jsx index 2c8dd200ca8..ba629e8b13a 100644 --- a/src/js/components/dashboard/TableCard.jsx +++ b/src/js/components/dashboard/TableCard.jsx @@ -2,6 +2,8 @@ import React from 'react'; import PropTypes from 'prop-types'; +import Translate from 'utils/Translate'; + /* global _ */ const TableCard = (props) => { const { @@ -60,6 +62,16 @@ const TableCard = (props) => {
+ {!data.body.length && data.emptyMessage ? ( +