chore: plugin lint fixes (#7947)

This commit is contained in:
Elliot DeNolf
2024-08-28 23:59:16 -04:00
committed by GitHub
parent 6e561b11ca
commit e5c34ead16
9 changed files with 23 additions and 51 deletions

View File

@@ -1,7 +1,7 @@
import type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'
import path from 'path'
import type { GenerateURL } from '../../types.js'
type GenerateUrlArgs = {
baseUrl: string
prefix?: string

View File

@@ -1,8 +1,8 @@
import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'
import { del } from '@vercel/blob'
import path from 'path'
import type { HandleDelete } from '../../types.js'
type HandleDeleteArgs = {
baseUrl: string
prefix?: string

View File

@@ -1,8 +1,7 @@
import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'
import { put } from '@vercel/blob'
import path from 'path'
import type { HandleUpload } from '../../types.js'
import type { VercelBlobAdapterUploadOptions } from './index.js'
type HandleUploadArgs = {

View File

@@ -1,4 +1,4 @@
import type { Adapter, GeneratedAdapter } from '@payloadcms/plugin-cloud-storage/types'
import type { Adapter, GeneratedAdapter } from '../../types.js'
import { getGenerateUrl } from './generateURL.js'
import { getHandleDelete } from './handleDelete.js'

View File

@@ -1,9 +1,10 @@
import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'
import type { CollectionConfig } from 'payload'
import { head } from '@vercel/blob'
import path from 'path'
import type { StaticHandler } from '../../types.js'
import { getFilePrefix } from '../../utilities/getFilePrefix.js'
type StaticHandlerArgs = {

View File

@@ -23,12 +23,6 @@ describe('plugin', () => {
verify: jest.fn(),
} as unknown as ReturnType<typeof nodemailer.createTransport>
})
const createTestAccountSpy = jest.spyOn(nodemailer, 'createTestAccount').mockResolvedValueOnce({
pass: 'password',
user: 'user',
web: 'ethereal.email',
} as unknown as nodemailer.TestAccount)
})
describe('not in Payload Cloud', () => {
@@ -69,7 +63,7 @@ describe('plugin', () => {
describe('email', () => {
it('should default to using payload cloud email', async () => {
const plugin = payloadCloudPlugin()
const config = await plugin(createConfig())
await plugin(createConfig())
expect(createTransportSpy).toHaveBeenCalledWith(
expect.objectContaining({
@@ -118,7 +112,7 @@ describe('plugin', () => {
})
const plugin = payloadCloudPlugin()
const config = await plugin(configWithTransport)
await plugin(configWithTransport)
expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining('Payload Cloud Email is enabled but'),
@@ -144,8 +138,8 @@ describe('plugin', () => {
const initializedEmail = emailConfig({ payload: mockedPayload })
expect(initializedEmail.defaultFromName).toEqual(defaultFromName)
expect(initializedEmail.defaultFromAddress).toEqual(defaultFromAddress)
expect(initializedEmail.defaultFromName).toStrictEqual(defaultFromName)
expect(initializedEmail.defaultFromAddress).toStrictEqual(defaultFromAddress)
expect(createTransportSpy).toHaveBeenCalledWith(
expect.objectContaining({
@@ -158,17 +152,13 @@ describe('plugin', () => {
})
function assertCloudStorage(config: Config) {
expect(config.upload?.useTempFiles).toEqual(true)
expect(config.upload?.useTempFiles).toStrictEqual(true)
}
function assertNoCloudStorage(config: Config) {
expect(config.upload?.useTempFiles).toBeFalsy()
}
async function assertCloudEmail(config: Config) {
expect(config.email && 'name' in config.email).toStrictEqual('Nodemailer - SMTP')
}
function createConfig(overrides?: Partial<Config>): Config {
return {
...defaults,

View File

@@ -26,7 +26,8 @@ export const deleteFromSearch: CollectionAfterDeleteHook = async ({
}
} catch (err: unknown) {
payload.logger.error({
err: `Error deleting search doc: ${err}`,
err,
msg: `Error deleting search doc.`,
})
}

View File

@@ -141,7 +141,7 @@ export const syncWithSearch: SyncWithSearch = async (args) => {
req,
})
} catch (err: unknown) {
payload.logger.error(`Error deleting search document: ${err}`)
payload.logger.error({ err, msg: `Error deleting search document.` })
}
}
} else if (doSync) {
@@ -155,17 +155,18 @@ export const syncWithSearch: SyncWithSearch = async (args) => {
req,
})
} catch (err: unknown) {
payload.logger.error(`Error creating search document: ${err}`)
payload.logger.error({ err, msg: `Error creating search document.` })
}
}
} catch (err: unknown) {
payload.logger.error(`Error finding search document: ${err}`)
payload.logger.error({ err, msg: `Error finding search document.` })
}
}
} catch (err: unknown) {
payload.logger.error(
`Error syncing search document related to ${collection} with id: '${id}': ${err}`,
)
payload.logger.error({
err,
msg: `Error syncing search document related to ${collection} with id: '${id}'.`,
})
}
return doc

View File

@@ -1,32 +1,12 @@
'use client'
import type { FormState } from 'payload'
import { useConfig, useWatchForm } from '@payloadcms/ui'
import { useConfig } from '@payloadcms/ui'
import { formatAdminURL } from '@payloadcms/ui/shared'
import React from 'react'
// TODO: fix this import to work in dev mode within the monorepo in a way that is backwards compatible with 1.x
// import CopyToClipboard from 'payload/dist/admin/components/elements/CopyToClipboard'
type FieldsWithDoc = {
doc: {
value: {
relationTo: string
value: string
}
}
} & FormState
export const LinkToDocClient: React.FC = () => {
const form = useWatchForm()
const fields = form.fields as FieldsWithDoc
const {
doc: {
value: { relationTo, value: docId },
},
} = fields
const { config } = useConfig()
const {