-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from jeff-phillips-18/expand-collapse-fixes
Handle expand/collapse groups
- Loading branch information
Showing
18 changed files
with
525 additions
and
540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 10 additions & 54 deletions
64
packages/demo-app-ts/src/demos/pipelinesDemo/DemoPipelinesGroup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,34 @@ | ||
import * as React from 'react'; | ||
import { | ||
DefaultTaskGroup, | ||
GraphElement, | ||
Node, | ||
LabelPosition, | ||
observer, | ||
ScaleDetailsLevel, | ||
ShapeProps, | ||
WithContextMenuProps, | ||
WithDragNodeProps, | ||
WithSelectionProps, | ||
PipelinesDefaultGroup, | ||
AnchorEnd, | ||
DagreLayoutOptions, | ||
TOP_TO_BOTTOM, | ||
useAnchor, | ||
Dimensions | ||
} from '@patternfly/react-topology'; | ||
|
||
export enum DataTypes { | ||
Default, | ||
Alternate | ||
} | ||
|
||
type DemoPipelinesGroupProps = { | ||
element: GraphElement; | ||
collapsible?: boolean; | ||
collapsedWidth?: number; | ||
collapsedHeight?: number; | ||
onCollapseChange?: (group: Node, collapsed: boolean) => void; | ||
getCollapsedShape?: (node: Node) => React.FunctionComponent<ShapeProps>; | ||
collapsedShadowOffset?: number; // defaults to 10 | ||
} & WithContextMenuProps & | ||
WithDragNodeProps & | ||
WithSelectionProps; | ||
|
||
import TaskGroupSourceAnchor from '../pipelineGroupsDemo/TaskGroupSourceAnchor'; | ||
import TaskGroupTargetAnchor from '../pipelineGroupsDemo/TaskGroupTargetAnchor'; | ||
|
||
export const DemoPipelinesGroup: React.FunctionComponent<DemoPipelinesGroupProps> = ({ | ||
element, | ||
onCollapseChange, | ||
...rest | ||
}) => { | ||
const DemoPipelinesGroup: React.FunctionComponent<DemoPipelinesGroupProps> = ({ element }) => { | ||
const data = element.getData(); | ||
const detailsLevel = element.getGraph().getDetailsLevel(); | ||
const verticalLayout = (element.getGraph().getLayoutOptions?.() as DagreLayoutOptions)?.rankdir === TOP_TO_BOTTOM; | ||
|
||
const handleCollapse = (group: Node, collapsed: boolean): void => { | ||
if (collapsed && rest.collapsedWidth !== undefined && rest.collapsedHeight !== undefined) { | ||
group.setDimensions(new Dimensions(rest.collapsedWidth, rest.collapsedHeight)); | ||
} | ||
group.setCollapsed(collapsed); | ||
onCollapseChange && onCollapseChange(group, collapsed); | ||
}; | ||
|
||
useAnchor( | ||
React.useCallback((node: Node) => new TaskGroupSourceAnchor(node, verticalLayout), [verticalLayout]), | ||
AnchorEnd.source | ||
); | ||
|
||
useAnchor( | ||
React.useCallback((node: Node) => new TaskGroupTargetAnchor(node, verticalLayout), [verticalLayout]), | ||
AnchorEnd.target | ||
); | ||
const detailsLevel = element.getGraph().getDetailsLevel() | ||
|
||
return ( | ||
<PipelinesDefaultGroup | ||
<DefaultTaskGroup | ||
element={element} | ||
collapsible | ||
collapsedWidth={75} | ||
collapsedHeight={75} | ||
// TODO: labels don't render until clicked | ||
collapsible={false} | ||
showLabel={detailsLevel === ScaleDetailsLevel.high} | ||
labelPosition={LabelPosition.top} | ||
badge={data?.badge} | ||
onCollapseChange={handleCollapse} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
export default observer(DemoPipelinesGroup); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.