Skip to content

WIP: Inventory -> DeliveryOrder Navigation#16320

Open
gigincg wants to merge 1 commit intodevelopfrom
CARE-78-when-a-user-click-on-an-inventory-item-it-should-display-all-supply-deliveries
Open

WIP: Inventory -> DeliveryOrder Navigation#16320
gigincg wants to merge 1 commit intodevelopfrom
CARE-78-when-a-user-click-on-an-inventory-item-it-should-display-all-supply-deliveries

Conversation

@gigincg
Copy link
Copy Markdown
Member

@gigincg gigincg commented Apr 29, 2026

Proposed Changes

Fixes #issue_number

  • Change 1
  • Change 2
  • Additional context if needed

Tagging: @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

Release Notes

  • New Features

    • Product deliveries can now be accessed directly from the inventory list by clicking on product names.
    • Added confirmation dialog for the "mark as entered in error" workflow.
  • Improvements

    • Enhanced product navigation with quick access to both deliveries and settings.
    • Improved empty state messaging for delivery views.

@gigincg gigincg requested review from a team and Copilot April 29, 2026 03:04
@gigincg gigincg requested a review from a team as a code owner April 29, 2026 03:04
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@github-actions
Copy link
Copy Markdown

⚠️ Merge Checklist Incomplete

Thank you for your contribution! To help us review your PR efficiently, please complete the merge checklist in your PR description.

Your PR will be reviewed once you have marked the appropriate checklist items.

To update the checklist:

  • Change - [ ] to - [x] for completed items
  • Only check items that are relevant to your PR
  • Leave items unchecked if they don't apply

The checklist helps ensure code quality, testing coverage, and documentation are properly addressed.

@github-actions github-actions Bot added the Type Changes Contains changes in typescript types label Apr 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Walkthrough

Adds supply delivery viewing functionality to the inventory system through a new drawer component, integrates delivery links into the inventory list, updates the supply delivery table to support product linking via order type identification, and extends the supply delivery type definition to include order information.

Changes

Cohort / File(s) Summary
Localization
public/locale/en.json
Adds i18n strings for product-scoped delivery display (deliveries_for) and "entered in error" confirmation dialog with patient name and token number interpolation. Removes duplicate key definition.
Inventory & Deliveries Components
src/pages/Facility/services/inventory/InventoryList.tsx, src/pages/Facility/services/inventory/SupplyDeliveriesDrawer.tsx
Converts product cell in inventory list to a link-styled button that opens a drawer. New SupplyDeliveriesDrawer component manages state, conditionally fetches supply deliveries by facility and query parameters, and displays results in a table or empty state with localized messaging.
Supply Delivery Table
src/pages/Facility/services/inventory/SupplyDeliveryTable.tsx
Adds identifyOrderType helper to determine order origin. Implements product name linking with linkToProduct support, creating delivery-scoped navigation links keyed by destination, order type, and order ID. Updates product name rendering from <div> to styled <span>.
Type Definitions
src/types/inventory/supplyDelivery/supplyDelivery.ts
Extends SupplyDeliveryRead type with required order property typed as DeliveryOrderRetrieve, enabling access to order origin and other delivery-related metadata.
Component Refactoring
src/pages/Facility/services/inventory/externalSupply/deliveryOrder/DeliveryOrderShow.tsx
Simplifies conditional SupplyDeliveryTable rendering by removing wrapper fragment and returning component directly.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description uses only placeholder text ('Change 1', 'Change 2', 'Fixes #issue_number') without any actual details about the implemented changes despite substantial modifications across five files. Replace placeholder text with concrete descriptions of changes: the new SupplyDeliveriesDrawer component, i18n additions, InventoryList modifications, and type updates. Include the actual issue number and specific details about the delivery order navigation implementation.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'WIP: Inventory -> DeliveryOrder Navigation' accurately describes the main change: enabling navigation from inventory items to delivery orders, matching the branch name and the primary code modifications.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch CARE-78-when-a-user-click-on-an-inventory-item-it-should-display-all-supply-deliveries

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: ba93eda
Status: ✅  Deploy successful!
Preview URL: https://9f3d12c8.care-preview-a7w.pages.dev
Branch Preview URL: https://care-78-when-a-user-click-on.care-preview-a7w.pages.dev

View logs

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve navigation from the Inventory summary view into the relevant Delivery Order context by introducing a deliveries drawer and updating how supply-delivery items link out to related pages.

Changes:

  • Extend SupplyDeliveryRead to include the associated order object.
  • Add a reusable SupplyDeliveriesDrawer and wire it into InventoryList (open drawer by clicking a product name).
  • Update SupplyDeliveryTable to link the product name to a delivery-order route and move the product-settings link to an external-link icon; add i18n for the drawer title.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/types/inventory/supplyDelivery/supplyDelivery.ts Adds order: DeliveryOrderRetrieve to supply delivery read model.
src/pages/Facility/services/inventory/externalSupply/deliveryOrder/DeliveryOrderShow.tsx Simplifies rendering by removing an unnecessary fragment wrapper.
src/pages/Facility/services/inventory/SupplyDeliveryTable.tsx Adds delivery-order navigation link(s) from delivery rows and helper to infer order type.
src/pages/Facility/services/inventory/SupplyDeliveriesDrawer.tsx New drawer component that fetches and displays supply deliveries in a table.
src/pages/Facility/services/inventory/InventoryList.tsx Adds “deliveries for product” drawer entry point from inventory list rows.
public/locale/en.json Adds deliveries_for i18n string and reorders an existing confirmation string.

Comment on lines +247 to +265
<SupplyDeliveriesDrawer
open={!!deliveriesDrawerProduct}
onOpenChange={(open) => {
if (!open) setDeliveriesDrawerProduct(undefined);
}}
title={
deliveriesDrawerProduct
? t("deliveries_for", { product: deliveriesDrawerProduct.name })
: undefined
}
facilityId={facilityId}
queryParams={{
destination: locationId,
supplied_inventory_item_product_knowledge:
deliveriesDrawerProduct?.id,
ordering: "-created_date",
}}
linkToProduct
/>
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

This adds a new user-facing navigation flow (Inventory summary -> open deliveries drawer -> navigate into a delivery order). There are existing Playwright specs covering inventory receive/dispatch flows, but none appear to cover this new drawer + navigation path. Please add/update a Playwright spec to exercise opening the drawer from the inventory list and following the delivery-order link (at least one internal and one external case if applicable).

Copilot generated this review using guidance from repository custom instructions.
</Link>
<div className="flex items-center gap-2">
<Link
href={`/facility/${facilityId}/locations/${delivery.order.destination.id}/inventory/${identifyOrderType(delivery)}/deliveries/incoming/${delivery.order.id}`}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The generated delivery-order link path is incorrect for internal deliveries. Location routes expect /inventory/internal/:type/deliveries/:id (e.g. .../internal/receive/deliveries/{id}), but this builds /inventory/internal/deliveries/incoming/{id}, which won’t match any route and will 404 for internal orders. Build the href using the existing inventory route helper (or include the required :type segment based on receive/dispatch) so internal navigation resolves correctly.

Suggested change
href={`/facility/${facilityId}/locations/${delivery.order.destination.id}/inventory/${identifyOrderType(delivery)}/deliveries/incoming/${delivery.order.id}`}
href={
internal
? `/facility/${facilityId}/locations/${delivery.order.destination.id}/inventory/internal/receive/deliveries/${delivery.order.id}`
: `/facility/${facilityId}/locations/${delivery.order.destination.id}/inventory/${identifyOrderType(delivery)}/deliveries/incoming/${delivery.order.id}`
}

Copilot uses AI. Check for mistakes.
Comment on lines +268 to +274
<Link
href={`/facility/${facilityId}/locations/${delivery.order.destination.id}/inventory/${identifyOrderType(delivery)}/deliveries/incoming/${delivery.order.id}`}
className="font-medium text-primary-600 hover:underline"
basePath="/"
>
{productName}
</Link>
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

This <Link> is inside a <TableCell> that has an onClick handler; unlike the settings-link, it does not stop event propagation. Clicking the product name can therefore also trigger onDeliveryClick (and potentially navigate twice / to the wrong place). Add e.stopPropagation() on the product-name link click as well when onDeliveryClick is in use.

Copilot uses AI. Check for mistakes.
Comment on lines 265 to +276
if (linkToProduct && facilityId && productId) {
return (
<Link
href={`/facility/${facilityId}/settings/product/${productId}`}
className="font-medium text-primary-600 hover:underline"
onClick={(e) => e.stopPropagation()}
basePath="/"
>
{productName}
</Link>
<div className="flex items-center gap-2">
<Link
href={`/facility/${facilityId}/locations/${delivery.order.destination.id}/inventory/${identifyOrderType(delivery)}/deliveries/incoming/${delivery.order.id}`}
className="font-medium text-primary-600 hover:underline"
basePath="/"
>
{productName}
</Link>
<Link
href={`/facility/${facilityId}/settings/product/${productId}`}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

linkToProduct is now effectively controlling whether the product-name navigates to the delivery order (with a separate icon linking to the product settings). This makes the prop name misleading for callers and future maintenance. Consider renaming/splitting this prop so its name reflects the current behavior (e.g. one prop for “link product name to order”, another for “show product settings link”).

Copilot uses AI. Check for mistakes.
Comment on lines 289 to +292
return (
<div className="font-medium text-wrap wrap-break-word">
<span className="font-medium text-primary-600 hover:underline">
{productName}
</div>
</span>
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

When linkToProduct is false, the product name is rendered as a styled <span> that looks like a link (primary color + hover underline) but is not interactive unless the cell itself is clickable. This is misleading for users and a11y tools. Consider rendering link-like styling only when there is an actual navigation target/click handler, or use a real <Link>/<button> with proper semantics.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@public/locale/en.json`:
- Line 1736: The new i18n key "deliveries_for" was inserted in-place instead of
being appended; remove the in-place entry ("deliveries_for": "Deliveries for
{{product}}") and append that key/value pair to the very end of
public/locale/en.json (respecting JSON syntax — add a comma to the previous last
entry if needed and ensure no trailing comma at EOF). Locate the key by
searching for "deliveries_for" and move it to the file's EOF so the repository's
append-only i18n policy is preserved.

In `@src/pages/Facility/services/inventory/SupplyDeliveriesDrawer.tsx`:
- Around line 47-53: The current useQuery call using
query.paginated(supplyDeliveryApi.listSupplyDelivery) only fetches one page and
the UI renders supplyDeliveries.results, truncating history; change to a
paginated/infinite pattern: replace useQuery with useInfiniteQuery (or implement
a helper that fetches all pages) using query.paginated as the queryFn, provide a
getNextPageParam that returns the next page cursor/page number, and in the
render logic replace supplyDeliveries.results with the aggregated list (e.g.,
supplyDeliveries.pages.flatMap(p => p.results) or the helper's combined array)
and add either a "load more" control or an intersection-observer-triggered
fetchNextPage call to load subsequent pages (update any calls to
isLoading/isFetching accordingly and reference useInfiniteQuery,
query.paginated, supplyDeliveryApi.listSupplyDelivery, getNextPageParam,
fetchNextPage, and pages.flatMap to find where to modify).
- Around line 64-80: The current render treats fetch errors as an empty list
because it only checks isLoading and supplyDeliveries.results; update the
rendering logic in SupplyDeliveriesDrawer to explicitly handle an error state:
after isLoading, check for the fetch error (e.g., supplyDeliveriesError or error
returned by the hook that provides supplyDeliveries) and render an ErrorState
(or an EmptyState variant showing the error) with a retry button wired to the
hook's refetch/mutate function; only then check supplyDeliveries?.results.length
to render SupplyDeliveryTable, otherwise render the existing EmptyState;
reference the existing symbols isLoading, supplyDeliveries (results),
SupplyDeliveryTable, EmptyState/TableSkeleton/Truck and the hook's error/refetch
identifiers to locate and implement the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f1be217f-9f1f-48f0-843e-a0fbd11b2b20

📥 Commits

Reviewing files that changed from the base of the PR and between c9ff904 and ba93eda.

📒 Files selected for processing (6)
  • public/locale/en.json
  • src/pages/Facility/services/inventory/InventoryList.tsx
  • src/pages/Facility/services/inventory/SupplyDeliveriesDrawer.tsx
  • src/pages/Facility/services/inventory/SupplyDeliveryTable.tsx
  • src/pages/Facility/services/inventory/externalSupply/deliveryOrder/DeliveryOrderShow.tsx
  • src/types/inventory/supplyDelivery/supplyDelivery.ts

Comment thread public/locale/en.json
"deliveries": "Deliveries",
"deliveries_approved": "Deliveries approved successfully",
"deliveries_created": "Deliveries Created",
"deliveries_for": "Deliveries for {{product}}",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Move new i18n key to the end of en.json (append-only policy).

Line 1736 adds a new key in-place. In this repo, new keys in public/locale/en.json should be appended at EOF.

Proposed fix
-  "deliveries_for": "Deliveries for {{product}}",
   "zoom_in": "Zoom In",
   "zoom_out": "Zoom Out",
+  "deliveries_for": "Deliveries for {{product}}",
   "℞": "℞"

As per coding guidelines public/locale/en.json: Append missing i18n keys directly to the end of the public/locale/en.json file without reading i18n files.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@public/locale/en.json` at line 1736, The new i18n key "deliveries_for" was
inserted in-place instead of being appended; remove the in-place entry
("deliveries_for": "Deliveries for {{product}}") and append that key/value pair
to the very end of public/locale/en.json (respecting JSON syntax — add a comma
to the previous last entry if needed and ensure no trailing comma at EOF).
Locate the key by searching for "deliveries_for" and move it to the file's EOF
so the repository's append-only i18n policy is preserved.

Comment on lines +47 to +53
const { data: supplyDeliveries, isLoading } = useQuery({
queryKey: ["supplyDeliveriesDrawer", facilityId, queryParams],
queryFn: query.paginated(supplyDeliveryApi.listSupplyDelivery, {
queryParams: { facility: facilityId, ...queryParams },
}),
enabled: open && enabled,
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Only the first paginated page is rendered; “all deliveries” is not guaranteed.

At Line 49, the API call is paginated, but at Lines 68-74 only the current results page is shown and there is no page state/control or infinite loading. This can truncate delivery history when records exceed page size.

💡 Suggested fix direction
+ const [page, setPage] = useState(1);

  const { data: supplyDeliveries, isLoading } = useQuery({
    queryKey: ["supplyDeliveriesDrawer", facilityId, queryParams],
    queryFn: query.paginated(supplyDeliveryApi.listSupplyDelivery, {
-     queryParams: { facility: facilityId, ...queryParams },
+     queryParams: { facility: facilityId, page, ...queryParams },
    }),
    enabled: open && enabled,
  });

+ // Render pagination controls based on supplyDeliveries.count / next / previous
+ // and update `page` via setPage(...)

As per coding guidelines: “Handle pagination and infinite scroll patterns appropriately in page components.”

Also applies to: 68-74

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Facility/services/inventory/SupplyDeliveriesDrawer.tsx` around
lines 47 - 53, The current useQuery call using
query.paginated(supplyDeliveryApi.listSupplyDelivery) only fetches one page and
the UI renders supplyDeliveries.results, truncating history; change to a
paginated/infinite pattern: replace useQuery with useInfiniteQuery (or implement
a helper that fetches all pages) using query.paginated as the queryFn, provide a
getNextPageParam that returns the next page cursor/page number, and in the
render logic replace supplyDeliveries.results with the aggregated list (e.g.,
supplyDeliveries.pages.flatMap(p => p.results) or the helper's combined array)
and add either a "load more" control or an intersection-observer-triggered
fetchNextPage call to load subsequent pages (update any calls to
isLoading/isFetching accordingly and reference useInfiniteQuery,
query.paginated, supplyDeliveryApi.listSupplyDelivery, getNextPageParam,
fetchNextPage, and pages.flatMap to find where to modify).

Comment on lines +64 to +80
{isLoading ? (
<TableSkeleton count={3} />
) : supplyDeliveries?.results &&
supplyDeliveries.results.length > 0 ? (
<SupplyDeliveryTable
deliveries={supplyDeliveries.results}
internal={internal}
isRequester={isRequester}
facilityId={facilityId}
linkToProduct={linkToProduct}
/>
) : (
<EmptyState
icon={<Truck className="size-5 text-primary-600" />}
title={t("no_deliveries_found")}
description={t("no_deliveries_found_description")}
/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

API errors are currently shown as “no deliveries found.”

At Line 64 onward, the branch handles loading and empty data, but errors fall through to the empty-state message. That masks backend/network failures and misleads users.

💡 Suggested fix direction
- const { data: supplyDeliveries, isLoading } = useQuery({
+ const { data: supplyDeliveries, isLoading, isError } = useQuery({
    ...
  });

  {isLoading ? (
    <TableSkeleton count={3} />
+ ) : isError ? (
+   <EmptyState
+     icon={<Truck className="size-5 text-primary-600" />}
+     title={t("deliveries_load_failed")}
+     description={t("deliveries_load_failed_description")}
+   />
  ) : supplyDeliveries?.results && supplyDeliveries.results.length > 0 ? (
    <SupplyDeliveryTable ... />
  ) : (
    <EmptyState ... />
  )}

As per coding guidelines: “Implement proper loading, error, and success states for data fetching.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Facility/services/inventory/SupplyDeliveriesDrawer.tsx` around
lines 64 - 80, The current render treats fetch errors as an empty list because
it only checks isLoading and supplyDeliveries.results; update the rendering
logic in SupplyDeliveriesDrawer to explicitly handle an error state: after
isLoading, check for the fetch error (e.g., supplyDeliveriesError or error
returned by the hook that provides supplyDeliveries) and render an ErrorState
(or an EmptyState variant showing the error) with a retry button wired to the
hook's refetch/mutate function; only then check supplyDeliveries?.results.length
to render SupplyDeliveryTable, otherwise render the existing EmptyState;
reference the existing symbols isLoading, supplyDeliveries (results),
SupplyDeliveryTable, EmptyState/TableSkeleton/Truck and the hook's error/refetch
identifiers to locate and implement the change.

@github-actions
Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 21
✅ Passed 15
❌ Failed 6
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #8607

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type Changes Contains changes in typescript types Work in Progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants