diff --git a/.changeset/eighty-owls-type.md b/.changeset/eighty-owls-type.md new file mode 100644 index 000000000..b671f1e1b --- /dev/null +++ b/.changeset/eighty-owls-type.md @@ -0,0 +1,5 @@ +--- +'gitbook': patch +--- + +Improve consistency of change request preview by removing cache-control on response diff --git a/.changeset/sixty-paws-share.md b/.changeset/sixty-paws-share.md new file mode 100644 index 000000000..ce6f5ffb1 --- /dev/null +++ b/.changeset/sixty-paws-share.md @@ -0,0 +1,5 @@ +--- +'gitbook': minor +--- + +Improve the toolbar for change-requests and revisions to show more actions diff --git a/packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx b/packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx index 3fad38f96..671896844 100644 --- a/packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx +++ b/packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx @@ -1,9 +1,12 @@ import { Space } from '@gitbook/api'; +import { Icon } from '@gitbook/icons'; import React from 'react'; import { ContentPointer, getChangeRequest, getRevision } from '@/lib/api'; import { tcls } from '@/lib/tailwind'; +import { DateRelative } from '../primitives'; + interface AdminToolbarProps { content: ContentPointer; space: Space; @@ -67,9 +70,27 @@ async function ChangeRequestToolbar(props: { spaceId: string; changeRequestId: s const changeRequest = await getChangeRequest(spaceId, changeRequestId); return ( - - Change request #{changeRequest.number}: {changeRequest.subject ?? 'No subject'} - + + + + + + + #{changeRequest.number}: {changeRequest.subject ?? 'No subject'} + + + Change request updated + + + + + + + + + + + ); } @@ -77,34 +98,93 @@ async function RevisionToolbar(props: { spaceId: string; revisionId: string }) { const { spaceId, revisionId } = props; const revision = await getRevision(spaceId, revisionId, { - metadata: false, + metadata: true, }); return ( - - Revision created on {new Date(revision.createdAt).toLocaleDateString()} - + + + + + + + Revision created + + {revision.git ? ( + {revision.git.message} + ) : null} + + + + + + {revision.git?.url ? ( + + + + ) : null} + + ); } -function ToolbarButton(props: { href: string; children: React.ReactNode }) { - const { href, children } = props; +function Toolbar(props: { children: React.ReactNode }) { + const { children } = props; return ( - + {children} + + ); +} + +function ToolbarBody(props: { children: React.ReactNode }) { + return {props.children}; +} + +function ToolbarButtonGroups(props: { children: React.ReactNode }) { + return {props.children}; +} + +function ToolbarButton(props: { title: string; href: string; children: React.ReactNode }) { + const { title, href, children } = props; + return ( + {children} diff --git a/packages/gitbook/src/lib/api.ts b/packages/gitbook/src/lib/api.ts index 96b3f2fc3..c319625e0 100644 --- a/packages/gitbook/src/lib/api.ts +++ b/packages/gitbook/src/lib/api.ts @@ -306,8 +306,6 @@ export const getChangeRequest = cache({ signal: options.signal, }); return cacheResponse(response, { - // We don't cache for long as we currently don't invalidate change-request cache - // and it's only used for preview where perfs are not critical ttl: 60 * 60, revalidateBefore: 10 * 60, }); diff --git a/packages/gitbook/src/middleware.ts b/packages/gitbook/src/middleware.ts index 9ba3e06ef..b3e1bc57b 100644 --- a/packages/gitbook/src/middleware.ts +++ b/packages/gitbook/src/middleware.ts @@ -276,7 +276,7 @@ export async function middleware(request: NextRequest) { 'private, no-cache, no-store, max-age=0, must-revalidate', ); } else { - if (resolved.cacheMaxAge) { + if (typeof resolved.cacheMaxAge === 'number') { const cacheControl = `public, max-age=0, s-maxage=${resolved.cacheMaxAge}, stale-if-error=0`; if ( @@ -666,14 +666,17 @@ async function lookupSpaceByAPI( return null; } + const changeRequest = data.changeRequest ?? lookup.changeRequest; return { space: data.space, - changeRequest: data.changeRequest ?? lookup.changeRequest, + changeRequest, revision: data.revision ?? lookup.revision, basePath: joinPath(data.basePath, lookup.basePath ?? ''), pathname: joinPath(data.pathname, alternative.extraPath), apiToken: data.apiToken, - cacheMaxAge: data.cacheMaxAge, + // We don't cache change requests as they often change and we want to have consistent previews + // Purging the CDN cache will not be efficient enough. + cacheMaxAge: changeRequest ? 0 : data.cacheMaxAge, cacheTags: data.cacheTags, ...('site' in data ? {
+ #{changeRequest.number}: {changeRequest.subject ?? 'No subject'} +
+ Change request updated +
+ Revision created +
{revision.git.message}