From b33065deee1a5496391fcbc0fc1291432537d5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Thu, 4 Apr 2024 15:37:26 +0100 Subject: [PATCH 01/13] web: Fix Popup types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Díaz González --- web/src/components/core/Popup.jsx | 63 ++++++++++++++----------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/web/src/components/core/Popup.jsx b/web/src/components/core/Popup.jsx index 78cdca2e8b..4c60cc01b0 100644 --- a/web/src/components/core/Popup.jsx +++ b/web/src/components/core/Popup.jsx @@ -19,12 +19,19 @@ * find current contact information at www.suse.com. */ +// @ts-check + import React from "react"; import { Button, Modal } from "@patternfly/react-core"; - import { _ } from "~/i18n"; import { partition } from "~/utils"; +/** + * @typedef {import("@patternfly/react-core").ModalProps} ModalProps + * @typedef {import("@patternfly/react-core").ButtonProps} ButtonProps + * @typedef {Omit} ButtonWithoutVariantProps + */ + /** * Wrapper component for holding Popup actions * @@ -33,6 +40,7 @@ import { partition } from "~/utils"; * * @see Popup examples. * + * @param {object} props * @param {React.ReactNode} [props.children] - a collection of Action components */ const Actions = ({ children }) => <>{children}; @@ -42,13 +50,10 @@ const Actions = ({ children }) => <>{children}; * * Built on top of {@link https://www.patternfly.org/components/button PF/Button} * - * @see Popup examples. - * - * @param {React.ReactNode} props.children - content of the action - * @param {object} [props] - PF/Button props, see {@link https://www.patternfly.org/components/button#props} + * @param {ButtonProps} props */ -const Action = ({ children, ...props }) => ( - ); @@ -68,11 +73,10 @@ const Action = ({ children, ...props }) => ( * Upload * * - * @param {React.ReactNode} props.children - content of the action - * @param {object} [props] - {@link Action} props + * @param {ButtonWithoutVariantProps} props */ -const PrimaryAction = ({ children, ...props }) => ( - { children } +const PrimaryAction = ({ children, ...actionProps }) => ( + { children } ); /** @@ -84,11 +88,10 @@ const PrimaryAction = ({ children, ...props }) => ( * @example Using it with a custom text * Accept * - * @param {React.ReactNode} [props.children="confirm"] - content of the action - * @param {object} [props] - {@link Action} props + * @param {ButtonWithoutVariantProps} props */ -const Confirm = ({ children = _("Confirm"), ...props }) => ( - { children } +const Confirm = ({ children = _("Confirm"), ...actionProps }) => ( + { children } ); /** @@ -106,11 +109,10 @@ const Confirm = ({ children = _("Confirm"), ...props }) => ( * Dismiss * * - * @param {React.ReactNode} props.children - content of the action - * @param {object} [props] - {@link Action} props + * @param {ButtonWithoutVariantProps} props */ -const SecondaryAction = ({ children, ...props }) => ( - { children } +const SecondaryAction = ({ children, ...actionProps }) => ( + { children } ); /** @@ -122,11 +124,10 @@ const SecondaryAction = ({ children, ...props }) => ( * @example Using it with a custom text * Dismiss * - * @param {React.ReactNode} [props.children="Cancel"] - content of the action - * @param {object} [props] - {@link Action} props + * @param {ButtonWithoutVariantProps} props */ -const Cancel = ({ children = _("Cancel"), ...props }) => ( - { children } +const Cancel = ({ children = _("Cancel"), ...actionProps }) => ( + { children } ); /** @@ -144,11 +145,10 @@ const Cancel = ({ children = _("Cancel"), ...props }) => ( * Do not set * * - * @param {React.ReactNode} props.children - content of the action - * @param {object} [props] - {@link Action} props + * @param {ButtonWithoutVariantProps} props */ -const AncillaryAction = ({ children, ...props }) => ( - { children } +const AncillaryAction = ({ children, ...actionsProps }) => ( + { children } ); /** @@ -187,13 +187,7 @@ const AncillaryAction = ({ children, ...props }) => ( * * * - * @param {object} props - component props - * @param {boolean} [props.isOpen=false] - whether the popup is displayed or not - * @param {boolean} [props.showClose=false] - whether the popup should include a "X" action for closing it - * @param {string} [props.variant="small"] - the popup size, based on PF/Modal `variant` prop - * @param {React.ReactNode} props.children - the popup content and actions - * @param {object} [pfModalProps] - PF/Modal props, See {@link https://www.patternfly.org/components/modal#props} - * + * @param {ModalProps} props */ const Popup = ({ isOpen = false, @@ -205,6 +199,7 @@ const Popup = ({ const [actions, content] = partition(React.Children.toArray(children), child => child.type === Actions); return ( + /** @ts-ignore */ Date: Thu, 4 Apr 2024 15:38:02 +0100 Subject: [PATCH 02/13] web: Fix Section types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Díaz González --- web/src/components/core/Section.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/core/Section.jsx b/web/src/components/core/Section.jsx index c1954b7d4e..831d5f792d 100644 --- a/web/src/components/core/Section.jsx +++ b/web/src/components/core/Section.jsx @@ -56,7 +56,7 @@ import { If, ValidationErrors } from "~/components/core"; * @property {string} [className] - Class name for section html tag. * @property {string} [id] - Id of the section ("software", "product", "storage", "storage-actions", ...) * @property {import("~/client/mixins").ValidationError[]} [props.errors] - Validation errors to be shown before the title. - * @property {React.ReactElement} [children] - The section content. + * @property {React.ReactNode} [children] - The section content. * @property {string} [aria-label] - aria-label attribute, required if title if not given * * @param { SectionProps } props From b858e91f4ec67bf96de675ebe11ddea94e14bfa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Thu, 4 Apr 2024 15:39:10 +0100 Subject: [PATCH 03/13] web: Fix OptionsPicker types --- web/src/components/core/OptionsPicker.jsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/src/components/core/OptionsPicker.jsx b/web/src/components/core/OptionsPicker.jsx index 55cc44f850..eb1d96f011 100644 --- a/web/src/components/core/OptionsPicker.jsx +++ b/web/src/components/core/OptionsPicker.jsx @@ -19,8 +19,12 @@ * find current contact information at www.suse.com. */ +// @ts-check + import React from "react"; +import { noop } from "~/utils"; + /** * Wrapper for OptionsPicker options * @component @@ -29,12 +33,14 @@ import React from "react"; * @param {string} [props.title] - Text to be used as option title * @param {string} [props.body] - Text to be used as option body * @param {boolean} [props.isSelected=false] - Whether the option should be set as select of not + * @param {() => void} [props.onClick=noop] * @param {object} [props.props] - Other props sent to div#option node */ -const Option = ({ title, body, isSelected = false, ...props }) => { +const Option = ({ title, body, isSelected = false, onClick = noop, ...props }) => { return (
@@ -50,10 +56,10 @@ const Option = ({ title, body, isSelected = false, ...props }) => { * * @param {object} props * @param {string} [props.ariaLabel] - Text to be used as accessible label - * @param {Array