etr2460 commented on a change in pull request #10426:
URL:
https://github.com/apache/incubator-superset/pull/10426#discussion_r460639544
##########
File path: superset-frontend/src/components/Menu/MenuObject.tsx
##########
@@ -17,20 +17,29 @@
* under the License.
*/
import React from 'react';
-import PropTypes from 'prop-types';
import { NavItem, NavDropdown, MenuItem } from 'react-bootstrap';
-const propTypes = {
- label: PropTypes.string.isRequired,
- icon: PropTypes.string.isRequired,
- index: PropTypes.number.isRequired,
- url: PropTypes.string,
- childs: PropTypes.arrayOf(
- PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
- ),
-};
+export interface MenuObjectChildProps {
+ label: string;
+ icon: string;
+ index: number;
+ url?: string;
+}
+export interface MenuObjectProps {
+ label?: string;
+ icon?: string;
+ index: number;
+ url?: string;
+ childs?: (MenuObjectChildProps | string)[];
Review comment:
ah I see. I think this is fine as is then
##########
File path: superset-frontend/src/components/Menu/MenuObject.tsx
##########
@@ -51,22 +61,20 @@ export default function MenuObject({ label, icon, childs,
url, index }) {
eventKey={index}
title={navTitle}
>
- {childs.map((child, index1) =>
- child === '-' ? (
+ {childs?.map((child: MenuObjectChildProps | string, index1: number) =>
+ typeof child === 'string' && child === '-' ? (
<MenuItem key={`$${index1}`} divider />
) : (
<MenuItem
- key={`${child.label}`}
- href={child.url}
+ key={`${(child as MenuObjectChildProps).label}`}
+ href={(child as MenuObjectChildProps).url}
eventKey={parseFloat(`${index}.${index1}`)}
>
- <i className={`fa ${child.icon}`} />
- {child.label}
+ <i className={`fa ${(child as MenuObjectChildProps).icon}`} />
+ {(child as MenuObjectChildProps).label}
Review comment:
Gotcha. I think the typing is correct above as is (and if it's not, then
we can always improve it in the future)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]