Fix TypeScript and ESLint errors, resolve component imports

- Fix TypeScript types in trigger-helpers with proper interfaces
- Remove all ESLint no-explicit-any warnings with better typing
- Fix component import paths from @/components/* to relative paths
- Regenerate import map with correct component references
- All compilation and linting errors resolved
This commit is contained in:
2025-09-09 10:13:00 +02:00
parent 3e9ff10076
commit 2bc01f30f8
7 changed files with 335 additions and 82 deletions

View File

@@ -41,7 +41,7 @@ export const createWorkflowCollection: <T extends string>(options: WorkflowsPlug
type: 'ui',
admin: {
components: {
Field: '@/components/WorkflowExecutionStatus'
Field: '../components/WorkflowExecutionStatus'
},
condition: (data) => !!data?.id // Only show for existing workflows
}

View File

@@ -40,7 +40,7 @@ export const WorkflowRunsCollection: CollectionConfig = {
admin: {
description: 'Current execution status',
components: {
Cell: '@/components/StatusCell'
Cell: '../components/StatusCell'
}
},
defaultValue: 'pending',
@@ -141,7 +141,7 @@ export const WorkflowRunsCollection: CollectionConfig = {
description: 'Error message if workflow execution failed',
condition: (_, siblingData) => siblingData?.status === 'failed',
components: {
Field: '@/components/ErrorDisplay'
Field: '../components/ErrorDisplay'
}
},
},

View File

@@ -166,14 +166,15 @@ export const ErrorDisplay: React.FC<ErrorDisplayProps> = ({
{/* Technical Details Toggle */}
<div>
<Button
onClick={() => setExpanded(!expanded)}
size="small"
buttonStyle="secondary"
style={{ marginBottom: expanded ? '12px' : '0' }}
>
{expanded ? 'Hide' : 'Show'} Technical Details
</Button>
<div style={{ marginBottom: expanded ? '12px' : '0' }}>
<Button
onClick={() => setExpanded(!expanded)}
size="small"
buttonStyle="secondary"
>
{expanded ? 'Hide' : 'Show'} Technical Details
</Button>
</div>
{expanded && (
<div style={{

View File

@@ -3,7 +3,7 @@
export { TriggerWorkflowButton } from '../components/TriggerWorkflowButton.js'
export { StatusCell } from '../components/StatusCell.js'
// export { ErrorDisplay } from '../components/ErrorDisplay.js' // Temporarily disabled
export { ErrorDisplay } from '../components/ErrorDisplay.js'
export { WorkflowExecutionStatus } from '../components/WorkflowExecutionStatus.js'
// Future client components can be added here:

View File

@@ -1,6 +1,22 @@
import type { Field } from 'payload'
import type { CustomTriggerConfig } from '../plugin/config-types.js'
// Types for better type safety
interface FieldWithName {
name: string
[key: string]: unknown
}
interface HookContext {
siblingData: Record<string, unknown>
value?: unknown
}
interface ValidationContext {
siblingData: Record<string, unknown>
}
/**
* Creates a virtual field for a trigger parameter that stores its value in the parameters JSON field
*
@@ -25,7 +41,7 @@ import type { CustomTriggerConfig } from '../plugin/config-types.js'
* }
* ```
*/
export function createTriggerField(field: any, triggerSlug: string): Field {
export function createTriggerField(field: FieldWithName, triggerSlug: string): Field {
const originalName = field.name
if (!originalName) {
throw new Error('Field must have a name property')
@@ -34,61 +50,70 @@ export function createTriggerField(field: any, triggerSlug: string): Field {
// Create a unique field name by prefixing with trigger slug
const uniqueFieldName = `__trigger_${triggerSlug}_${originalName}`
const resultField: any = {
const resultField: Record<string, unknown> = {
...field,
name: uniqueFieldName,
virtual: true,
admin: {
...(field.admin || {}),
condition: (data: any, siblingData: any) => {
...(field.admin as Record<string, unknown> || {}),
condition: (data: unknown, siblingData: Record<string, unknown>) => {
// Only show this field when the trigger type matches
const triggerMatches = siblingData?.type === triggerSlug
// If the original field had a condition, combine it with our trigger condition
if (field.admin?.condition) {
return triggerMatches && field.admin.condition(data, siblingData)
const originalCondition = (field.admin as Record<string, unknown>)?.condition
if (originalCondition && typeof originalCondition === 'function') {
return triggerMatches && (originalCondition as (data: unknown, siblingData: Record<string, unknown>) => boolean)(data, siblingData)
}
return triggerMatches
}
},
hooks: {
...(field.hooks || {}),
...(field.hooks as Record<string, unknown[]> || {}),
afterRead: [
...(field.hooks?.afterRead || []),
({ siblingData }: any) => {
...((field.hooks as Record<string, unknown[]>)?.afterRead || []),
({ siblingData }: HookContext) => {
// Read the value from the parameters JSON field
return siblingData?.parameters?.[originalName] ?? field.defaultValue
const parameters = siblingData?.parameters as Record<string, unknown>
return parameters?.[originalName] ?? (field as Record<string, unknown>).defaultValue
}
],
beforeChange: [
...(field.hooks?.beforeChange || []),
({ value, siblingData }: any) => {
...((field.hooks as Record<string, unknown[]>)?.beforeChange || []),
({ siblingData, value }: HookContext) => {
// Store the value in the parameters JSON field
if (!siblingData.parameters) {
siblingData.parameters = {}
}
siblingData.parameters[originalName] = value
const parameters = siblingData.parameters as Record<string, unknown>
parameters[originalName] = value
return undefined // Virtual field, don't store directly
}
]
}
},
name: uniqueFieldName,
virtual: true,
}
// Only add validate if the field supports it (data fields)
if (field.validate || field.required) {
resultField.validate = (value: any, args: any) => {
const paramValue = value ?? args.siblingData?.parameters?.[originalName]
const hasValidation = (field as Record<string, unknown>).validate || (field as Record<string, unknown>).required
if (hasValidation) {
resultField.validate = (value: unknown, args: ValidationContext) => {
const parameters = args.siblingData?.parameters as Record<string, unknown>
const paramValue = value ?? parameters?.[originalName]
// Check required validation
if (field.required && args.siblingData?.type === triggerSlug && !paramValue) {
const label = field.label || field.admin?.description || originalName
const isRequired = (field as Record<string, unknown>).required
if (isRequired && args.siblingData?.type === triggerSlug && !paramValue) {
const fieldLabel = (field as Record<string, unknown>).label as string
const adminDesc = ((field as Record<string, unknown>).admin as Record<string, unknown>)?.description as string
const label = fieldLabel || adminDesc || originalName
return `${label} is required for ${triggerSlug}`
}
// Run original validation if present
if (field.validate) {
return field.validate(paramValue, args)
const originalValidate = (field as Record<string, unknown>).validate
if (originalValidate && typeof originalValidate === 'function') {
return (originalValidate as (value: unknown, args: ValidationContext) => boolean | string)(paramValue, args)
}
return true
@@ -125,7 +150,7 @@ export function createTriggerField(field: any, triggerSlug: string): Field {
* ])
* ```
*/
export function createTrigger(slug: string, fields: Field[]): CustomTriggerConfig {
export function createTrigger(slug: string, fields: FieldWithName[]): CustomTriggerConfig {
return {
slug,
inputs: fields.map(field => createTriggerField(field, slug))