From 2299061f20e0486c4c9c307f057c41b5ed81de10 Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:54:57 -0400 Subject: [PATCH] chore: upgrade v4 components to v5 in demo-app --- packages/demo-app-ts/src/App.tsx | 30 +- .../src/components/stylesComponentFactory.tsx | 2 +- .../src/utils/useTopologyOptions.tsx | 320 +++++++++++------- 3 files changed, 213 insertions(+), 139 deletions(-) diff --git a/packages/demo-app-ts/src/App.tsx b/packages/demo-app-ts/src/App.tsx index ab37386..ee3014a 100755 --- a/packages/demo-app-ts/src/App.tsx +++ b/packages/demo-app-ts/src/App.tsx @@ -10,25 +10,24 @@ import { Avatar, Brand, Radio, - Masthead, - MastheadMain, - MastheadToggle, - MastheadBrand, NavExpandable, PageSidebarBody, - MastheadContent, - PageToggleButton, Toolbar, - ToolbarContent, ToolbarGroup, - ToolbarItem + ToolbarItem, + Masthead, + MastheadToggle, + PageToggleButton, + MastheadContent, + MastheadBrand, + MastheadMain, + ToolbarContent } from '@patternfly/react-core'; +import { BarsIcon } from '@patternfly/react-icons/dist/esm/icons/bars-icon'; import imgBrand from './assets/images/imgBrand.svg'; import imgAvatar from './assets/images/imgAvatar.svg'; import Demos from './Demos'; import './App.css'; -import { BarsIcon } from '@patternfly/react-icons'; - interface AppState { activeItem: number | string; isNavOpen: boolean; @@ -153,13 +152,18 @@ class App extends React.Component<{}, AppState> { const AppHeader = ( - + this.setState({ isNavOpen: !isNavOpen })} + > - - + + {AppToolbar} diff --git a/packages/demo-app-ts/src/components/stylesComponentFactory.tsx b/packages/demo-app-ts/src/components/stylesComponentFactory.tsx index 084d0b9..30f77ee 100644 --- a/packages/demo-app-ts/src/components/stylesComponentFactory.tsx +++ b/packages/demo-app-ts/src/components/stylesComponentFactory.tsx @@ -53,7 +53,7 @@ const contextMenuItem = (label: string, i: number): React.ReactElement => { const createContextMenuItems = (...labels: string[]): React.ReactElement[] => labels.map(contextMenuItem); -const defaultMenu = createContextMenuItems('First', 'Second', 'Third', '-', 'Fourth'); +const defaultMenu = createContextMenuItems('First', 'Second', 'Third', '-', 'Sub Menu-> Child1, Child2, Child3, -, Child4'); const stylesComponentFactory: ComponentFactory = ( kind: ModelKind, diff --git a/packages/demo-app-ts/src/utils/useTopologyOptions.tsx b/packages/demo-app-ts/src/utils/useTopologyOptions.tsx index 7b3f36c..5a7a2be 100644 --- a/packages/demo-app-ts/src/utils/useTopologyOptions.tsx +++ b/packages/demo-app-ts/src/utils/useTopologyOptions.tsx @@ -1,31 +1,24 @@ import React from 'react'; import * as _ from 'lodash'; import { - Button, - Flex, - Split, - SplitItem, - TextInput, - ToolbarItem, - Tooltip + Button, + Dropdown, + DropdownItem, + DropdownList, + Flex, + MenuToggle, + MenuToggleElement, + Select, + SelectList, + SelectOption, + Split, + SplitItem, + TextInput, + ToolbarItem, + Tooltip } from '@patternfly/react-core'; -import { - Dropdown as DropdownDeprecated, - DropdownItem as DropdownItemDeprecated, - DropdownPosition as DropdownPositionDeprecated, - DropdownToggle as DropdownToggleDeprecated, - Select, - SelectOption, - SelectVariant -} from '@patternfly/react-core/deprecated'; import { DefaultEdgeOptions, DefaultNodeOptions, GeneratorEdgeOptions, GeneratorNodeOptions } from '../data/generator'; -import { - EDGE_ANIMATION_SPEEDS, - EDGE_STYLES, - EDGE_TERMINAL_TYPES, - NODE_SHAPES, - NODE_STATUSES -} from './styleUtils'; +import { EDGE_ANIMATION_SPEEDS, EDGE_STYLES, EDGE_TERMINAL_TYPES, NODE_SHAPES, NODE_STATUSES } from './styleUtils'; import { Controller, Model, NodeShape } from '@patternfly/react-topology'; const GRAPH_LAYOUT_OPTIONS = ['x', 'y', 'visible', 'style', 'layout', 'scale', 'scaleExtent', 'layers']; @@ -74,115 +67,149 @@ export const useTopologyOptions = ( - setLayoutDropdownOpen(!layoutDropdownOpen)}>{layout}} + ) => ( + setLayoutDropdownOpen(!layoutDropdownOpen)}> + {layout} + + )} isOpen={layoutDropdownOpen} - dropdownItems={[ - updateLayout('Force')}> + > + + updateLayout('Force')}> Force - , - updateLayout('Dagre')}> + + updateLayout('Dagre')}> Dagre - , - updateLayout('Cola')}> + + updateLayout('Cola')}> Cola - , - updateLayout('ColaGroups')}> + + updateLayout('ColaGroups')}> ColaGroups - , - updateLayout('ColaNoForce')}> + + updateLayout('ColaNoForce')}> ColaNoForce - , - updateLayout('Grid')}> + + updateLayout('Grid')}> Grid - , - updateLayout('Concentric')}> + + updateLayout('Concentric')}> Concentric - , - updateLayout('BreadthFirst')}> + + updateLayout('BreadthFirst')}> BreadthFirst - - ]} - /> + + + ); const renderNodeOptionsDropdown = () => { const selectContent = ( -
+ setNodeOptions(prev => ({ ...prev, nodeLabels: !prev.nodeLabels }))} - /> + isSelected={nodeOptions.nodeLabels} + onClick={() => setNodeOptions((prev) => ({ ...prev, nodeLabels: !prev.nodeLabels }))} + > + Labels + setNodeOptions(prev => ({ ...prev, nodeSecondaryLabels: !prev.nodeSecondaryLabels }))} - /> + isSelected={nodeOptions.nodeSecondaryLabels} + onClick={() => setNodeOptions((prev) => ({ ...prev, nodeSecondaryLabels: !prev.nodeSecondaryLabels }))} + > + Secondary Labels + 1} + isSelected={nodeOptions.statuses.length > 1} onClick={() => - setNodeOptions(prev => ({ + setNodeOptions((prev) => ({ ...prev, statuses: prev.statuses.length > 1 ? DefaultNodeOptions.statuses : NODE_STATUSES })) } - /> + > + Status + - setNodeOptions(prev => ({ + setNodeOptions((prev) => ({ ...prev, statusDecorators: !prev.statusDecorators, showDecorators: !prev.showDecorators })) } - /> + > + Decorators + setNodeOptions(prev => ({ ...prev, nodeBadges: !prev.nodeBadges }))} - /> + isSelected={nodeOptions.nodeBadges} + onClick={() => setNodeOptions((prev) => ({ ...prev, nodeBadges: !prev.nodeBadges }))} + > + Badges + setNodeOptions(prev => ({ ...prev, nodeIcons: !prev.nodeIcons }))} - /> + isSelected={nodeOptions.nodeIcons} + onClick={() => setNodeOptions((prev) => ({ ...prev, nodeIcons: !prev.nodeIcons }))} + > + Icons + setNodeOptions(prev => ({ ...prev, contextMenus: !prev.contextMenus }))} - /> -
+ isSelected={nodeOptions.contextMenus} + onClick={() => setNodeOptions((prev) => ({ ...prev, contextMenus: !prev.contextMenus }))} + > + Context Menus + + + ); + + const nodeOptionsToggle = (toggleRef: React.Ref) => ( + setNodeOptionsOpen((prev) => !prev)} + isExpanded={nodeOptionsOpen} + style={ + { + width: '250px' + } as React.CSSProperties + } + > + Node options + ); return ( - {}} isOpen={nodeOptionsOpen} placeholder="Node options" toggle={nodeOptionsToggle}> + {selectContent} + ); }; const toggleNodeShape = (shape: NodeShape): void => { const index = nodeOptions.shapes.indexOf(shape); if (index >= 0) { - setNodeOptions(prev => ({ + setNodeOptions((prev) => ({ ...prev, shapes: [...prev.shapes.slice(0, index), ...prev.shapes.slice(index + 1)] })); } else { - setNodeOptions(prev => ({ + setNodeOptions((prev) => ({ ...prev, shapes: [...prev.shapes, shape] })); @@ -191,92 +218,127 @@ export const useTopologyOptions = ( const renderNodeShapesDropdown = () => { const selectContent = ( -
- {NODE_SHAPES.map(shape => ( + + {NODE_SHAPES.map((shape) => ( toggleNodeShape(shape)} - /> + > + {shape} + ))} -
+ + ); + + const nodeShapesToggle = (toggleRef: React.Ref) => ( + setNodeShapesOpen((prev) => !prev)} + isExpanded={nodeShapesOpen} + style={ + { + width: '250px' + } as React.CSSProperties + } + > + Node shapes + ); return ( - {}} isOpen={nodeShapesOpen} toggle={nodeShapesToggle}> + {selectContent} + ); }; const renderEdgeOptionsDropdown = () => { const selectContent = ( -
+ 1} + hasCheckbox + isSelected={edgeOptions.edgeStatuses.length > 1} onClick={() => - setEdgeOptions(prev => ({ + setEdgeOptions((prev) => ({ ...prev, edgeStatuses: prev.edgeStatuses.length > 1 ? DefaultEdgeOptions.edgeStatuses : NODE_STATUSES })) } - /> + > + Status + 1} + hasCheckbox + isSelected={edgeOptions.edgeStyles.length > 1} onClick={() => - setEdgeOptions(prev => ({ + setEdgeOptions((prev) => ({ ...prev, edgeStyles: prev.edgeStyles.length > 1 ? DefaultEdgeOptions.edgeStyles : EDGE_STYLES })) } - /> + > + Styles + 1} + hasCheckbox + isSelected={edgeOptions.edgeAnimations.length > 1} onClick={() => - setEdgeOptions(prev => ({ + setEdgeOptions((prev) => ({ ...prev, edgeAnimations: prev.edgeAnimations.length > 1 ? DefaultEdgeOptions.edgeAnimations : EDGE_ANIMATION_SPEEDS })) } - /> + > + Animations + 1} + hasCheckbox + isSelected={edgeOptions.terminalTypes.length > 1} onClick={() => - setEdgeOptions(prev => ({ + setEdgeOptions((prev) => ({ ...prev, terminalTypes: prev.terminalTypes.length > 1 ? DefaultEdgeOptions.terminalTypes : EDGE_TERMINAL_TYPES })) } - /> + > + Terminal type + setEdgeOptions(prev => ({ ...prev, edgeTags: !prev.edgeTags }))} - /> -
+ hasCheckbox + isSelected={edgeOptions.edgeTags} + onClick={() => setEdgeOptions((prev) => ({ ...prev, edgeTags: !prev.edgeTags }))} + > + Tags + + + ); + const edgeOptionsToggle = (toggleRef: React.Ref) => ( + setEdgeOptionsOpen((prev) => !prev)} + isExpanded={edgeOptionsOpen} + style={ + { + width: '250px' + } as React.CSSProperties + } + > + Edge options + ); return ( - {}} isOpen={edgeOptionsOpen} toggle={edgeOptionsToggle}> + {selectContent} + ); }; @@ -295,8 +357,8 @@ export const useTopologyOptions = ( ...currentModel.graph, ..._.pick(savedModel.graph, GRAPH_LAYOUT_OPTIONS) }; - currentModel.nodes = currentModel.nodes.map(n => { - const savedNode = savedModel.nodes.find(sn => sn.id === n.id); + currentModel.nodes = currentModel.nodes.map((n) => { + const savedNode = savedModel.nodes.find((sn) => sn.id === n.id); if (!savedNode) { return n; } @@ -341,28 +403,36 @@ export const useTopologyOptions = ( aria-label="nodes" type="number" value={numNodes || ''} - onChange={(_event, val: string) => (val ? updateValue(parseInt(val), 0, 9999, setNumNodes) : setNumNodes(null))} + onChange={(_event, val: string) => + val ? updateValue(parseInt(val), 0, 9999, setNumNodes) : setNumNodes(null) + } /> Edges: (val ? updateValue(parseInt(val), 0, 200, setNumEdges) : setNumEdges(null))} + onChange={(_event, val: string) => + val ? updateValue(parseInt(val), 0, 200, setNumEdges) : setNumEdges(null) + } /> Groups: (val ? updateValue(parseInt(val), 0, 100, setNumGroups) : setNumGroups(null))} + onChange={(_event, val: string) => + val ? updateValue(parseInt(val), 0, 100, setNumGroups) : setNumGroups(null) + } /> Nesting Depth: (val ? updateValue(parseInt(val), 0, 5, setNestedLevel) : setNestedLevel(null))} + onChange={(_event, val: string) => + val ? updateValue(parseInt(val), 0, 5, setNestedLevel) : setNestedLevel(null) + } />