Dev Helpers
← Back

Find parts stored at multiple locations

Find parts stored at multiple locations. Build the result in an App Router server page and send the rendered entries to the client.

Open this example in the interactive library

Source code

// app/find-parts-stored-at-multiple-locations/page.tsx
export const metadata = { title: "Find parts stored at multiple locations" };
export default function Page() {
  const rows = [
    { sku: "pen", bin: "A", qty: 4 },
    { sku: "pad", bin: "B", qty: 0 },
    { sku: "pen", bin: "B", qty: 3 },
    { sku: "clip", bin: "A", qty: 9 },
  ];
  const result = [...new Set(rows.map((r) => r.sku))].filter(
    (sku) =>
      new Set(rows.filter((r) => r.sku === sku).map((r) => r.bin)).size > 1,
  );
  const entries = Object.entries(
    typeof result === "object" && result !== null ? result : { value: result },
  );
  return (
    <section>
      <h2>{"Find parts stored at multiple locations"}</h2>
      {entries.length ? (
        <dl>
          {entries.map(([key, value]) => (
            <div key={key}>
              <dt>{key}</dt>
              <dd>
                {typeof value === "string" ? value : JSON.stringify(value)}
              </dd>
            </div>
          ))}
        </dl>
      ) : (
        <p>No matching entries.</p>
      )}
    </section>
  );
}