Skip to content

Commit 7d37d68

Browse files
committed
Add props schema
1 parent 4739c47 commit 7d37d68

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

packages/fluent-theme/src/components/activity/PartGroupingDecorator.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
import { getOrgSchemaMessage, type WebChatActivity } from 'botframework-webchat-core';
1+
import { reactNode, validateProps } from '@msinternal/botframework-webchat-react-valibot';
22
import { PartGrouping } from 'botframework-webchat-component/internal';
3+
import { getOrgSchemaMessage, type WebChatActivity } from 'botframework-webchat-core';
34
import cx from 'classnames';
4-
import React, { memo, useMemo } from 'react';
5+
import React, { memo, useMemo, type ReactNode } from 'react';
6+
import { array, custom, object, optional, pipe, readonly, safeParse } from 'valibot';
57

6-
import CopilotMessageHeader from './CopilotMessageHeader';
78
import useVariants from '../../private/useVariants';
89
import { useStyles, useVariantClassName } from '../../styles';
10+
import CopilotMessageHeader from './CopilotMessageHeader';
911

1012
import styles from './PartGroupingDecorator.module.css';
1113

12-
type PartGroupingDecoratorProps = Readonly<{
13-
activities: readonly WebChatActivity[];
14-
children?: React.ReactNode;
15-
}>;
14+
const partGroupingDecoratorPropsSchema = pipe(
15+
object({
16+
activities: pipe(array(custom<WebChatActivity>(value => safeParse(object({}), value).success)), readonly()),
17+
children: optional(reactNode())
18+
}),
19+
readonly()
20+
);
21+
22+
// TODO: [P2] InferInput does not add the required readonly, need to have a better way to define props.
23+
type PartGroupingDecoratorProps = {
24+
readonly activities: readonly WebChatActivity[];
25+
readonly children?: ReactNode | undefined;
26+
};
1627

1728
function PartGroupingDecorator(props: PartGroupingDecoratorProps) {
1829
const {
1930
activities: [activity, ...restActivities]
20-
} = props;
31+
} = validateProps(partGroupingDecoratorPropsSchema, props);
32+
2133
const variants = useVariants();
2234
const classNames = useStyles(styles);
2335
const variantClassName = useVariantClassName(styles);

0 commit comments

Comments
 (0)