Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions packages/next/src/views/List/handleServerFunction.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { CollectionPreferences, ListQuery, ServerFunction, VisibleEntities } from 'payload'
import type { RenderListServerFnArgs, RenderListServerFnReturnType } from '@payloadcms/ui'
import type { CollectionPreferences, ServerFunction, VisibleEntities } from 'payload'

import { getClientConfig } from '@payloadcms/ui/utilities/getClientConfig'
import { headers as getHeaders } from 'next/headers.js'
Expand All @@ -7,27 +8,9 @@ import { applyLocaleFiltering } from 'payload/shared'

import { renderListView } from './index.js'

type RenderListResult = {
List: React.ReactNode
preferences: CollectionPreferences
}

export const renderListHandler: ServerFunction<
{
collectionSlug: string
disableActions?: boolean
disableBulkDelete?: boolean
disableBulkEdit?: boolean
disableQueryPresets?: boolean
documentDrawerSlug: string
drawerSlug?: string
enableRowSelections: boolean
overrideEntityVisibility?: boolean
query: ListQuery
redirectAfterDelete: boolean
redirectAfterDuplicate: boolean
},
Promise<RenderListResult>
RenderListServerFnArgs,
Promise<RenderListServerFnReturnType>
> = async (args) => {
const {
collectionSlug,
Expand Down
14 changes: 8 additions & 6 deletions packages/ui/src/elements/ListDrawer/DrawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { hoistQueryParamsToAnd } from 'payload/shared'
import React, { useCallback, useEffect, useState } from 'react'

import type { ListDrawerContextProps, ListDrawerContextType } from '../ListDrawer/Provider.js'
import type { ListDrawerProps } from './types.js'
import type {
ListDrawerProps,
RenderListServerFnArgs,
RenderListServerFnReturnType,
} from './types.js'

import { useDocumentDrawer } from '../../elements/DocumentDrawer/index.js'
import { useEffectEvent } from '../../hooks/useEffectEvent.js'
Expand Down Expand Up @@ -92,10 +96,9 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({
}

if (slug) {
const result: { List: React.ReactNode } = (await serverFunction({
const result: RenderListServerFnReturnType = (await serverFunction({
name: 'render-list',
args: {
allowCreate,
collectionSlug: slug,
disableBulkDelete: true,
disableBulkEdit: true,
Expand All @@ -104,8 +107,8 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({
enableRowSelections,
overrideEntityVisibility,
query: newQuery,
},
})) as { List: React.ReactNode }
} satisfies RenderListServerFnArgs,
})) as RenderListServerFnReturnType

setListView(result?.List || null)
} else {
Expand All @@ -123,7 +126,6 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({
[
serverFunction,
closeModal,
allowCreate,
drawerSlug,
isOpen,
enableRowSelections,
Expand Down
32 changes: 31 additions & 1 deletion packages/ui/src/elements/ListDrawer/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
import type { FilterOptionsResult, SanitizedCollectionConfig } from 'payload'
import type {
CollectionPreferences,
FilterOptionsResult,
ListQuery,
SanitizedCollectionConfig,
} from 'payload'
import type React from 'react'
import type { HTMLAttributes } from 'react'

import type { ListDrawerContextProps } from './Provider.js'

/**
* @internal - this may change in a minor release
*/
export type RenderListServerFnArgs = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable names here match variable names of render-field server action

collectionSlug: string
disableActions?: boolean
disableBulkDelete?: boolean
disableBulkEdit?: boolean
disableQueryPresets?: boolean
drawerSlug?: string
enableRowSelections: boolean
overrideEntityVisibility?: boolean
query: ListQuery
redirectAfterDelete?: boolean
redirectAfterDuplicate?: boolean
}

/**
* @internal - this may change in a minor release
*/
export type RenderListServerFnReturnType = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable names here match variable names of render-field server action

List: React.ReactNode
preferences: CollectionPreferences
}

export type ListDrawerProps = {
readonly allowCreate?: boolean
readonly collectionSlugs: SanitizedCollectionConfig['slug'][]
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/exports/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export { useListDrawer } from '../../elements/ListDrawer/index.js'
export type {
ListDrawerProps,
ListTogglerProps,
RenderListServerFnArgs,
RenderListServerFnReturnType,
UseListDrawer,
} from '../../elements/ListDrawer/types.js'
export { ListSelection } from '../../views/List/ListSelection/index.js'
Expand Down
Loading