Feat: AI moderation report compatibility - #419
Conversation
| resolved: z.boolean(), | ||
| createdAt: z.string(), | ||
| updatedAt: z.string().nullable(), | ||
| source: z.enum(['USER', 'AI']).nullish(), |
There was a problem hiding this comment.
| source: z.enum(['USER', 'AI']).nullish(), | |
| source: originSource.nullish(), |
So you don't repeat yourself.
Not super conviced about source name. But don't have better name.
| type CustomInjectionZoneCellProps = { | ||
| area: `${string}.${string}.${string}`; | ||
| as: 'th' | 'td'; | ||
| [key: string]: unknown; | ||
| }; |
There was a problem hiding this comment.
| type CustomInjectionZoneCellProps = { | |
| area: `${string}.${string}.${string}`; | |
| as: 'th' | 'td'; | |
| [key: string]: unknown; | |
| }; | |
| type CustomInjectionZoneCellProps = { | |
| area: `${string}.${string}.${string}`; | |
| as: 'th' | 'td'; | |
| } & Record<string, unknown>; |
|
|
||
| type ProviderComponentProps = { | ||
| children: ReactNode; | ||
| [key: string]: unknown; |
There was a problem hiding this comment.
Same as above. To split visually known from the rest.
| } | ||
|
|
||
| return components.reduceRight((acc, { name, Component }) => { | ||
| const Provider = Component as ComponentType<ProviderComponentProps>; |
There was a problem hiding this comment.
I'd probably at least made a TS guard to check if it is a function or a class. Typecast are too much confidence in one spot. IMO.
| {reportByAi && <ReportReasonBadge reason={report.source} />} | ||
| <ReportReasonBadge reason={report.reason} /> |
There was a problem hiding this comment.
This if operation defeats the purpose of the reason or source I don't know which. ReportReasonBadge's logic is kind of leaky that it maps reason (key?) to a variant. If report was by AI, then I'll just inline "other", "AI" or something. And I would handle it in translation. In this case component is repurposed but put in a detached context. I would refactor the component into two components with base one. Or just made a "AI" badge, or "BOT" badge.
What you have now will work, but it is hacky.
| @@ -0,0 +1,4 @@ | |||
| export enum REPORT_SOURCE { | |||
There was a problem hiding this comment.
enums are kind of passé
| } from './utils/reactions'; | ||
| import type { ContentType, LifeCycleEvent, LifeCycleHookName } from '../utils/types'; | ||
|
|
||
| type Effect<T> = (event: T) => void | Promise<void>; |
There was a problem hiding this comment.
| type Effect<T> = (event: T) => void | Promise<void>; | |
| type Effect<T = void> = [T] extends [void] ? () => void | Promise<void> : (event: T) => void | Promise<void>; |
It will make it more flexible. And if you want no-params effect you can have it too.
| publishedAt: z.string().nullable(), | ||
| locale: z.string().nullable(), | ||
| related: relatedSchema.nullable().optional(), | ||
| source: z.enum(['USER', 'AI']).nullish(), |
There was a problem hiding this comment.
it's duplicated here also
Summary
For integration with the Comments Enterprise plugin, the report table got a separate column describing the report source. Additionally, lifecycle methods have been added to trigger actions after adding a comment, and injection zones have been implemented.