Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show full URL for method #176

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions packages/zudoku/src/lib/components/navigation/SidebarBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { cn } from "../../util/cn.js";

export const TextColorMap = {
green: "text-green-600",
blue: "text-sky-600",
yellow: "text-yellow-600",
red: "text-red-600",
purple: "text-purple-600",
indigo: "text-indigo-600",
gray: "text-gray-600",
};

export const ColorMap = {
green: "bg-green-400 dark:bg-green-800",
blue: "bg-sky-400 dark:bg-sky-800",
Expand Down
1 change: 1 addition & 0 deletions packages/zudoku/src/lib/plugins/openapi/OperationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const OperationList = () => {
<StaggeredRender>
{tag.operations.map((fragment) => (
<OperationListItem
serverUrl={result.data?.schema.url}
key={fragment.slug}
operationFragment={fragment}
/>
Expand Down
12 changes: 12 additions & 0 deletions packages/zudoku/src/lib/plugins/openapi/OperationListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import { ParameterList } from "./ParameterList.js";
import { Sidecar } from "./Sidecar.js";
import { FragmentType, useFragment } from "./graphql/index.js";
import { SchemaView } from "./schema/SchemaView.js";
import { methodForColor } from "./util/methodToColor.js";

export const PARAM_GROUPS = ["path", "query", "header", "cookie"] as const;
export type ParameterGroup = (typeof PARAM_GROUPS)[number];

export const OperationListItem = ({
operationFragment,
serverUrl,
}: {
operationFragment: FragmentType<typeof OperationsFragment>;
serverUrl?: string;
}) => {
const operation = useFragment(OperationsFragment, operationFragment);
const groupedParameters = groupBy(
Expand All @@ -36,6 +39,15 @@ export const OperationListItem = ({
<Heading level={2} id={operation.slug} registerSidebarAnchor>
{operation.summary}
</Heading>
<div className="text-sm flex gap-2 font-mono">
<span className={methodForColor(operation.method)}>
{operation.method.toUpperCase()}
</span>
<div className="font-mono">
<span className="text-gray-500">{serverUrl}</span>
<span className="text-gray-200">{operation.path}</span>
</div>
</div>
{operation.description && (
<Markdown
className={`${ProseClasses} max-w-full prose-img:max-w-prose`}
Expand Down
18 changes: 2 additions & 16 deletions packages/zudoku/src/lib/plugins/openapi/Sidecar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HTTPSnippet } from "@zudoku/httpsnippet";
import { Fragment, useMemo, useTransition } from "react";
import { useSearchParams } from "react-router-dom";
import { TextColorMap } from "../../components/navigation/SidebarBadge.js";
import { SyntaxHighlight } from "../../components/SyntaxHighlight.js";
import type { SchemaObject } from "../../oas/parser/index.js";
import { cn } from "../../util/cn.js";
Expand All @@ -15,6 +14,7 @@ import { ResponsesSidecarBox } from "./ResponsesSidecarBox.js";
import * as SidecarBox from "./SidecarBox.js";
import { SimpleSelect } from "./SimpleSelect.js";
import { generateSchemaExample } from "./util/generateSchemaExample.js";
import { methodForColor } from "./util/methodToColor.js";
import { useQuery } from "./util/urql.js";

const getConverted = (snippet: HTTPSnippet, option: string) => {
Expand Down Expand Up @@ -71,17 +71,6 @@ export const GetServerQuery = graphql(/* GraphQL */ `

const context = { suspense: true };

const methodToColor = {
get: TextColorMap.green,
post: TextColorMap.blue,
put: TextColorMap.yellow,
delete: TextColorMap.red,
patch: TextColorMap.purple,
options: TextColorMap.indigo,
head: TextColorMap.gray,
trace: TextColorMap.gray,
};

export const Sidecar = ({
operation,
selectedResponse,
Expand All @@ -97,10 +86,7 @@ export const Sidecar = ({
variables: oasConfig,
context,
});
const methodTextColor =
methodToColor[
operation.method.toLocaleLowerCase() as keyof typeof methodToColor
] ?? TextColorMap.gray;
const methodTextColor = methodForColor(operation.method);

const [searchParams, setSearchParams] = useSearchParams();
const [, startTransition] = useTransition();
Expand Down
27 changes: 27 additions & 0 deletions packages/zudoku/src/lib/plugins/openapi/util/methodToColor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const TextColorMap = {
green: "text-green-600",
blue: "text-sky-600",
yellow: "text-yellow-600",
red: "text-red-600",
purple: "text-purple-600",
indigo: "text-indigo-600",
gray: "text-gray-600",
};

export const methodToColor = {
get: TextColorMap.green,
post: TextColorMap.blue,
put: TextColorMap.yellow,
delete: TextColorMap.red,
patch: TextColorMap.purple,
options: TextColorMap.indigo,
head: TextColorMap.gray,
trace: TextColorMap.gray,
};

export const methodForColor = (method: string) => {
return (
methodToColor[method.toLocaleLowerCase() as keyof typeof methodToColor] ??
TextColorMap.gray
);
};