Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions grails-app/conf/runtime.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ openboxes {
[
widgetId: "discrepancy",
order : 6
],
[
widgetId: "overdueInbound",
order : 7
]
]
}
Expand Down Expand Up @@ -676,6 +680,10 @@ openboxes {
[
widgetId: "discrepancy",
order : 6
],
[
widgetId: "overdueInbound",
order : 7
]
]
}
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 46 additions & 14 deletions src/js/actions/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Comment on lines +309 to +316

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: responseAdapter hook is a generic, backward-compatible extension

The new responseAdapter mechanism in src/js/actions/index.js:313-316 and src/js/utils/dashboard-response-adapters.js is threaded correctly through all four thunks that reach fetchGraphIndicator (reloadIndicator, fetchIndicators, addToIndicators, fetchConfigAndData), each now passing getTranslateFromState(getState). For widgets without a responseAdapter, adaptIndicatorResponse returns the raw res.data, preserving existing behavior. The backend passes the full config through (UserService.getDashboardConfig deep-copies the entire dashboardConfig), so responseAdapter/endpoint reach the frontend. I confirmed state.localize is the correct store slice (used identically in src/js/middlewares/index.js:12).

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


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}`;
Comment on lines +328 to +329

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Endpoint query-string separator change only affects the new widget

The separator logic at src/js/actions/index.js:328-329 appends locationId with & when the endpoint already contains ?. Only the new overdueInbound endpoint (/api/shipments/exceptions/overdue?max=5) has a query string; all existing dashboard endpoints have none, so they keep the ? separator and are unaffected. The extra locationId/listFiltersSelected params sent to the overdue endpoint are harmless since Grails command binding ignores unknown params and the controller scopes results by session.warehouse.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


dispatch({
type: FETCH_GRAPHS,
Expand All @@ -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: {
Expand Down Expand Up @@ -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] || {};
Expand All @@ -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);
}
Expand All @@ -436,15 +462,15 @@ export function fetchIndicators(
locationId,
userId,
) {
return (dispatch) => {
return (dispatch, getState) => {
dispatch({
type: SET_ACTIVE_CONFIG,
payload: {
data: config,
},
});

getData(dispatch, configData, locationId, config, userId);
getData(dispatch, configData, locationId, config, userId, getTranslateFromState(getState));
};
}

Expand All @@ -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);
}
Expand All @@ -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,
Expand All @@ -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));
});
};
}
Expand Down
16 changes: 16 additions & 0 deletions src/js/components/dashboard/TableCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';

import PropTypes from 'prop-types';

import Translate from 'utils/Translate';

/* global _ */
const TableCard = (props) => {
const {
Expand Down Expand Up @@ -60,6 +62,16 @@ const TableCard = (props) => {
</tr>
</thead>
<tbody>
{!data.body.length && data.emptyMessage ? (
<tr className="empty-table-row">
<td colSpan={3}>
<Translate
id={data.emptyMessage.id}
defaultMessage={data.emptyMessage.defaultMessage}
/>
</td>
</tr>
) : null}
Comment on lines +65 to +74

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Empty-message row colSpan is consistent with rendered header columns

The empty-state row uses colSpan={3} (src/js/components/dashboard/TableCard.jsx:67). This is only reached when data.body.length is 0, in which case the optional icon <td/> header cell (rendered via data.body.find((item) => item.icon) at line 55) is absent, leaving exactly 3 header columns (number/name/value). So the span matches. Also, !data.body.length is safe because existing code already dereferences data.body.find/.map unconditionally, meaning body is always defined for TableCard usages.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

{data.body.map((item) => (
<tr
onClick={() => {
Expand Down Expand Up @@ -116,6 +128,10 @@ TableCard.propTypes = {
nameLink: PropTypes.string,
nameDataList: PropTypes.arrayOf(PropTypes.string),
nameLinksList: PropTypes.arrayOf(PropTypes.string),
emptyMessage: PropTypes.shape({
id: PropTypes.string,
defaultMessage: PropTypes.string,
}),
}).isRequired,
columnsSize: PropTypes.shape({
name: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useMemo, useState } from 'react';

import PropTypes from 'prop-types';
import queryString from 'query-string';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { useLocation, withRouter } from 'react-router-dom';

import filterFields from 'components/stock-movement/inbound/FilterFields';
import StockMovementInboundFilters from 'components/stock-movement/inbound/StockMovementInboundFilters';
Expand All @@ -18,7 +19,10 @@ const StockMovementInboundList = (props) => {
setFilterValues,
filterParams,
} = useInboundFilters();
const [overdue, setOverdue] = useState(false);
const { search } = useLocation();
const [overdue, setOverdue] = useState(
queryString.parse(search).overdue === 'true',
);
Comment on lines +22 to +25

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Overdue toggle seeded once from URL query

StockMovementInboundList initializes overdue from ?overdue=true via useState, so it is read only at mount. Subsequent query-param changes without a remount won't re-seed the toggle. This matches the intent (landing on the filtered list from the dashboard card link) and is a typical pattern, but reviewers should be aware the toggle won't react to later URL changes.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

const tableFilterParams = useMemo(() => {
if (Object.keys(filterParams).length === 0 && !overdue) return filterParams;
return { ...filterParams, overdue };
Expand Down
50 changes: 50 additions & 0 deletions src/js/tests/utils/dashboard-response-adapters.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import dashboardResponseAdapters from 'utils/dashboard-response-adapters';

const translate = (id, defaultMessage) => defaultMessage;

describe('overdueInboundShipments adapter', () => {
it('maps rows onto the table card shape, preserving the response order', () => {
const { data, link } = dashboardResponseAdapters.overdueInboundShipments({
data: [
{
id: 'ship1',
shipmentNumber: 'S1',
origin: { id: 'a', name: 'Warehouse A' },
daysLate: 9,
},
{
id: 'ship2',
shipmentNumber: 'S2',
origin: { id: 'b', name: 'Warehouse B' },
daysLate: 2,
},
],
count: 2,
totalCount: 2,
}, translate);

expect(data.number).toBe('Shipment');
expect(data.name).toBe('Origin');
expect(data.value).toBe('Days late');
expect(data.body).toEqual([
{
number: 'S1', numberLink: '/openboxes/stockMovement/show/ship1', name: 'Warehouse A', value: '9',
},
{
number: 'S2', numberLink: '/openboxes/stockMovement/show/ship2', name: 'Warehouse B', value: '2',
},
]);
expect(link).toContain('overdue=true');
});

it('returns an empty body with an empty message when there are no overdue shipments', () => {
const { data } = dashboardResponseAdapters.overdueInboundShipments({
data: [],
count: 0,
totalCount: 0,
}, translate);

expect(data.body).toEqual([]);
expect(data.emptyMessage.id).toBe('react.dashboard.overdueInbound.empty.label');
});
});
34 changes: 34 additions & 0 deletions src/js/utils/dashboard-response-adapters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { STOCK_MOVEMENT_URL } from 'consts/applicationUrls';

const overdueInboundShipments = (responseData, translate) => {
const rows = responseData?.data ?? [];

return {
link: `${STOCK_MOVEMENT_URL.listInbound()}&overdue=true`,
data: {
number: translate('react.dashboard.overdueInbound.column.shipment.label', 'Shipment'),
name: translate('react.dashboard.overdueInbound.column.origin.label', 'Origin'),
value: translate('react.dashboard.overdueInbound.column.daysLate.label', 'Days late'),
emptyMessage: {
id: 'react.dashboard.overdueInbound.empty.label',
defaultMessage: 'No overdue inbound shipments',
},
body: rows.map((row) => ({
number: row.shipmentNumber,
numberLink: row.id ? STOCK_MOVEMENT_URL.show(row.id) : undefined,
name: row.origin?.name,
value: `${row.daysLate}`,
})),
},
};
};
Comment on lines +3 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Column headers captured at dispatch time, relying on default-message fallback

getTranslateFromState(getState) captures a translate function bound to the state at thunk-dispatch time. If react.dashboard.overdueInbound.column.* translations are not yet loaded when the adapter runs, translateWithDefaultMessage falls back to the English default strings ('Shipment', 'Origin', 'Days late') rather than showing translation keys, so the card degrades gracefully. Worth noting the captured translate won't reactively update if translations load afterward, but the fallback makes this a non-issue in practice.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


/**
* Maps a response from an API outside /api/dashboard onto the shape a dashboard card expects.
* Keyed by the responseAdapter declared on the widget in openboxes.dashboardConfig.
*/
const dashboardResponseAdapters = {
overdueInboundShipments,
};

export default dashboardResponseAdapters;
Loading