mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 09:33:21 +00:00
Formatting
This commit is contained in:
@@ -49,7 +49,7 @@ async function OpenAPIBody(props: BlockProps<DocumentBlockSwagger>) {
|
||||
|
||||
// To update the code sample we need to re-render the server component
|
||||
// so reading the cached value from search params
|
||||
const serverUrl = serverUrlCache.get('serverUrl');
|
||||
const serverUrl = serverUrlCache.get('serverUrl');
|
||||
|
||||
return (
|
||||
<OpenAPIClientStateContainer block={block} servers={data.servers}>
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import { OpenAPIV3 } from 'openapi-types';
|
||||
import * as React from 'react';
|
||||
|
||||
/**
|
||||
* Client component that wraps `OpenAPIClientState` so we can
|
||||
* Client component that wraps `OpenAPIClientState` so we can
|
||||
* use some hooks (e.g. useRouter) in the `onUpdate` callback.
|
||||
*/
|
||||
export default function OpenAPIClientStateContainer(props: {
|
||||
|
||||
@@ -65,7 +65,10 @@ export function OpenAPIClientState(props: {
|
||||
);
|
||||
}
|
||||
|
||||
function parseClientStateModifiers(servers: OpenAPIV3.ServerObject[], params: Record<string, string>) {
|
||||
function parseClientStateModifiers(
|
||||
servers: OpenAPIV3.ServerObject[],
|
||||
params: Record<string, string>,
|
||||
) {
|
||||
if (!servers) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -21,15 +21,19 @@ export function OpenAPIServerURL(props: {
|
||||
const { path, servers, context } = props;
|
||||
const stateContext = useOpenAPIClientState();
|
||||
|
||||
const serverIndex = !isNaN(Number(stateContext?.state?.server)) ? Number(stateContext?.state?.server) : 0;
|
||||
const serverIndex = !isNaN(Number(stateContext?.state?.server))
|
||||
? Number(stateContext?.state?.server)
|
||||
: 0;
|
||||
const server = servers[serverIndex];
|
||||
const parts = parseServerURL(server?.url ?? '');
|
||||
|
||||
if (!server) { return null; }
|
||||
if (!server) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ServerURLForm context={context} servers={servers} serverIndex={serverIndex}>
|
||||
<span className={classNames(stateContext?.isPending && "openapi-pending")}>
|
||||
<span className={classNames(stateContext?.isPending && 'openapi-pending')}>
|
||||
{parts.map((part, i) => {
|
||||
if (part.kind === 'text') {
|
||||
return <span key={i}>{part.text}</span>;
|
||||
|
||||
@@ -52,9 +52,9 @@ export function ServerURLForm(props: {
|
||||
});
|
||||
}
|
||||
|
||||
// Only make the server url editable if there is some onUpdate callback
|
||||
// Only make the server url editable if there is some onUpdate callback
|
||||
// and if there are variations on the server url (e.g. an array of servers or url variables).
|
||||
const isEditable = stateContext?.onUpdate && (servers.length > 1 || server.variables);
|
||||
const isEditable = stateContext?.onUpdate && (servers.length > 1 || server.variables);
|
||||
const isEditing = isEditable && stateContext?.state?.edit;
|
||||
return (
|
||||
<form
|
||||
@@ -89,9 +89,7 @@ export function ServerURLForm(props: {
|
||||
: { edit: 'true' }),
|
||||
});
|
||||
}}
|
||||
title={
|
||||
isEditing ? undefined : 'Try different server options'
|
||||
}
|
||||
title={isEditing ? undefined : 'Try different server options'}
|
||||
aria-label={isEditing ? 'Clear' : 'Edit'}
|
||||
>
|
||||
{isEditing ? context.icons.editDone : context.icons.edit}
|
||||
|
||||
Reference in New Issue
Block a user