diff --git a/striker-ui/components/GeneralInitForm.tsx b/striker-ui/components/GeneralInitForm.tsx index 96479748..ec07bcff 100644 --- a/striker-ui/components/GeneralInitForm.tsx +++ b/striker-ui/components/GeneralInitForm.tsx @@ -780,7 +780,11 @@ const GeneralInitForm = forwardRef< - + {helpMessage && ( { diff --git a/striker-ui/components/MessageGroup.tsx b/striker-ui/components/MessageGroup.tsx index c6e8fe38..af196207 100644 --- a/striker-ui/components/MessageGroup.tsx +++ b/striker-ui/components/MessageGroup.tsx @@ -1,5 +1,6 @@ import { forwardRef, + ReactNode, useCallback, useImperativeHandle, useMemo, @@ -13,6 +14,7 @@ type Messages = { }; type MessageGroupOptionalProps = { + count?: number; defaultMessageType?: MessageBoxProps['type']; }; @@ -25,6 +27,7 @@ type MessageGroupForwardedRefContent = { }; const MESSAGE_GROUP_DEFAULT_PROPS: Required = { + count: 0, defaultMessageType: 'info', }; @@ -33,7 +36,10 @@ const MessageGroup = forwardRef< MessageGroupProps >( ( - { defaultMessageType = MESSAGE_GROUP_DEFAULT_PROPS.defaultMessageType }, + { + count = MESSAGE_GROUP_DEFAULT_PROPS.count, + defaultMessageType = MESSAGE_GROUP_DEFAULT_PROPS.defaultMessageType, + }, ref, ) => { const [messages, setMessages] = useState({}); @@ -65,26 +71,39 @@ const MessageGroup = forwardRef< }); }, []); - const messageElements = useMemo( - () => - Object.entries(messages).map(([messageKey, message]) => { - let messageElement; - - if (message) { - const { children: messageChildren, type = defaultMessageType } = - message; - - messageElement = ( - - {messageChildren} - - ); - } + const messageElements = useMemo(() => { + const pairs = Object.entries(messages); + const isValidCount = count > 0; + const limit = isValidCount ? count : pairs.length; + const result: ReactNode[] = []; + + pairs.every(([messageKey, message]) => { + if (message) { + const { children: messageChildren, type = defaultMessageType } = + message; + + result.push( + + {messageChildren} + , + ); + } + + return result.length < limit; + }); - return messageElement; - }), - [defaultMessageType, messages], - ); + if (isValidCount && result.length === 0) { + result.push( + , + ); + } + + return result; + }, [count, defaultMessageType, messages]); useImperativeHandle(ref, () => ({ exists, setMessage, setMessageRe }), [ exists, diff --git a/striker-ui/components/NetworkInitForm.tsx b/striker-ui/components/NetworkInitForm.tsx index c26f2ca9..b4a2edd8 100644 --- a/striker-ui/components/NetworkInitForm.tsx +++ b/striker-ui/components/NetworkInitForm.tsx @@ -1237,7 +1237,11 @@ const NetworkInitForm = forwardRef< ref={dnsCSVInputRef} /> - + );