Skip to content

Commit 0d75985

Browse files
committed
some more styles
1 parent 5d76497 commit 0d75985

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { type ReactNode, useState } from "react";
2+
3+
interface CollapsibleSectionProps {
4+
title: string;
5+
children: ReactNode;
6+
defaultOpen?: boolean;
7+
}
8+
9+
export const CollapsibleSection = ({
10+
title,
11+
children,
12+
defaultOpen = false,
13+
}: CollapsibleSectionProps) => {
14+
const [isOpen, setIsOpen] = useState(defaultOpen);
15+
16+
return (
17+
<div className="mb-4 rounded-lg border">
18+
<button
19+
onClick={() => setIsOpen(!isOpen)}
20+
className="flex h-full w-full cursor-pointer items-center justify-between rounded-t-lg bg-gray-50 p-4 hover:bg-gray-100"
21+
>
22+
<h3 className="text-lg font-semibold">{title}</h3>
23+
<span className="text-lg">{isOpen ? "▼" : "▶"}</span>
24+
</button>
25+
{isOpen && <span className="border-t">{children}</span>}
26+
</div>
27+
);
28+
};

src/pages/analytics/graphql-api/api/[name].astro

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
55
import SchemaViewer from "~/components/models/SchemaViewer.astro";
66
import { Code } from "~/components";
77
import { LinkButton } from "~/components";
8+
import { CollapsibleSection } from "~/components/CollapsibleSection";
89
import {
910
GraphQLToJSONSchemaBuilder,
1011
type Field,
@@ -59,7 +60,10 @@ const typescriptInput = await compile(
5960
{ additionalProperties: false, bannerComment: "" },
6061
);
6162
62-
const [group, queryName] = name.split(".");
63+
const [group, queryName] = name.split(".") as [
64+
"account" | "zone" | "organization",
65+
string,
66+
];
6367
const gqlQuery = graphQLJSONSchemaToExample(
6468
`${group}s`,
6569
queryName,
@@ -74,19 +78,26 @@ const gqlQuery = graphQLJSONSchemaToExample(
7478
>
7579
<h2>{name.split(".").join(" ")}</h2>
7680
<p>{query.description}</p>
77-
<h3>Example</h3>
78-
<LinkButton href={`/analytics/graphql-api/graphiql?query=${btoa(gqlQuery)}`}
79-
>Open in GraphiQL</LinkButton
80-
>
81-
<Code code={gqlQuery} lang="graphql" />
82-
<h3 id="Parameters">Parameters</h3>
83-
<SchemaViewer schema={completeInputType} />
84-
<h4>Typescript definition</h4>
85-
<Code code={typescriptInput} lang="typescript" />
86-
<h3 id="Output">Output</h3>
87-
<SchemaViewer schema={completeResponseType} />
88-
<h4>Typescript definition</h4>
89-
<Code code={typescriptOutput} lang="typescript" />
81+
<div class="mt-4">
82+
<CollapsibleSection client:load title="Example GraphQL Query" defaultOpen>
83+
<LinkButton
84+
href={`/analytics/graphql-api/graphiql?query=${btoa(gqlQuery)}`}
85+
>Open in GraphiQL</LinkButton
86+
>
87+
<Code code={gqlQuery} lang="graphql" />
88+
</CollapsibleSection>
89+
90+
<CollapsibleSection client:load title="Parameters">
91+
<SchemaViewer schema={completeInputType} />
92+
<h4>Typescript definition</h4>
93+
<Code code={typescriptInput} lang="typescript" />
94+
</CollapsibleSection>
95+
<CollapsibleSection client:load title="Output">
96+
<SchemaViewer schema={completeResponseType} />
97+
<h4>Typescript definition</h4>
98+
<Code code={typescriptOutput} lang="typescript" />
99+
</CollapsibleSection>
100+
</div>
90101
</StarlightPage>
91102

92103
<style>

src/pages/analytics/graphql-api/graphiql.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import "~/tailwind.css";
1414
},
1515
}}
1616
/>
17+
1718
<style>
1819
:root {
1920
--sl-content-width: 100% !important;

src/util/graphQLJSONSchemaToExample.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export function graphQLJSONSchemaToExample(
2626
const outputSections = Object.keys(output.properties || {}).reduce(
2727
(outputQuery, key) => {
2828
const type = output.properties?.[key].type;
29-
console.log(type);
3029

3130
let outputQueryType = "";
3231
if (type === "object") {

0 commit comments

Comments
 (0)