+ )
}
Modal.Footer = ({ children }) => {
diff --git a/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceAttributes.tsx b/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceAttributes.tsx
index 371ea9b7e..6c34321f8 100644
--- a/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceAttributes.tsx
+++ b/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceAttributes.tsx
@@ -1,75 +1,81 @@
import type { Resource } from "@commercelayer/sdk"
+import cn from "classnames"
import capitalize from "lodash-es/capitalize"
import lowerCase from "lodash-es/lowerCase"
-import { type FC, useState } from "react"
+import { type FC, type ReactNode, useState } from "react"
import type { JsonObject } from "type-fest"
import { t } from "#providers/i18n"
import { Button } from "#ui/atoms/Button"
-import { Card } from "#ui/atoms/Card"
import { CodeBlock } from "#ui/atoms/CodeBlock"
import { Icon } from "#ui/atoms/Icon"
import { withSkeletonTemplate } from "#ui/atoms/SkeletonTemplate"
-import { Spacer } from "#ui/atoms/Spacer"
import { Text } from "#ui/atoms/Text"
-import { ListItem } from "#ui/composite/ListItem"
import { splitResourceFields } from "./resourceFields"
/**
- * Lists a resource's plain attributes. Relationships are filtered out: they
- * are rendered by whoever owns that concern, so they don't leak into this list
- * as raw JSON.
+ * Lists a resource's plain attributes as a single flat list, led by its id and
+ * type. Relationships are filtered out: they are rendered by whoever owns that
+ * concern, so they don't leak into this list as raw JSON.
*/
export const ResourceAttributes = withSkeletonTemplate<{ resource: Resource }>(
({ resource }) => {
const { attributes } = splitResourceFields(resource)
return (
- <>
-
-
-
- ID
-
-
-
- Type
-
-
-
-
-
-
- {attributes.map((attribute, idx) => (
-
- ))}
-
- >
+
)}
>
)
diff --git a/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsContent.test.tsx b/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsContent.test.tsx
index 22a72337c..fcbb4888c 100644
--- a/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsContent.test.tsx
+++ b/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsContent.test.tsx
@@ -149,3 +149,76 @@ describe("ResourceDetailsContent", () => {
).toBeNull()
})
})
+
+describe("ResourceDetailsContent edgeToEdge", () => {
+ const renderContent = async (edgeToEdge?: boolean): Promise =>
+ await act(async () =>
+ render(
+
+
+
+
+ ,
+ ),
+ )
+
+ it("keeps the tabs and their content flush with the container by default", async () => {
+ const { getByRole } = await renderContent()
+
+ expect(getByRole("tablist").parentElement?.parentElement).not.toHaveClass(
+ "[&_[role=tablist]]:px-6",
+ )
+ expect(getByRole("tabpanel").firstElementChild).not.toHaveClass("px-6")
+ })
+
+ it("gives the tabs and their content a gutter, the row spanning the edges", async () => {
+ const { getByRole } = await renderContent(true)
+
+ expect(getByRole("tablist").parentElement?.parentElement).toHaveClass(
+ "[&_[role=tablist]]:px-6",
+ // the room above the tabs, the container having none of its own
+ "[&_[role=tablist]]:pt-4",
+ // and the content 12px under the row, as designed
+ "[&_[role=tabpanel]]:pt-3",
+ )
+ expect(getByRole("tabpanel").firstElementChild).toHaveClass("px-6")
+ })
+})
+
+describe("ResourceDetailsContent fillHeight", () => {
+ const renderContent = async (fillHeight?: boolean): Promise =>
+ await act(async () =>
+ render(
+
+
+
+
+ ,
+ ),
+ )
+
+ it("lets the content flow with the page by default", async () => {
+ const { getByRole } = await renderContent()
+
+ expect(getByRole("tablist").parentElement?.parentElement).not.toHaveClass(
+ "h-full",
+ )
+ })
+
+ it("fills the container and scrolls the open panel only, under the tab row", async () => {
+ const { getByRole } = await renderContent(true)
+
+ expect(getByRole("tablist").parentElement?.parentElement).toHaveClass(
+ "h-full",
+ "flex",
+ "flex-col",
+ "[&>[role=tabpanel]]:overflow-y-auto",
+ )
+ })
+})
diff --git a/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsContent.tsx b/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsContent.tsx
index 60350ee6b..cb289f3f8 100644
--- a/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsContent.tsx
+++ b/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsContent.tsx
@@ -1,10 +1,15 @@
import type { Resource, ResourceTypeLock } from "@commercelayer/sdk"
+import cn from "classnames"
import { type FC, type ReactNode, useId } from "react"
import { t } from "#providers/i18n"
import { Spacer } from "#ui/atoms/Spacer"
-import { Tab, Tabs } from "#ui/atoms/Tabs"
+import { Tab, Tabs, type TabsProps } from "#ui/atoms/Tabs"
import { ResourceAttributes } from "./ResourceAttributes"
import { ResourceEvents } from "./ResourceEvents"
+import {
+ ResourceRelationships,
+ type ResourceRelationshipsConfig,
+} from "./ResourceRelationships"
export interface ResourceDetailsTab {
/** Tab label. */
@@ -24,15 +29,39 @@ export interface ResourceDetailsContentProps {
resource: Resource
/** Renders skeletons while the caller is still loading the resource. */
isLoading?: boolean
- /** Extra tabs, rendered between Attributes and Events. */
+ /**
+ * Shows a Relationships tab right after Attributes. Has-one relationships
+ * the caller sideloaded are read from `resource`; any other is fetched only
+ * when its row is expanded. Leave it unset to hide the tab.
+ */
+ relationships?: ResourceRelationshipsConfig
+ /** Extra tabs, rendered between Attributes (or Relationships) and Events. */
tabs?: ResourceDetailsTab[]
/**
- * Fixed height for each tab panel, e.g. `"70vh"`. Set it when the surrounding
- * container must not resize as tabs change (a modal, typically). Leave it
- * unset on a page, so content flows naturally instead of gaining a nested
- * scrollbar.
+ * Fixed height for each tab panel, e.g. `"70vh"`, which then scrolls on its
+ * own. Set it when the surrounding container must not resize as tabs change
+ * and cannot scroll as a whole. Leave it unset on a page, so content flows
+ * naturally instead of gaining a nested scrollbar.
*/
panelHeight?: string
+ /**
+ * Size of the tab row. `small` suits a side column, next to a list.
+ * @default regular
+ */
+ tabsSize?: TabsProps["size"]
+ /**
+ * Lets the tab row run from edge to edge of the container, with the tabs and
+ * their content kept 24px from the sides, the tabs 16px from the top and the
+ * content 12px under the row. For a container with no padding of its own,
+ * such as a side column next to a list.
+ */
+ edgeToEdge?: boolean
+ /**
+ * Fills the height of the container, which must have one: the tab row stays
+ * in place and only the open panel scrolls, so its scrollbar starts under the
+ * row. For a modal or a side column that should not scroll as a whole.
+ */
+ fillHeight?: boolean
/**
* Id for the tab list, used to build the ids that link each tab to its panel.
* Defaults to a generated one, so several instances can coexist on the same
@@ -42,8 +71,8 @@ export interface ResourceDetailsContentProps {
}
/**
- * Tabbed view of a single resource: its attributes, any tabs the caller adds,
- * and its event stream.
+ * Tabbed view of a single resource: its attributes, its relationships when
+ * asked for, any tabs the caller adds, and its event stream.
*
* Usable on its own inside a page, or wrapped in a modal via
* `useResourceDetailsModal`.
@@ -51,29 +80,62 @@ export interface ResourceDetailsContentProps {
export const ResourceDetailsContent: FC = ({
resource,
isLoading = false,
+ relationships,
tabs = [],
panelHeight,
+ tabsSize,
+ edgeToEdge = false,
+ fillHeight = false,
id,
}) => {
const generatedId = useId()
return (
-
+ [role=tabpanel]]:flex-1 [&>[role=tabpanel]]:min-h-0 [&>[role=tabpanel]]:overflow-y-auto [&>[role=tabpanel]]:pb-6":
+ fillHeight,
+ })}
+ >
{[
-
+ ,
+ ...(relationships != null
+ ? [
+
+
+
+
+ ,
+ ]
+ : []),
+
...tabs.map((tab) => (
- {tab.content(resource)}
+
+ {tab.content(resource)}
+
)),
-
+ = ({
/**
* Wraps a tab's content, optionally pinning it to a fixed height so switching
- * tabs can't resize the container. The gradient strips hint that it scrolls.
+ * tabs can't resize the container.
*
* Styled inline rather than with utility classes: consumers of this library
* have no Tailwind build of their own, and keeping the height configurable at
* runtime rules out a static class anyway.
*/
-const TabPanel: FC<{ height?: string; children: ReactNode }> = ({
- height,
- children,
-}) => {
+const TabPanel: FC<{
+ height?: string
+ hasGutter: boolean
+ children: ReactNode
+}> = ({ height, hasGutter, children }) => {
if (height == null) {
- return {children}
+ return (
+
+ {children}
+
+ )
}
return (
-
-
-
{children}
+
+
+ {children}
-
-
)
}
+
+/**
+ * Room between the tab row and the content. An edge-to-edge row sets it on the
+ * whole panel instead, to the design's 12px.
+ */
+function getPanelTop(hasGutter: boolean): "2" | undefined {
+ if (hasGutter) {
+ return undefined
+ }
+
+ return "2"
+}
diff --git a/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsTimeline.tsx b/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsTimeline.tsx
index 97bd05a7b..edd9c29f4 100644
--- a/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsTimeline.tsx
+++ b/packages/app-elements/src/ui/resources/ResourceDetailsModal/ResourceDetailsTimeline.tsx
@@ -54,8 +54,13 @@ export function ResourceDetailsTimeline({
<>
{Object.entries(groupedByDay).map(([day, dayItems], idx) => (
-
-
+
+
{formatDate({ isoDate: day, format: "date", timezone })}
@@ -68,6 +73,19 @@ export function ResourceDetailsTimeline({
)
}
+/**
+ * Room above a day's heading. The first one sits 12px down, level with the text
+ * of the first row of a list such as the attributes; the others leave a wide gap
+ * from the day before.
+ */
+function getDayTop(idx: number): "3" | "12" {
+ if (idx === 0) {
+ return "3"
+ }
+
+ return "12"
+}
+
export interface ResourceDetailsTimelineItemProps {
/** Shown in bold. The time of `isoDate` sits on the right, next to the caret. */
title: ReactNode
@@ -97,7 +115,9 @@ export function ResourceDetailsTimelineItem({
gap="none"
className={cn(
"w-full rounded! hover:border-black hover:shadow-cardhover",
- { "border-black! shadow-cardhover!": isOpen },
+ // a 2px black frame once open: the border plus a ring inside it, so the
+ // content does not move
+ { "border-black! inset-ring-1 inset-ring-black": isOpen },
)}
>