Skip to content

Commit

Permalink
Add icons to visualize/edit a specific path in the paths explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardo-forina committed Nov 27, 2024
1 parent 02d2b52 commit ff8486b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/ui/src/components/EditorToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export function EditorToolbar({
({ context }) => {
const groupedCount = groupBy(
context.validationProblems,
(v) => v.severity
(v) => v.severity,
);
return {
low: groupedCount["info"]?.length ?? 0,
medium: groupedCount["warning"]?.length ?? 0,
high: groupedCount["danger"]?.length ?? 0,
};
}
},
);
const actorRef = OpenApiEditorMachineContext.useActorRef();
return (
Expand Down
42 changes: 32 additions & 10 deletions packages/ui/src/documentDesigner/PathsExplorer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Accordion,
Button,
Card,
CardBody,
CardHeader,
Expand Down Expand Up @@ -44,6 +45,7 @@ import { useState } from "react";
import { OperationLabel } from "./OperationLabel.tsx";
import { StatusCodeLabel } from "../components/StatusCodeLabel.tsx";
import { AccordionSection } from "../components/AccordionSection.tsx";
import { EyeIcon, PencilAltIcon } from "@patternfly/react-icons";

function normalize(str: string) {
return str.toLowerCase().trim().normalize("NFC");
Expand Down Expand Up @@ -87,7 +89,7 @@ const machine = setup({
paths: ({ context: { initialPaths, filter } }) => {
const normalizedFilter = normalize(filter);
return initialPaths.filter((path) =>
isMatch(normalizedFilter, JSON.stringify(path))
isMatch(normalizedFilter, JSON.stringify(path)),
);
},
}),
Expand Down Expand Up @@ -172,16 +174,36 @@ function PathDetails({
}) {
const actorRef = OpenApiEditorMachineContext.useActorRef();
return (
<Card isCompact={true} isClickable={true} isPlain={true}>
<Card isCompact={true} isPlain={true}>
<CardHeader
selectableActions={{
onClickAction: () =>
actorRef.send({
type: "SELECT_PATH_VISUALIZER",
path: path.node.path,
nodePath: path.node.nodePath,
}),
selectableActionAriaLabelledby: `path-title-${path.node.nodePath}`,
actions={{
actions: (
<>
<Button
variant={"control"}
icon={<EyeIcon />}
onClick={() =>
actorRef.send({
type: "SELECT_PATH_VISUALIZER",
path: path.node.path,
nodePath: path.node.nodePath,
})
}
/>
<Button
variant={"control"}
icon={<PencilAltIcon />}
onClick={() =>
actorRef.send({
type: "SELECT_PATH_DESIGNER",
path: path.node.path,
nodePath: path.node.nodePath,
})
}
/>
</>
),
hasNoOffset: true,
}}
>
<CardTitle id={`path-title-${path.node.nodePath}`}>
Expand Down

0 comments on commit ff8486b

Please sign in to comment.