chore: consolidates admin view types
This commit is contained in:
@@ -52,18 +52,14 @@ export const globalCustomRoutes = (props: {
|
||||
const routesToReturn = [...acc]
|
||||
|
||||
if (typeof ViewComponent === 'function') {
|
||||
routesToReturn.push(<ViewComponent global={global} key={ViewComponent.name} user={user} />)
|
||||
routesToReturn.push(<ViewComponent key={ViewComponent.name} user={user} />)
|
||||
} else {
|
||||
const { Component, path } = ViewComponent
|
||||
|
||||
if (global) {
|
||||
routesToReturn.push(
|
||||
<Route exact key={`${global.slug}-${path}`} path={`${match.url}${path}`}>
|
||||
{permissions?.read?.permission ? (
|
||||
<Component global={global} user={user} />
|
||||
) : (
|
||||
<Unauthorized />
|
||||
)}
|
||||
{permissions?.read?.permission ? <Component user={user} /> : <Unauthorized />}
|
||||
</Route>,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -52,20 +52,14 @@ export const collectionCustomRoutes = (props: {
|
||||
const routesToReturn = [...acc]
|
||||
|
||||
if (typeof ViewComponent === 'function') {
|
||||
routesToReturn.push(
|
||||
<ViewComponent collection={collection} key={ViewComponent.name} user={user} />,
|
||||
)
|
||||
routesToReturn.push(<ViewComponent key={ViewComponent.name} user={user} />)
|
||||
} else {
|
||||
const { Component, path } = ViewComponent
|
||||
|
||||
if (collection) {
|
||||
routesToReturn.push(
|
||||
<Route exact key={`${collection.slug}-${path}`} path={`${match.url}${path}`}>
|
||||
{permissions?.read?.permission ? (
|
||||
<Component collection={collection} user={user} />
|
||||
) : (
|
||||
<Unauthorized />
|
||||
)}
|
||||
{permissions?.read?.permission ? <Component user={user} /> : <Unauthorized />}
|
||||
</Route>,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ import type { Props as ListProps } from '../../admin/components/views/collection
|
||||
import type { Auth, IncomingAuthType, User } from '../../auth/types'
|
||||
import type {
|
||||
Access,
|
||||
AdminViewComponent,
|
||||
EditView,
|
||||
EditViewComponent,
|
||||
Endpoint,
|
||||
EntityDescription,
|
||||
GeneratePreviewURL,
|
||||
@@ -233,7 +233,7 @@ export type CollectionAdminOptions = {
|
||||
// References?: EditView
|
||||
// Relationships?: EditView
|
||||
}
|
||||
| EditViewComponent
|
||||
| AdminViewComponent
|
||||
List?: React.ComponentType<ListProps>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,8 +242,6 @@ export type AdminViewConfig = {
|
||||
|
||||
export type AdminViewProps = {
|
||||
canAccessAdmin?: boolean
|
||||
collection?: SanitizedCollectionConfig
|
||||
global?: SanitizedGlobalConfig
|
||||
user: User | null | undefined
|
||||
}
|
||||
|
||||
@@ -256,18 +254,12 @@ export type EditViewConfig = {
|
||||
* The component to render for this view
|
||||
* + Replaces the default component
|
||||
*/
|
||||
Component: EditViewComponent
|
||||
Component: AdminViewComponent
|
||||
Tab: DocumentTab
|
||||
path: string
|
||||
}
|
||||
|
||||
export type EditViewComponent = React.ComponentType<{
|
||||
collection?: SanitizedCollectionConfig
|
||||
global?: SanitizedGlobalConfig
|
||||
user: User | null | undefined
|
||||
}>
|
||||
|
||||
export type EditView = EditViewComponent | EditViewConfig
|
||||
export type EditView = AdminViewComponent | EditViewConfig
|
||||
|
||||
export type Locale = {
|
||||
/**
|
||||
|
||||
@@ -10,8 +10,8 @@ import type {
|
||||
import type { User } from '../../auth/types'
|
||||
import type {
|
||||
Access,
|
||||
AdminViewComponent,
|
||||
EditView,
|
||||
EditViewComponent,
|
||||
Endpoint,
|
||||
EntityDescription,
|
||||
GeneratePreviewURL,
|
||||
@@ -100,7 +100,7 @@ export type GlobalAdminOptions = {
|
||||
// References?: EditView
|
||||
// Relationships?: EditView
|
||||
}
|
||||
| EditViewComponent
|
||||
| AdminViewComponent
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ const CustomDefaultView: AdminViewComponent = ({ canAccessAdmin, user }) => {
|
||||
const {
|
||||
routes: { admin: adminRoute },
|
||||
} = useConfig()
|
||||
|
||||
const { setStepNav } = useStepNav()
|
||||
|
||||
// This effect will only run one time and will allow us
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import React, { Fragment, useEffect } from 'react'
|
||||
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 { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config'
|
||||
|
||||
const CustomDefaultView: EditViewComponent = ({
|
||||
const CustomDefaultView: AdminViewComponent = ({
|
||||
canAccessAdmin,
|
||||
// collection,
|
||||
// global,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import React, { Fragment, useEffect } from 'react'
|
||||
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 { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config'
|
||||
|
||||
const CustomEditView: EditViewComponent = ({
|
||||
const CustomEditView: AdminViewComponent = ({
|
||||
canAccessAdmin,
|
||||
// collection,
|
||||
// global,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import React, { Fragment, useEffect } from 'react'
|
||||
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 { useConfig } from '../../../../../packages/payload/src/admin/components/utilities/Config'
|
||||
|
||||
const CustomVersionsView: EditViewComponent = ({
|
||||
const CustomVersionsView: AdminViewComponent = ({
|
||||
canAccessAdmin,
|
||||
// collection,
|
||||
// global,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React, { Fragment, useEffect } from 'react'
|
||||
|
||||
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()
|
||||
|
||||
// This effect will only run one time and will allow us
|
||||
|
||||
Reference in New Issue
Block a user