It is currently very difficult to build custom edit and list views or inject custom components into these views because these views and components are not explicitly typed. Instances of these components were not fully type safe as well, i.e. when rendering them via `RenderServerComponent`, there was little to no type-checking in most cases. There is now a 1:1 type match for all views and view components and they now receive type-checking at render time. The following types have been newly added and/or improved: List View: - `ListViewClientProps` - `ListViewServerProps` - `BeforeListClientProps` - `BeforeListServerProps` - `BeforeListTableClientProps` - `BeforeListTableServerProps` - `AfterListClientProps` - `AfterListServerProps` - `AfterListTableClientProps` - `AfterListTableServerProps` - `ListViewSlotSharedClientProps` Document View: - `DocumentViewClientProps` - `DocumentViewServerProps` - `SaveButtonClientProps` - `SaveButtonServerProps` - `SaveDraftButtonClientProps` - `SaveDraftButtonServerProps` - `PublishButtonClientProps` - `PublishButtonServerProps` - `PreviewButtonClientProps` - `PreviewButtonServerProps` Root View: - `AdminViewClientProps` - `AdminViewServerProps` General: - `ViewDescriptionClientProps` - `ViewDescriptionServerProps` A few other changes were made in a non-breaking way: - `Column` is now exported from `payload` - `ListPreferences` is now exported from `payload` - `ListViewSlots` is now exported from `payload` - `ListViewClientProps` is now exported from `payload` - `AdminViewProps` is now an alias of `AdminViewServerProps` (listed above) - `ClientSideEditViewProps` is now an alias of `DocumentViewClientProps` (listed above) - `ServerSideEditViewProps` is now an alias of `DocumentViewServerProps` (listed above) - `ListComponentClientProps` is now an alias of `ListViewClientProps` (listed above) - `ListComponentServerProps` is now an alias of `ListViewServerProps` (listed above) - `CustomSaveButton` is now marked as deprecated because this is only relevant to the config (see correct type above) - `CustomSaveDraftButton` is now marked as deprecated because this is only relevant to the config (see correct type above) - `CustomPublishButton` is now marked as deprecated because this is only relevant to the config (see correct type above) - `CustomPreviewButton` is now marked as deprecated because this is only relevant to the config (see correct type above) This PR _does not_ apply these changes to _root_ components, i.e. `afterNavLinks`. Those will come in a future PR. Related: #10987.
71 lines
1.8 KiB
TypeScript
71 lines
1.8 KiB
TypeScript
import type { DocumentViewServerProps } from 'payload'
|
|
|
|
import { SetStepNav } from '@payloadcms/ui'
|
|
import { notFound, redirect } from 'next/navigation.js'
|
|
import React, { Fragment } from 'react'
|
|
|
|
export function CustomVersionsView({ initPageResult }: DocumentViewServerProps) {
|
|
if (!initPageResult) {
|
|
notFound()
|
|
}
|
|
|
|
const {
|
|
permissions: { canAccessAdmin },
|
|
req: {
|
|
payload: {
|
|
config: {
|
|
routes: { admin: adminRoute },
|
|
},
|
|
},
|
|
user,
|
|
},
|
|
} = initPageResult
|
|
|
|
// If an unauthorized user tries to navigate straight to this page,
|
|
// Boot 'em out
|
|
if (!user || (user && !canAccessAdmin)) {
|
|
return redirect(`${adminRoute}/unauthorized`)
|
|
}
|
|
|
|
return (
|
|
<Fragment>
|
|
<SetStepNav
|
|
nav={[
|
|
{
|
|
label: 'Custom Versions View',
|
|
},
|
|
]}
|
|
/>
|
|
<div
|
|
style={{
|
|
marginTop: 'calc(var(--base) * 2)',
|
|
paddingLeft: 'var(--gutter-h)',
|
|
paddingRight: 'var(--gutter-h)',
|
|
}}
|
|
>
|
|
<h1>Custom Versions View</h1>
|
|
<p>This custom Versions view was added through one of the following Payload configs:</p>
|
|
<ul>
|
|
<li>
|
|
<code>components.views.edit.Versions</code>
|
|
<p>
|
|
{'This allows you to override only the Versions edit view specifically, but '}
|
|
<b>
|
|
<em>not</em>
|
|
</b>
|
|
{' any other views. The document header will render above this component.'}
|
|
</p>
|
|
</li>
|
|
<li>
|
|
<code>components.views.edit.versions.Component</code>
|
|
</li>
|
|
<p>
|
|
This is the most granular override, allowing you to override only the Versions
|
|
component, or any of its other properties like path and label.
|
|
</p>
|
|
</ul>
|
|
</div>
|
|
</Fragment>
|
|
)
|
|
}
|