mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Revised client state with context
This commit is contained in:
@@ -93,7 +93,6 @@ export default async function Page(props: {
|
||||
// Display the page feedback in the page footer if the aside is not visible
|
||||
withPageFeedback && !page.layout.outline
|
||||
}
|
||||
searchParams={searchParams}
|
||||
/>
|
||||
{page.layout.outline ? (
|
||||
<PageAside
|
||||
|
||||
@@ -46,8 +46,6 @@ export interface DocumentContext {
|
||||
* https://linear.app/gitbook-x/issue/RND-3588/gitbook-open-code-syntax-highlighting-runs-out-of-memory-after-a
|
||||
*/
|
||||
shouldHighlightCode: (spaceId: string | undefined) => boolean;
|
||||
|
||||
searchParams?: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface DocumentContextProps {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DocumentBlockSwagger } from '@gitbook/api';
|
||||
import { Icon } from '@gitbook/icons';
|
||||
import { OpenAPIOperation, OpenAPIOperationData } from '@gitbook/react-openapi';
|
||||
import { OpenAPIOperation } from '@gitbook/react-openapi';
|
||||
import React from 'react';
|
||||
|
||||
import { LoadingPane } from '@/components/primitives';
|
||||
@@ -100,27 +100,3 @@ function OpenAPIFallback() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function parseModifiers(data: OpenAPIOperationData, params: Record<string, string>) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
const { server: serverQueryParam } = params;
|
||||
const serverIndex =
|
||||
serverQueryParam && !isNaN(Number(serverQueryParam))
|
||||
? Math.max(0, Math.min(Number(serverQueryParam), data.servers.length - 1))
|
||||
: 0;
|
||||
const server = data.servers[serverIndex];
|
||||
if (server) {
|
||||
return Object.keys(server.variables ?? {}).reduce<Record<string, number>>(
|
||||
(result, key) => {
|
||||
const selection = Number(params[key]);
|
||||
if (!isNaN(selection)) {
|
||||
result[key] = selection;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
{ server: serverIndex },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ export function PageBody(props: {
|
||||
document: JSONDocument | null;
|
||||
context: ContentRefContext;
|
||||
withPageFeedback: boolean;
|
||||
searchParams: Record<string, string>;
|
||||
}) {
|
||||
const {
|
||||
space,
|
||||
@@ -45,7 +44,6 @@ export function PageBody(props: {
|
||||
page,
|
||||
document,
|
||||
withPageFeedback,
|
||||
searchParams,
|
||||
} = props;
|
||||
|
||||
const asFullWidth = document ? hasFullWidthBlock(document) : false;
|
||||
@@ -98,7 +96,6 @@ export function PageBody(props: {
|
||||
resolveContentRef: (ref, options) =>
|
||||
resolveContentRef(ref, context, options),
|
||||
shouldHighlightCode,
|
||||
searchParams,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
|
||||
@@ -5,7 +5,7 @@ import { OpenAPIOperationData, toJSON } from './fetchOpenAPIOperation';
|
||||
import { Markdown } from './Markdown';
|
||||
import { OpenAPICodeSample } from './OpenAPICodeSample';
|
||||
import { OpenAPIResponseExample } from './OpenAPIResponseExample';
|
||||
import { getServersURL, OpenAPIServerURL } from './OpenAPIServerURL';
|
||||
import { OpenAPIServerURL } from './OpenAPIServerURL';
|
||||
import { OpenAPISpec } from './OpenAPISpec';
|
||||
import { OpenAPIClientContext, OpenAPIContextProps } from './types';
|
||||
import { ScalarApiClient } from './ScalarApiButton';
|
||||
@@ -25,11 +25,10 @@ export async function OpenAPIOperation(props: {
|
||||
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
||||
icons: context.icons,
|
||||
blockKey: context.blockKey,
|
||||
enumSelectors: context.enumSelectors,
|
||||
};
|
||||
|
||||
return (
|
||||
<ScalarApiClient serverUrl={getServersURL(data.servers, context.enumSelectors)}>
|
||||
<ScalarApiClient>
|
||||
<div className={classNames('openapi-operation', className)}>
|
||||
<div className="openapi-intro">
|
||||
<h2 className="openapi-summary" id={context.id}>
|
||||
|
||||
@@ -18,7 +18,6 @@ export function OpenAPIServerURL(props: {
|
||||
}) {
|
||||
const { path, servers, context } = props;
|
||||
const ctx = useOpenAPIContext();
|
||||
|
||||
const serverIndex = !isNaN(Number(ctx?.state?.server)) ? Number(ctx?.state?.server) : 0;
|
||||
const server = servers[serverIndex];
|
||||
const parts = parseServerURL(server?.url ?? '');
|
||||
|
||||
@@ -67,9 +67,9 @@ export function ServerURLForm(props: {
|
||||
{children}
|
||||
{stateContext?.state?.edit && servers.length > 1 ? (
|
||||
<ServerSelector
|
||||
servers={servers}
|
||||
currentIndex={serverIndex}
|
||||
onChange={switchServer}
|
||||
servers={servers}
|
||||
currentIndex={serverIndex}
|
||||
onChange={switchServer}
|
||||
/>
|
||||
) : null}
|
||||
{isEditable ? (
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
'use client';
|
||||
import * as React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import classNames from 'classnames';
|
||||
import { OpenAPIV3 } from 'openapi-types';
|
||||
import { OpenAPIClientContext } from './types';
|
||||
|
||||
/**
|
||||
* Interactive component to show the value of a server variable and let the user change it.
|
||||
|
||||
Reference in New Issue
Block a user