chore: consolidates admin view types

This commit is contained in:
Jacob Fletcher
2023-10-08 20:50:07 -04:00
parent 501ec4464f
commit 25ae4a24f2
10 changed files with 19 additions and 36 deletions

View File

@@ -52,18 +52,14 @@ export const globalCustomRoutes = (props: {
const routesToReturn = [...acc] const routesToReturn = [...acc]
if (typeof ViewComponent === 'function') { if (typeof ViewComponent === 'function') {
routesToReturn.push(<ViewComponent global={global} key={ViewComponent.name} user={user} />) routesToReturn.push(<ViewComponent key={ViewComponent.name} user={user} />)
} else { } else {
const { Component, path } = ViewComponent const { Component, path } = ViewComponent
if (global) { if (global) {
routesToReturn.push( routesToReturn.push(
<Route exact key={`${global.slug}-${path}`} path={`${match.url}${path}`}> <Route exact key={`${global.slug}-${path}`} path={`${match.url}${path}`}>
{permissions?.read?.permission ? ( {permissions?.read?.permission ? <Component user={user} /> : <Unauthorized />}
<Component global={global} user={user} />
) : (
<Unauthorized />
)}
</Route>, </Route>,
) )
} }

View File

@@ -52,20 +52,14 @@ export const collectionCustomRoutes = (props: {
const routesToReturn = [...acc] const routesToReturn = [...acc]
if (typeof ViewComponent === 'function') { if (typeof ViewComponent === 'function') {
routesToReturn.push( routesToReturn.push(<ViewComponent key={ViewComponent.name} user={user} />)
<ViewComponent collection={collection} key={ViewComponent.name} user={user} />,
)
} else { } else {
const { Component, path } = ViewComponent const { Component, path } = ViewComponent
if (collection) { if (collection) {
routesToReturn.push( routesToReturn.push(
<Route exact key={`${collection.slug}-${path}`} path={`${match.url}${path}`}> <Route exact key={`${collection.slug}-${path}`} path={`${match.url}${path}`}>
{permissions?.read?.permission ? ( {permissions?.read?.permission ? <Component user={user} /> : <Unauthorized />}
<Component collection={collection} user={user} />
) : (
<Unauthorized />
)}
</Route>, </Route>,
) )
} }

View File

@@ -14,8 +14,8 @@ import type { Props as ListProps } from '../../admin/components/views/collection
import type { Auth, IncomingAuthType, User } from '../../auth/types' import type { Auth, IncomingAuthType, User } from '../../auth/types'
import type { import type {
Access, Access,
AdminViewComponent,
EditView, EditView,
EditViewComponent,
Endpoint, Endpoint,
EntityDescription, EntityDescription,
GeneratePreviewURL, GeneratePreviewURL,
@@ -233,7 +233,7 @@ export type CollectionAdminOptions = {
// References?: EditView // References?: EditView
// Relationships?: EditView // Relationships?: EditView
} }
| EditViewComponent | AdminViewComponent
List?: React.ComponentType<ListProps> List?: React.ComponentType<ListProps>
} }
} }

View File

@@ -242,8 +242,6 @@ export type AdminViewConfig = {
export type AdminViewProps = { export type AdminViewProps = {
canAccessAdmin?: boolean canAccessAdmin?: boolean
collection?: SanitizedCollectionConfig
global?: SanitizedGlobalConfig
user: User | null | undefined user: User | null | undefined
} }
@@ -256,18 +254,12 @@ export type EditViewConfig = {
* The component to render for this view * The component to render for this view
* + Replaces the default component * + Replaces the default component
*/ */
Component: EditViewComponent Component: AdminViewComponent
Tab: DocumentTab Tab: DocumentTab
path: string path: string
} }
export type EditViewComponent = React.ComponentType<{ export type EditView = AdminViewComponent | EditViewConfig
collection?: SanitizedCollectionConfig
global?: SanitizedGlobalConfig
user: User | null | undefined
}>
export type EditView = EditViewComponent | EditViewConfig
export type Locale = { export type Locale = {
/** /**

View File

@@ -10,8 +10,8 @@ import type {
import type { User } from '../../auth/types' import type { User } from '../../auth/types'
import type { import type {
Access, Access,
AdminViewComponent,
EditView, EditView,
EditViewComponent,
Endpoint, Endpoint,
EntityDescription, EntityDescription,
GeneratePreviewURL, GeneratePreviewURL,
@@ -100,7 +100,7 @@ export type GlobalAdminOptions = {
// References?: EditView // References?: EditView
// Relationships?: EditView // Relationships?: EditView
} }
| EditViewComponent | AdminViewComponent
} }
} }
/** /**

View File

@@ -25,6 +25,7 @@ const CustomDefaultView: AdminViewComponent = ({ canAccessAdmin, user }) => {
const { const {
routes: { admin: adminRoute }, routes: { admin: adminRoute },
} = useConfig() } = useConfig()
const { setStepNav } = useStepNav() const { setStepNav } = useStepNav()
// This effect will only run one time and will allow us // This effect will only run one time and will allow us

View File

@@ -1,12 +1,12 @@
import React, { Fragment, useEffect } from 'react' import React, { Fragment, useEffect } from 'react'
import { Redirect } from 'react-router-dom' import { Redirect } from 'react-router-dom'
import type { EditViewComponent } from '../../../../../packages/payload/src/config/types' import type { AdminViewComponent } from '../../../../../packages/payload/src/config/types'
import { useStepNav } from '../../../../../packages/payload/src/admin/components/elements/StepNav' import { useStepNav } from '../../../../../packages/payload/src/admin/components/elements/StepNav'
import { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config' import { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config'
const CustomDefaultView: EditViewComponent = ({ const CustomDefaultView: AdminViewComponent = ({
canAccessAdmin, canAccessAdmin,
// collection, // collection,
// global, // global,

View File

@@ -1,12 +1,12 @@
import React, { Fragment, useEffect } from 'react' import React, { Fragment, useEffect } from 'react'
import { Redirect } from 'react-router-dom' import { Redirect } from 'react-router-dom'
import type { EditViewComponent } from '../../../../../packages/payload/src/config/types' import type { AdminViewComponent } from '../../../../../packages/payload/src/config/types'
import { useStepNav } from '../../../../../packages/payload/src/admin/components/elements/StepNav' import { useStepNav } from '../../../../../packages/payload/src/admin/components/elements/StepNav'
import { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config' import { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config'
const CustomEditView: EditViewComponent = ({ const CustomEditView: AdminViewComponent = ({
canAccessAdmin, canAccessAdmin,
// collection, // collection,
// global, // global,

View File

@@ -1,12 +1,12 @@
import React, { Fragment, useEffect } from 'react' import React, { Fragment, useEffect } from 'react'
import { Redirect } from 'react-router-dom' import { Redirect } from 'react-router-dom'
import type { EditViewComponent } from '../../../../../packages/payload/src/config/types' import type { AdminViewComponent } from '../../../../../packages/payload/src/config/types'
import { useStepNav } from '../../../../../packages/payload/src/admin/components/elements/StepNav' import { useStepNav } from '../../../../../packages/payload/src/admin/components/elements/StepNav'
import { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config' import { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config'
const CustomVersionsView: EditViewComponent = ({ const CustomVersionsView: AdminViewComponent = ({
canAccessAdmin, canAccessAdmin,
// collection, // collection,
// global, // global,

View File

@@ -1,9 +1,9 @@
import React, { Fragment, useEffect } from 'react' import React, { Fragment, useEffect } from 'react'
import { useStepNav } from '../../../../../packages/payload/src/admin/components/elements/StepNav' import { useStepNav } from '../../../../../packages/payload/src/admin/components/elements/StepNav'
import { type EditViewComponent } from '../../../../../packages/payload/src/config/types' import { type AdminViewComponent } from '../../../../../packages/payload/src/config/types'
const CustomView: EditViewComponent = () => { const CustomView: AdminViewComponent = () => {
const { setStepNav } = useStepNav() const { setStepNav } = useStepNav()
// This effect will only run one time and will allow us // This effect will only run one time and will allow us