Skip to Content

ResourceDetail

One record’s page from manh/shell: a title with the status tag, the fields from the columns, buttons for the moves the signed-in role may make, edit, delete and tabs.

Usage

app/orders/[id:int]/page.tsx
import { useApiClient } from "app/api"; import { ResourceDetail } from "manh/shell"; import { OrderFlow, OrderStatus } from "app/shared/order"; import { orderColumns } from "../orders-columns"; export default function OrderPage() { const api = useApiClient(); return ( <ResourceDetail api={api.orders} path="/orders" listTitle="Đơn hàng" columns={orderColumns} title={(o) => `Đơn ${o.code}`} status="status" statusEnum={OrderStatus} flow={OrderFlow} move={(to, o, v) => api.orders.status(o.id, { to, ...v })} moveLabels={{ confirmed: "Xác nhận", shipping: "Giao hàng" }} /> ); }

Signature

manh/shell
function ResourceDetail<T = any>(props: { api: { detail: (id: any) => Promise<any>; update?: (id: any, body: any) => Promise<any>; remove?: (id: any) => Promise<any> }; id?: number | string; columns: any[]; title?: (r: T) => ReactNode; path?: string; listTitle?: string; status?: string; statusEnum?: Enum; // from defineEnum flow?: Flow | ((r: T) => Flow); // from defineFlow move?: (to: string, r: T, values?: any) => Promise<unknown>; ask?: Record<string, any[]>; moveLabels?: Record<string, string>; actions?: (r: T, reload: () => void) => ReactNode[]; tabs?: { key: string; tab: string; render: (r: T, reload: () => void) => ReactNode }[]; extra?: (r: T) => ReactNode; edit?: boolean | ((r: T) => boolean); remove?: boolean; defaultTab?: string; }): JSX.Element;

Parameters

  • api: the resource’s group. Needs detail; with update there is an Edit (Sửa) button, with remove and remove={true} a Delete (Xoá) button.
  • id: the record id; taken from the id in the path by default.
  • columns: the same columns as ResourceList, for the fields and the edit form.
  • title(r): the page title, #<id> by default.
  • path, listTitle: the link back to the list and its text.
  • status, statusEnum: the status column and its enum, shown as a coloured tag next to the title.
  • flow, move: the status flow and the API call that moves a record. With both, the page shows a button for each move the signed-in role may make. flow may be a function of the record, when the route depends on it (requests over an amount go through one more approval level, say).
  • ask: moves that need input first, such as { lost: [{ title: "Lý do", dataIndex: "reason" }] }. The form values reach move as its third argument.
  • moveLabels: the button text per move, such as { done: "Trả máy" }. The target status name by default.
  • actions(r, reload): extra header buttons.
  • tabs: tabs under the fields, such as history or attachments. defaultTab: the tab open at first.
  • extra(r): extra content under the title.
  • edit: false (or a function returning false) hides the edit button, for an order already closed, say.

Returns

A page with PageContainer. Status buttons confirm risky moves first, then reload the page. The edit form is built from columns without the status column: status changes only through move. After a delete it goes back to path. API errors show the server’s message.

Examples

A history tab with ActivityLog from manh/shell, logging calls and notes right on the page:

app/deals/[id:int]/page.tsx
<ResourceDetail api={api.deals} path="/deals" listTitle="Cơ hội" columns={dealColumns} title={(d) => d.title} status="stage" statusEnum={DealStage} flow={DealFlow} move={(to, d, v) => api.deals.stage(d.id, { to, ...v })} tabs={[{ key: "log", tab: "Lịch sử", render: (d, reload) => <DealLog id={d.id} onDone={reload} /> }]} />

The server still refuses illegal moves with Flow.assert; the buttons are only the UI, see defineFlow.

Next steps

Last updated