Repository navigation
feature: Overdue inbound dashboard card - #6
matthewguerra-cog wants to merge 1 commit into
Conversation
…erdue shipments API Co-Authored-By: Matthew Guerra <matthew.guerra@cognition.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| function getTranslateFromState(getState) { | ||
| return translateWithDefaultMessage(getTranslate(getState().localize)); | ||
| } | ||
|
|
||
| function adaptIndicatorResponse(indicatorConfig, responseData, translate) { | ||
| const adapter = dashboardResponseAdapters[indicatorConfig.responseAdapter]; | ||
| return adapter ? adapter(responseData, translate) : responseData; | ||
| } |
There was a problem hiding this comment.
📝 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).
Was this helpful? React with 👍 or 👎 to provide feedback.
| const separator = indicatorConfig.endpoint.includes('?') ? '&' : '?'; | ||
| const url = `${indicatorConfig.endpoint}${separator}${listParams}`; |
There was a problem hiding this comment.
📝 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| 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}`, | ||
| })), | ||
| }, | ||
| }; | ||
| }; |
There was a problem hiding this comment.
📝 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| {!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} |
There was a problem hiding this comment.
📝 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| const { search } = useLocation(); | ||
| const [overdue, setOverdue] = useState( | ||
| queryString.parse(search).overdue === 'true', | ||
| ); |
There was a problem hiding this comment.
📝 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
UI test: Overdue inbound dashboard card — passed (one caveat)Tested end-to-end against a real local build of this branch (MySQL 8 + Grails Card renders correctly (translated headers, most-overdue-first, control excluded)
Empty state, error state and recovery
Navigation, regression, drag/archive, narrow viewport
|
✨ Description of Change
Link to GitHub issue or Jira ticket: n/a — spec source is
docs/demo/ui-spec-prompt.mdonspec-driven-development(the branch has nospecs/ui/*.spec.md).Description:
Adds an "Overdue inbound" table card to the warehouse dashboard, backed by the
GET /api/shipments/exceptions/overdueendpoint that already exists on this branch. No backend query, domain, or migration changes.The dashboard fetch path assumed every widget endpoint lives under
/api/dashboardand already returns the card shape. Instead of adding a second fetch path, widgets can now declare aresponseAdapterthat maps an arbitrary API response onto the card shape:Consequences of that hook:
fetchGraphIndicatorgets atranslateargument (column headers come from the adapter, not from the backend), threaded from redux state viagetTranslate(state.localize)in the thunks that reach it.locationIdparam is appended with&when the endpoint already has a?.fetchConfigAndData's unused trailingfilterSelectedarg is dropped; it was forwarded into agetDataparameter that never existed, and that slot now carriestranslate.Card behavior: columns shipment / origin / days late, rows in the API's default
daysLate descorder, each shipment number linking to its stock movement, card title linking to the inbound list's Overdue view.TableCardrenders a translated empty row when a card suppliesemptyMessage, so the card reads as "no overdue inbound shipments" rather than an empty table. Loading and error states, drag-to-reorder, and the add-widget flow are the existing generic dashboard ones; the endpoint scopes results to the session warehouse and returns a validation error without one, which surfaces as the standard card error state.To make the card's link land on the filtered list,
StockMovementInboundListnow seeds itsoverduetoggle from?overdue=true.📷 Screenshots & Recordings (optional)
UI verification is running; screenshots/recording to follow in a comment.
Devin-Org: engineering
Link to Devin session: https://app.devin.ai/sessions/eef130c0744642c99c7aa9382de2109f
Requested by: @matthewguerra-cog
Devin Review
4ba706c