Skip to content

Commit

Permalink
Button to go to the designer view quickly
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardo-forina committed Nov 27, 2024
1 parent ff8486b commit 55ee05d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
41 changes: 31 additions & 10 deletions packages/ui/src/components/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
import { ReactNode } from "react";
import {
Badge,
Button,
Card,
CardBody,
CardHeader,
CardTitle,
Split,
SplitItem,
} from "@patternfly/react-core";
import { PencilAltIcon } from "@patternfly/react-icons";

export function Section({
title,
count,
id,
children,
onEdit,
}: {
title: ReactNode;
count?: number;
id: string;
children: ReactNode;
onEdit?: () => void;
}) {
return (
<Card isPlain={true} isLarge={true} id={id}>
<CardTitle>
<Split hasGutter={true}>
<SplitItem>{title}</SplitItem>
{count !== undefined && (
<SplitItem>
<Badge>{count}</Badge>
</SplitItem>
)}
</Split>
</CardTitle>
<CardHeader
actions={{
actions: (
<>
{onEdit && (
<Button
variant={"control"}
icon={<PencilAltIcon />}
onClick={onEdit}
/>
)}
</>
),
}}
>
<CardTitle>
<Split hasGutter={true}>
<SplitItem>{title}</SplitItem>
{count !== undefined && (
<SplitItem>
<Badge>{count}</Badge>
</SplitItem>
)}
</Split>
</CardTitle>
</CardHeader>
<CardBody>{children}</CardBody>
</Card>
);
Expand Down
8 changes: 8 additions & 0 deletions packages/ui/src/documentDesigner/Designer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useMachineSelector } from "./DocumentDesignerMachineContext.ts";
import { DesignerLayout } from "./DesignerLayout.tsx";
import { PathsExplorer } from "./PathsExplorer.tsx";
import { PathsTree } from "./PathsTree.tsx";
import { OpenApiEditorMachineContext } from "../OpenApiEditor.tsx";

export function Designer() {
const {
Expand All @@ -28,6 +29,12 @@ export function Designer() {
editable: context.editable,
};
});
const actorRef = OpenApiEditorMachineContext.useActorRef();
const onEdit = !editable
? () => {
actorRef.send({ type: "SELECT_DOCUMENT_ROOT_DESIGNER" });
}
: undefined;
return (
<DesignerLayout
info={<Info />}
Expand All @@ -43,6 +50,7 @@ export function Designer() {
serversCount={serversCount}
securitySchemeCount={securitySchemeCount}
securityRequirementsCount={securityRequirementsCount}
onEdit={onEdit}
/>
);
}
25 changes: 20 additions & 5 deletions packages/ui/src/documentDesigner/DesignerLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function DesignerLayout({
serversCount,
securitySchemeCount,
securityRequirementsCount,
onEdit,
}: {
info?: ReactNode;
paths?: ReactNode;
Expand All @@ -33,6 +34,7 @@ export function DesignerLayout({
serversCount?: number;
securitySchemeCount?: number;
securityRequirementsCount?: number;
onEdit?: () => void;
}) {
return (
<Flex>
Expand All @@ -49,38 +51,50 @@ export function DesignerLayout({
</JumpLinksItem>
</Toc>
<TocContainer>
<Section title={"Info"} id={"info"}>
<Section title={"Info"} id={"info"} onEdit={onEdit}>
{info}
</Section>
<Divider inset={{ default: "insetNone" }} />
<Section title={"Contact"} id={"contact"}>
<Section title={"Contact"} id={"contact"} onEdit={onEdit}>
{contact}
</Section>
<Divider inset={{ default: "insetNone" }} />
<Section title={"License"} id={"license"}>
<Section title={"License"} id={"license"} onEdit={onEdit}>
{license}
</Section>
<Divider inset={{ default: "insetNone" }} />
<Section title={"Paths"} id={"paths"} count={pathsCount}>
<Section
title={"Paths"}
id={"paths"}
count={pathsCount}
onEdit={onEdit}
>
{paths}
</Section>
<Divider inset={{ default: "insetNone" }} />
<Section
title={"Tag definitions"}
count={tagDefinitionsCount}
id={"tag-definitions"}
onEdit={onEdit}
>
{tagDefinitions}
</Section>
<Divider inset={{ default: "insetNone" }} />
<Section title={"Servers"} count={serversCount} id={"servers"}>
<Section
title={"Servers"}
count={serversCount}
id={"servers"}
onEdit={onEdit}
>
{servers}
</Section>
<Divider inset={{ default: "insetNone" }} />
<Section
title={"Security scheme"}
count={securitySchemeCount}
id={"security-scheme"}
onEdit={onEdit}
>
{securityScheme}
</Section>
Expand All @@ -89,6 +103,7 @@ export function DesignerLayout({
title={"Security requirements"}
count={securityRequirementsCount}
id={"security-requirements"}
onEdit={onEdit}
>
{securityRequirements}
</Section>
Expand Down

0 comments on commit 55ee05d

Please sign in to comment.