Partial fix for #9774. When `admin.disableListColumn` is set retroactively, it continues to appear in column state, but shouldn't. This was because the table column context was not refreshing after HMR runs, and would instead hold onto these stale columns until the page itself refreshes. Similarly, this was also a problem when the user had saved any of these columns to their list preferences, where those prefs would take precedence despite these properties being set on the underlying fields. The fix is to filter these columns from all requests that send them, and ensure local component state properly refreshes itself.
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
import type { Endpoint, PayloadHandler } from 'payload'
|
|
|
|
import { addDataAndFileToRequest } from '@payloadcms/next/utilities'
|
|
import httpStatus from 'http-status'
|
|
|
|
export const handler: PayloadHandler = async (req) => {
|
|
await addDataAndFileToRequest(req)
|
|
|
|
const { data, payload, user } = req
|
|
|
|
const operation = data?.operation ? String(data.operation) : undefined
|
|
|
|
if (data?.operation && typeof payload[operation] === 'function') {
|
|
try {
|
|
const result = await payload[operation]({
|
|
...(typeof data.args === 'object' ? data.args : {}),
|
|
user,
|
|
})
|
|
|
|
return Response.json(result, {
|
|
status: httpStatus.OK,
|
|
})
|
|
} catch (err) {
|
|
payload.logger.error(err)
|
|
return Response.json(err, {
|
|
status: httpStatus.BAD_REQUEST,
|
|
})
|
|
}
|
|
}
|
|
|
|
return Response.json(
|
|
{
|
|
message: 'Payload Local API method not found.',
|
|
},
|
|
{
|
|
status: httpStatus.BAD_REQUEST,
|
|
},
|
|
)
|
|
}
|
|
|
|
export const localAPIEndpoint: Endpoint = {
|
|
path: '/local-api',
|
|
method: 'post',
|
|
handler,
|
|
}
|