diff --git a/packages/ui/src/components/Section.tsx b/packages/ui/src/components/Section.tsx
index a5dc482..1ccb5eb 100644
--- a/packages/ui/src/components/Section.tsx
+++ b/packages/ui/src/components/Section.tsx
@@ -1,58 +1,68 @@
-import { ReactNode } from "react";
+import { createContext, ReactNode, useContext, useState } from "react";
import {
Badge,
- Button,
Card,
CardBody,
CardHeader,
CardTitle,
Split,
SplitItem,
+ Switch,
} from "@patternfly/react-core";
-import { PencilAltIcon } from "@patternfly/react-icons";
+
+const SectionContext = createContext<{
+ view: "viewer" | "designer";
+ toggleView: () => void;
+}>({
+ view: "viewer",
+ toggleView: () => {},
+});
+
+export function useSection() {
+ return useContext(SectionContext).view;
+}
export function Section({
title,
count,
id,
children,
- onEdit,
}: {
title: ReactNode;
count?: number;
id: string;
children: ReactNode;
- onEdit?: () => void;
}) {
+ const [view, setView] = useState<"viewer" | "designer">("viewer");
+ const toggleView = () =>
+ setView((v) => (v === "viewer" ? "designer" : "viewer"));
return (
-
-
- {onEdit && (
- }
- onClick={onEdit}
- />
+
+
+
+ ),
+ }}
+ >
+
+
+ {title}
+ {count !== undefined && (
+
+ {count}
+
)}
- >
- ),
- }}
- >
-
-
- {title}
- {count !== undefined && (
-
- {count}
-
- )}
-
-
-
- {children}
-
+
+
+
+ {children}
+
+
);
}
diff --git a/packages/ui/src/documentDesigner/Designer.tsx b/packages/ui/src/documentDesigner/Designer.tsx
index 41a984b..0d8e861 100644
--- a/packages/ui/src/documentDesigner/Designer.tsx
+++ b/packages/ui/src/documentDesigner/Designer.tsx
@@ -7,9 +7,8 @@ import { SecurityScheme } from "./SecurityScheme.tsx";
import { SecurityRequirements } from "./SecurityRequirements.tsx";
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";
+import { Paths } from "./Paths.tsx";
export function Designer() {
const {
@@ -38,7 +37,7 @@ export function Designer() {
return (
}
- paths={editable ? : }
+ paths={}
pathsCount={pathsCount}
contact={}
license={}
diff --git a/packages/ui/src/documentDesigner/Info.tsx b/packages/ui/src/documentDesigner/Info.tsx
index 7ef9de4..26c4c86 100644
--- a/packages/ui/src/documentDesigner/Info.tsx
+++ b/packages/ui/src/documentDesigner/Info.tsx
@@ -10,6 +10,7 @@ import {
useMachineActorRef,
useMachineSelector,
} from "./DocumentDesignerMachineContext.ts";
+import { useSection } from "../components/Section.tsx";
export function Info() {
const { title, version, description, editable } = useMachineSelector(
@@ -20,8 +21,10 @@ export function Info() {
description: context.description,
editable: context.editable,
};
- }
+ },
);
+ const view = useSection();
+ const isEditable = view === "designer" || editable;
const actorRef = useMachineActorRef();
return (
@@ -33,7 +36,7 @@ export function Info() {
actorRef.send({ type: "CHANGE_TITLE", title });
}}
value={title}
- editing={editable}
+ editing={isEditable}
autoFocus={true}
/>
@@ -46,14 +49,14 @@ export function Info() {
actorRef.send({ type: "CHANGE_VERSION", version });
}}
value={version}
- editing={editable}
+ editing={isEditable}
/>
Description
- {description}
+ {description}
diff --git a/packages/ui/src/documentDesigner/Paths.tsx b/packages/ui/src/documentDesigner/Paths.tsx
new file mode 100644
index 0000000..11eb655
--- /dev/null
+++ b/packages/ui/src/documentDesigner/Paths.tsx
@@ -0,0 +1,13 @@
+import { useSection } from "../components/Section.tsx";
+import { useMachineSelector } from "./DocumentDesignerMachineContext.ts";
+import { PathsTree } from "./PathsTree.tsx";
+import { PathsExplorer } from "./PathsExplorer.tsx";
+
+export function Paths() {
+ const { editable } = useMachineSelector(({ context }) => ({
+ editable: context.editable,
+ }));
+ const view = useSection();
+ const isEditable = view === "designer" || editable;
+ return isEditable ? : ;
+}
diff --git a/packages/ui/src/documentDesigner/PathsExplorer.tsx b/packages/ui/src/documentDesigner/PathsExplorer.tsx
index a0deb6d..e94a725 100644
--- a/packages/ui/src/documentDesigner/PathsExplorer.tsx
+++ b/packages/ui/src/documentDesigner/PathsExplorer.tsx
@@ -39,7 +39,7 @@ import { Markdown } from "../components/Markdown.tsx";
import { Path } from "../components/Path.tsx";
import { TagLabel } from "../components/TagLabel.tsx";
import { assign, setup } from "xstate";
-import { useMachine } from "@xstate/react";
+import { useActor } from "@xstate/react";
import { SectionSkeleton } from "../components/SectionSkeleton.tsx";
import { useState } from "react";
import { OperationLabel } from "./OperationLabel.tsx";
@@ -123,7 +123,7 @@ export function PathsExplorer() {
allPaths: context.paths,
};
});
- const [state, send] = useMachine(machine, {
+ const [state, send] = useActor(machine, {
input: {
paths: allPaths,
},
@@ -289,95 +289,99 @@ function OperationRow({
id={`path-${pathId}-operation-${name}-expand`}
isHidden={!isExpanded}
>
-
- {operation.description && (
- {operation.description}
- )}
- {operation.pathParameters.length +
- operation.headerParameters.length +
- operation.queryParameters.length +
- operation.headerParameters.length >
- 0 && (
- <>
- Request
-
- {operation.pathParameters.length > 0 && (
-
-
-
- )}
- {operation.queryParameters.length > 0 && (
-
-
-
- )}
- {operation.headerParameters.length > 0 && (
-
- )}
- {operation.cookieParameters.length > 0 && (
-
-
-
- )}
-
- >
- )}
- Responses
-
- {operation.responses.map((t) => (
-
-
- {t.description && (
-
- {t.description}
-
- )}
-
- }
- id={`response-${t.statusCode}`}
- startExpanded={false}
- >
- TODO
-
- ))}
-
-
+ {isExpanded && (
+
+ {operation.description && (
+
+ {operation.description}
+
+ )}
+ {operation.pathParameters.length +
+ operation.headerParameters.length +
+ operation.queryParameters.length +
+ operation.headerParameters.length >
+ 0 && (
+ <>
+ Request
+
+ {operation.pathParameters.length > 0 && (
+
+
+
+ )}
+ {operation.queryParameters.length > 0 && (
+
+
+
+ )}
+ {operation.headerParameters.length > 0 && (
+
+ )}
+ {operation.cookieParameters.length > 0 && (
+
+
+
+ )}
+
+ >
+ )}
+ Responses
+
+ {operation.responses.map((t) => (
+
+
+ {t.description && (
+
+ {t.description}
+
+ )}
+
+ }
+ id={`response-${t.statusCode}`}
+ startExpanded={false}
+ >
+ TODO
+
+ ))}
+
+
+ )}
);