chore(plugin-seo): enable TypeScript strict (#11933)
This commit is contained in:
@@ -58,15 +58,12 @@ export const MetaDescriptionComponent: React.FC<MetaDescriptionProps> = (props)
|
||||
const maxLength = maxLengthFromProps || maxLengthDefault
|
||||
const minLength = minLengthFromProps || minLengthDefault
|
||||
|
||||
const {
|
||||
customComponents: { AfterInput, BeforeInput, Label },
|
||||
errorMessage,
|
||||
setValue,
|
||||
showError,
|
||||
value,
|
||||
}: FieldType<string> = useField({
|
||||
path,
|
||||
} as Options)
|
||||
const { customComponents, errorMessage, setValue, showError, value }: FieldType<string> =
|
||||
useField({
|
||||
path,
|
||||
} as Options)
|
||||
|
||||
const { AfterInput, BeforeInput, Label } = customComponents ?? {}
|
||||
|
||||
const regenerateDescription = useCallback(async () => {
|
||||
if (!hasGenerateDescriptionFn) {
|
||||
@@ -85,7 +82,7 @@ export const MetaDescriptionComponent: React.FC<MetaDescriptionProps> = (props)
|
||||
hasPublishPermission: docInfo.hasPublishPermission,
|
||||
hasSavePermission: docInfo.hasSavePermission,
|
||||
initialData: docInfo.initialData,
|
||||
initialState: reduceToSerializableFields(docInfo.initialState),
|
||||
initialState: reduceToSerializableFields(docInfo.initialState ?? {}),
|
||||
locale: typeof locale === 'object' ? locale?.code : locale,
|
||||
title: docInfo.title,
|
||||
} satisfies Omit<
|
||||
|
||||
@@ -25,6 +25,6 @@ export const MetaDescriptionField: FieldFunction = ({ hasGenerateFn = false, ove
|
||||
},
|
||||
},
|
||||
localized: true,
|
||||
...((overrides as unknown as TextareaField) ?? {}),
|
||||
...(overrides ?? {}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ export const MetaImageComponent: React.FC<MetaImageProps> = (props) => {
|
||||
} = useConfig()
|
||||
|
||||
const field: FieldType<string> = useField({ ...props, path } as Options)
|
||||
const {
|
||||
customComponents: { Error, Label },
|
||||
} = field
|
||||
const { customComponents } = field
|
||||
|
||||
const { Error, Label } = customComponents ?? {}
|
||||
|
||||
const { t } = useTranslation<PluginSEOTranslations, PluginSEOTranslationKeys>()
|
||||
|
||||
@@ -72,7 +72,7 @@ export const MetaImageComponent: React.FC<MetaImageProps> = (props) => {
|
||||
hasPublishPermission: docInfo.hasPublishPermission,
|
||||
hasSavePermission: docInfo.hasSavePermission,
|
||||
initialData: docInfo.initialData,
|
||||
initialState: reduceToSerializableFields(docInfo.initialState),
|
||||
initialState: reduceToSerializableFields(docInfo.initialState ?? {}),
|
||||
locale: typeof locale === 'object' ? locale?.code : locale,
|
||||
title: docInfo.title,
|
||||
} satisfies Omit<
|
||||
|
||||
@@ -29,6 +29,6 @@ export const MetaImageField: FieldFunction = ({ hasGenerateFn = false, overrides
|
||||
label: 'Meta Image',
|
||||
localized: true,
|
||||
relationTo,
|
||||
...((overrides as unknown as UploadField) ?? {}),
|
||||
...((overrides ?? {}) as { hasMany: boolean } & Partial<UploadField>),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export const MetaTitleComponent: React.FC<MetaTitleProps> = (props) => {
|
||||
hasPublishPermission: docInfo.hasPublishPermission,
|
||||
hasSavePermission: docInfo.hasSavePermission,
|
||||
initialData: docInfo.initialData,
|
||||
initialState: reduceToSerializableFields(docInfo.initialState),
|
||||
initialState: reduceToSerializableFields(docInfo.initialState ?? {}),
|
||||
locale: typeof locale === 'object' ? locale?.code : locale,
|
||||
title: docInfo.title,
|
||||
} satisfies Omit<
|
||||
|
||||
@@ -25,6 +25,6 @@ export const MetaTitleField: FieldFunction = ({ hasGenerateFn = false, overrides
|
||||
},
|
||||
},
|
||||
localized: true,
|
||||
...((overrides as unknown as TextField) ?? {}),
|
||||
...((overrides ?? {}) as { hasMany: boolean } & Partial<TextField>),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,15 +59,6 @@ export const OverviewComponent: React.FC<OverviewProps> = ({
|
||||
const minTitle = titleOverrides?.minLength || minTitleDefault
|
||||
const maxTitle = titleOverrides?.maxLength || maxTitleDefault
|
||||
|
||||
const resetAll = useCallback(() => {
|
||||
const fields = getFields()
|
||||
const fieldsWithoutMeta = fields
|
||||
fieldsWithoutMeta['meta.title'].value = ''
|
||||
fieldsWithoutMeta['meta.description'].value = ''
|
||||
fieldsWithoutMeta['meta.image'].value = ''
|
||||
// dispatchFields(fieldsWithoutMeta);
|
||||
}, [getFields])
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof metaTitle === 'string') {
|
||||
setTitleIsValid(metaTitle.length >= minTitle && metaTitle.length <= maxTitle)
|
||||
|
||||
@@ -58,6 +58,6 @@ export const OverviewField: FieldFunction = ({
|
||||
},
|
||||
},
|
||||
label: 'Overview',
|
||||
...((overrides as unknown as UIField) ?? {}),
|
||||
...(overrides ?? {}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export const PreviewComponent: React.FC<PreviewProps> = (props) => {
|
||||
hasPublishPermission: docInfo.hasPublishPermission,
|
||||
hasSavePermission: docInfo.hasSavePermission,
|
||||
initialData: docInfo.initialData,
|
||||
initialState: reduceToSerializableFields(docInfo.initialState),
|
||||
initialState: reduceToSerializableFields(docInfo.initialState ?? {}),
|
||||
locale: typeof locale === 'object' ? locale?.code : locale,
|
||||
title: docInfo.title,
|
||||
} satisfies Omit<
|
||||
|
||||
@@ -44,6 +44,6 @@ export const PreviewField: FieldFunction = ({
|
||||
},
|
||||
},
|
||||
label: 'Preview',
|
||||
...((overrides as unknown as UIField) ?? {}),
|
||||
...(overrides ?? {}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ export const seoPlugin =
|
||||
if (pluginConfig?.tabbedUI) {
|
||||
// prevent issues with auth enabled collections having an email field that shouldn't be moved to the SEO tab
|
||||
const emailField =
|
||||
(collection.auth ||
|
||||
!(typeof collection.auth === 'object' && collection.auth.disableLocalStrategy)) &&
|
||||
collection.auth &&
|
||||
!(typeof collection.auth === 'object' && collection.auth.disableLocalStrategy) &&
|
||||
collection.fields?.find((field) => 'name' in field && field.name === 'email')
|
||||
const hasOnlyEmailField = collection.fields?.length === 1 && emailField
|
||||
|
||||
@@ -137,21 +137,17 @@ export const seoPlugin =
|
||||
const data: Omit<
|
||||
Parameters<GenerateTitle>[0],
|
||||
'collectionConfig' | 'globalConfig' | 'req'
|
||||
> = await req.json()
|
||||
> = await req.json?.()
|
||||
|
||||
if (data) {
|
||||
req.data = data
|
||||
}
|
||||
const reqData = data ?? req.data
|
||||
|
||||
const result = pluginConfig.generateTitle
|
||||
? await pluginConfig.generateTitle({
|
||||
...data,
|
||||
collectionConfig: req.data.collectionSlug
|
||||
? config.collections?.find((c) => c.slug === req.data.collectionSlug)
|
||||
: null,
|
||||
globalConfig: req.data.globalSlug
|
||||
? config.globals?.find((g) => g.slug === req.data.globalSlug)
|
||||
: null,
|
||||
collectionConfig: config.collections?.find(
|
||||
(c) => c.slug === reqData.collectionSlug,
|
||||
),
|
||||
globalConfig: config.globals?.find((g) => g.slug === reqData.globalSlug),
|
||||
req,
|
||||
} satisfies Parameters<GenerateTitle>[0])
|
||||
: ''
|
||||
@@ -165,21 +161,17 @@ export const seoPlugin =
|
||||
const data: Omit<
|
||||
Parameters<GenerateTitle>[0],
|
||||
'collectionConfig' | 'globalConfig' | 'req'
|
||||
> = await req.json()
|
||||
> = await req.json?.()
|
||||
|
||||
if (data) {
|
||||
req.data = data
|
||||
}
|
||||
const reqData = data ?? req.data
|
||||
|
||||
const result = pluginConfig.generateDescription
|
||||
? await pluginConfig.generateDescription({
|
||||
...data,
|
||||
collectionConfig: req.data.collectionSlug
|
||||
? config.collections?.find((c) => c.slug === req.data.collectionSlug)
|
||||
: null,
|
||||
globalConfig: req.data.globalSlug
|
||||
? config.globals?.find((g) => g.slug === req.data.globalSlug)
|
||||
: null,
|
||||
collectionConfig: config.collections?.find(
|
||||
(c) => c.slug === reqData.collectionSlug,
|
||||
),
|
||||
globalConfig: config.globals?.find((g) => g.slug === reqData.globalSlug),
|
||||
req,
|
||||
} satisfies Parameters<GenerateDescription>[0])
|
||||
: ''
|
||||
@@ -193,21 +185,17 @@ export const seoPlugin =
|
||||
const data: Omit<
|
||||
Parameters<GenerateTitle>[0],
|
||||
'collectionConfig' | 'globalConfig' | 'req'
|
||||
> = await req.json()
|
||||
> = await req.json?.()
|
||||
|
||||
if (data) {
|
||||
req.data = data
|
||||
}
|
||||
const reqData = data ?? req.data
|
||||
|
||||
const result = pluginConfig.generateURL
|
||||
? await pluginConfig.generateURL({
|
||||
...data,
|
||||
collectionConfig: req.data.collectionSlug
|
||||
? config.collections?.find((c) => c.slug === req.data.collectionSlug)
|
||||
: null,
|
||||
globalConfig: req.data.globalSlug
|
||||
? config.globals?.find((g) => g.slug === req.data.globalSlug)
|
||||
: null,
|
||||
collectionConfig: config.collections?.find(
|
||||
(c) => c.slug === reqData.collectionSlug,
|
||||
),
|
||||
globalConfig: config.globals?.find((g) => g.slug === reqData.globalSlug),
|
||||
req,
|
||||
} satisfies Parameters<GenerateURL>[0])
|
||||
: ''
|
||||
@@ -221,25 +209,21 @@ export const seoPlugin =
|
||||
const data: Omit<
|
||||
Parameters<GenerateTitle>[0],
|
||||
'collectionConfig' | 'globalConfig' | 'req'
|
||||
> = await req.json()
|
||||
> = await req.json?.()
|
||||
|
||||
if (data) {
|
||||
req.data = data
|
||||
}
|
||||
const reqData = data ?? req.data
|
||||
|
||||
const result = pluginConfig.generateImage
|
||||
? await pluginConfig.generateImage({
|
||||
...data,
|
||||
collectionConfig: req.data.collectionSlug
|
||||
? config.collections?.find((c) => c.slug === req.data.collectionSlug)
|
||||
: null,
|
||||
globalConfig: req.data.globalSlug
|
||||
? config.globals?.find((g) => g.slug === req.data.globalSlug)
|
||||
: null,
|
||||
collectionConfig: config.collections?.find(
|
||||
(c) => c.slug === reqData.collectionSlug,
|
||||
),
|
||||
globalConfig: config.globals?.find((g) => g.slug === reqData.globalSlug),
|
||||
req,
|
||||
} as Parameters<GenerateImage>[0])
|
||||
} satisfies Parameters<GenerateImage>[0])
|
||||
: ''
|
||||
return new Response(result, { status: 200 })
|
||||
return new Response(JSON.stringify({ result }), { status: 200 })
|
||||
},
|
||||
method: 'post',
|
||||
path: '/plugin-seo/generate-image',
|
||||
@@ -258,7 +242,7 @@ export const seoPlugin =
|
||||
tabs: [
|
||||
// append a new tab onto the end of the tabs array, if there is one at the first index
|
||||
// if needed, create a new `Content` tab in the first index for this global's base fields
|
||||
...(global?.fields?.[0].type === 'tabs' && global?.fields?.[0].tabs
|
||||
...(global?.fields?.[0]?.type === 'tabs' && global?.fields?.[0].tabs
|
||||
? global.fields[0].tabs
|
||||
: [
|
||||
{
|
||||
@@ -278,7 +262,7 @@ export const seoPlugin =
|
||||
...global,
|
||||
fields: [
|
||||
...seoTabs,
|
||||
...(global?.fields?.[0].type === 'tabs' ? global.fields.slice(1) : []),
|
||||
...(global?.fields?.[0]?.type === 'tabs' ? global.fields.slice(1) : []),
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -293,7 +277,7 @@ export const seoPlugin =
|
||||
}) || [],
|
||||
i18n: {
|
||||
...config.i18n,
|
||||
translations: deepMergeSimple(translations, config.i18n?.translations),
|
||||
translations: deepMergeSimple(translations, config.i18n?.translations ?? {}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
/* TODO: remove the following lines */
|
||||
"strict": false,
|
||||
},
|
||||
"references": [{ "path": "../payload" }, { "path": "../ui" }, { "path": "../next" }]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user