-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As a preparation for adding containers for branches, we need to introduce a new `CustomGroup` component that can render its label on top, among other topics. This commit moves the `CustomGroup` and `CustomNode` to dedicated folders while also reuse the same `NodeContextMenu` component. fix: #368
- Loading branch information
Showing
35 changed files
with
1,233 additions
and
758 deletions.
There are no files selected for viewing
687 changes: 246 additions & 441 deletions
687
packages/ui/src/components/Visualization/Canvas/__snapshots__/Canvas.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
...ents/Visualization/Custom/ItemAddStep.tsx → ...zation/Custom/ContextMenu/ItemAddStep.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
8 changes: 4 additions & 4 deletions
8
.../Visualization/Custom/ItemDeleteGroup.tsx → ...on/Custom/ContextMenu/ItemDeleteGroup.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
8 changes: 4 additions & 4 deletions
8
...s/Visualization/Custom/ItemDeleteStep.tsx → ...ion/Custom/ContextMenu/ItemDeleteStep.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
8 changes: 4 additions & 4 deletions
8
.../Visualization/Custom/ItemDisableStep.tsx → ...on/Custom/ContextMenu/ItemDisableStep.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
8 changes: 4 additions & 4 deletions
8
...s/Visualization/Custom/ItemInsertStep.tsx → ...ion/Custom/ContextMenu/ItemInsertStep.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
8 changes: 4 additions & 4 deletions
8
.../Visualization/Custom/ItemReplaceStep.tsx → ...on/Custom/ContextMenu/ItemReplaceStep.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
110 changes: 110 additions & 0 deletions
110
packages/ui/src/components/Visualization/Custom/ContextMenu/NodeContextMenu.test.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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { ElementModel, GraphElement } from '@patternfly/react-topology'; | ||
import { render } from '@testing-library/react'; | ||
import { CanvasNode } from '../../Canvas'; | ||
import { NodeContextMenu } from './NodeContextMenu'; | ||
import { createVisualizationNode, IVisualizationNode, NodeInteraction } from '../../../../models'; | ||
|
||
describe('NodeContextMenu', () => { | ||
let element: GraphElement<ElementModel, CanvasNode['data']>; | ||
let vizNode: IVisualizationNode | undefined; | ||
let nodeInteractions: NodeInteraction; | ||
|
||
beforeEach(() => { | ||
nodeInteractions = { | ||
canHavePreviousStep: false, | ||
canHaveNextStep: false, | ||
canHaveChildren: false, | ||
canHaveSpecialChildren: false, | ||
canReplaceStep: false, | ||
canRemoveStep: false, | ||
canRemoveFlow: false, | ||
canBeDisabled: false, | ||
}; | ||
vizNode = createVisualizationNode('test', {}); | ||
jest.spyOn(vizNode, 'getNodeInteraction').mockReturnValue(nodeInteractions); | ||
element = { | ||
getData: () => { | ||
return { vizNode } as CanvasNode['data']; | ||
}, | ||
} as unknown as GraphElement<ElementModel, CanvasNode['data']>; | ||
}); | ||
|
||
it('should render an empty component when there is no vizNode', () => { | ||
vizNode = undefined; | ||
const { container } = render(<NodeContextMenu element={element} />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render a PrependStep item if canHavePreviousStep is true', () => { | ||
nodeInteractions.canHavePreviousStep = true; | ||
const wrapper = render(<NodeContextMenu element={element} />); | ||
|
||
const item = wrapper.getByTestId('context-menu-item-prepend'); | ||
|
||
expect(item).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an AppendStep item if canHaveNextStep is true', () => { | ||
nodeInteractions.canHaveNextStep = true; | ||
const wrapper = render(<NodeContextMenu element={element} />); | ||
|
||
const item = wrapper.getByTestId('context-menu-item-append'); | ||
|
||
expect(item).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an InsertStep item if canHaveChildren is true', () => { | ||
nodeInteractions.canHaveChildren = true; | ||
const wrapper = render(<NodeContextMenu element={element} />); | ||
|
||
const item = wrapper.getByTestId('context-menu-item-insert'); | ||
|
||
expect(item).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an InsertSpecialStep item if canHaveSpecialChildren is true', () => { | ||
nodeInteractions.canHaveSpecialChildren = true; | ||
const wrapper = render(<NodeContextMenu element={element} />); | ||
|
||
const item = wrapper.getByTestId('context-menu-item-insert-special'); | ||
|
||
expect(item).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an ItemDisableStep item if canBeDisabled is true', () => { | ||
nodeInteractions.canBeDisabled = true; | ||
const wrapper = render(<NodeContextMenu element={element} />); | ||
|
||
const item = wrapper.getByTestId('context-menu-item-disable'); | ||
|
||
expect(item).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an ItemReplaceStep item if canReplaceStep is true', () => { | ||
nodeInteractions.canReplaceStep = true; | ||
const wrapper = render(<NodeContextMenu element={element} />); | ||
|
||
const item = wrapper.getByTestId('context-menu-item-replace'); | ||
|
||
expect(item).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an ItemDeleteStep item if canRemoveStep is true', () => { | ||
nodeInteractions.canRemoveStep = true; | ||
const wrapper = render(<NodeContextMenu element={element} />); | ||
|
||
const item = wrapper.getByTestId('context-menu-item-delete'); | ||
|
||
expect(item).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an ItemDeleteGroup item if canRemoveFlow is true', () => { | ||
nodeInteractions.canRemoveFlow = true; | ||
const wrapper = render(<NodeContextMenu element={element} />); | ||
|
||
const item = wrapper.getByTestId('context-menu-container-remove'); | ||
|
||
expect(item).toBeInTheDocument(); | ||
}); | ||
}); |
123 changes: 123 additions & 0 deletions
123
packages/ui/src/components/Visualization/Custom/ContextMenu/NodeContextMenu.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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { ArrowDownIcon, ArrowUpIcon, CodeBranchIcon, PlusIcon } from '@patternfly/react-icons'; | ||
import { ContextMenuSeparator, ElementModel, GraphElement } from '@patternfly/react-topology'; | ||
import { forwardRef, ReactElement } from 'react'; | ||
import { AddStepMode } from '../../../../models/visualization/base-visual-entity'; | ||
import { CanvasNode } from '../../Canvas/canvas.models'; | ||
import { ItemAddStep } from './ItemAddStep'; | ||
import { ItemDeleteGroup } from './ItemDeleteGroup'; | ||
import { ItemDeleteStep } from './ItemDeleteStep'; | ||
import { ItemDisableStep } from './ItemDisableStep'; | ||
import { ItemInsertStep } from './ItemInsertStep'; | ||
import { ItemReplaceStep } from './ItemReplaceStep'; | ||
|
||
export const NodeContextMenuFn = (element: GraphElement<ElementModel, CanvasNode['data']>) => { | ||
const items: ReactElement[] = []; | ||
const vizNode = element.getData()?.vizNode; | ||
if (!vizNode) return items; | ||
|
||
const nodeInteractions = vizNode.getNodeInteraction(); | ||
|
||
if (nodeInteractions.canHavePreviousStep) { | ||
items.push( | ||
<ItemAddStep | ||
key="context-menu-item-prepend" | ||
data-testid="context-menu-item-prepend" | ||
mode={AddStepMode.PrependStep} | ||
vizNode={vizNode} | ||
> | ||
<ArrowUpIcon /> Prepend | ||
</ItemAddStep>, | ||
); | ||
} | ||
if (nodeInteractions.canHaveNextStep) { | ||
items.push( | ||
<ItemAddStep | ||
key="context-menu-item-append" | ||
data-testid="context-menu-item-append" | ||
mode={AddStepMode.AppendStep} | ||
vizNode={vizNode} | ||
> | ||
<ArrowDownIcon /> Append | ||
</ItemAddStep>, | ||
); | ||
} | ||
if (nodeInteractions.canHavePreviousStep || nodeInteractions.canHaveNextStep) { | ||
items.push(<ContextMenuSeparator key="context-menu-separator-add" />); | ||
} | ||
|
||
if (nodeInteractions.canHaveChildren) { | ||
items.push( | ||
<ItemInsertStep | ||
key="context-menu-item-insert" | ||
data-testid="context-menu-item-insert" | ||
mode={AddStepMode.InsertChildStep} | ||
vizNode={vizNode} | ||
> | ||
<PlusIcon /> Add step | ||
</ItemInsertStep>, | ||
); | ||
} | ||
if (nodeInteractions.canHaveSpecialChildren) { | ||
items.push( | ||
<ItemInsertStep | ||
key="context-menu-item-insert-special" | ||
data-testid="context-menu-item-insert-special" | ||
mode={AddStepMode.InsertSpecialChildStep} | ||
vizNode={vizNode} | ||
> | ||
<CodeBranchIcon /> Add branch | ||
</ItemInsertStep>, | ||
); | ||
} | ||
if (nodeInteractions.canHaveChildren || nodeInteractions.canHaveSpecialChildren) { | ||
items.push(<ContextMenuSeparator key="context-menu-separator-insert" />); | ||
} | ||
|
||
if (nodeInteractions.canBeDisabled) { | ||
items.push( | ||
<ItemDisableStep key="context-menu-item-disable" data-testid="context-menu-item-disable" vizNode={vizNode} />, | ||
); | ||
} | ||
if (nodeInteractions.canReplaceStep) { | ||
items.push( | ||
<ItemReplaceStep key="context-menu-item-replace" data-testid="context-menu-item-replace" vizNode={vizNode} />, | ||
); | ||
} | ||
if (nodeInteractions.canBeDisabled || nodeInteractions.canReplaceStep) { | ||
items.push(<ContextMenuSeparator key="context-menu-separator-replace" />); | ||
} | ||
|
||
if (nodeInteractions.canRemoveStep) { | ||
const childrenNodes = vizNode.getChildren(); | ||
const shouldConfirmBeforeDeletion = childrenNodes !== undefined && childrenNodes.length > 0; | ||
items.push( | ||
<ItemDeleteStep | ||
key="context-menu-item-delete" | ||
data-testid="context-menu-item-delete" | ||
vizNode={vizNode} | ||
loadModal={shouldConfirmBeforeDeletion} | ||
/>, | ||
); | ||
} | ||
if (nodeInteractions.canRemoveFlow) { | ||
items.push( | ||
<ItemDeleteGroup | ||
key="context-menu-container-remove" | ||
data-testid="context-menu-container-remove" | ||
vizNode={vizNode} | ||
/>, | ||
); | ||
} | ||
|
||
return items; | ||
}; | ||
|
||
export const NodeContextMenu = forwardRef<HTMLDivElement, { element: GraphElement<ElementModel, CanvasNode['data']> }>( | ||
({ element }, forwardedRef) => { | ||
return ( | ||
<div data-testid="node-context-menu" ref={forwardedRef}> | ||
{NodeContextMenuFn(element)} | ||
</div> | ||
); | ||
}, | ||
); |
9 changes: 9 additions & 0 deletions
9
...c/components/Visualization/Custom/ContextMenu/__snapshots__/NodeContextMenu.test.tsx.snap
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NodeContextMenu should render an empty component when there is no vizNode 1`] = ` | ||
<div> | ||
<div | ||
data-testid="node-context-menu" | ||
/> | ||
</div> | ||
`; |
Oops, something went wrong.