Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link/Node: noop onClick/Hover if readonly #45

Merged
merged 2 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## Fixed

- Readonly mode should prevent link edits [loonyuni](https://github.com/MrBlenny/react-flow-chart/pull/45)

## [0.0.7] - 2019-08-22

## Added
Expand Down
11 changes: 6 additions & 5 deletions src/components/Link/Link.wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { IConfig, ILink, INode, IOnLinkMouseEnter, IOnLinkMouseLeave } from '../../'
import { IConfig, ILink, INode, IOnLinkClick, IOnLinkMouseEnter, IOnLinkMouseLeave } from '../../'
import { noop } from '../../utils'
import { ILinkDefaultProps, LinkDefault } from './Link.default'
import { getLinkPosition } from './utils'

Expand All @@ -12,7 +13,7 @@ export interface ILinkWrapperProps {
toNode: INode | undefined
onLinkMouseEnter: IOnLinkMouseEnter
onLinkMouseLeave: IOnLinkMouseLeave
onLinkClick: IOnLinkMouseLeave
onLinkClick: IOnLinkClick
Component?: React.FunctionComponent<ILinkDefaultProps>
}

Expand Down Expand Up @@ -46,9 +47,9 @@ export const LinkWrapper = React.memo(({
link={link}
startPos={startPos}
endPos={endPos}
onLinkMouseEnter={onLinkMouseEnter}
onLinkMouseLeave={onLinkMouseLeave}
onLinkClick={onLinkClick}
onLinkMouseEnter={config.readonly ? noop : onLinkMouseEnter}
onLinkMouseLeave={config.readonly ? noop : onLinkMouseLeave}
onLinkClick={config.readonly ? noop : onLinkClick}
isSelected={isSelected}
isHovered={isHovered}
/>
Expand Down
11 changes: 7 additions & 4 deletions src/components/Node/Node.wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IOnNodeClick, IOnNodeSizeChange, IOnPortPositionChange,
IPortDefaultProps, IPortsDefaultProps, IPosition, ISelectedOrHovered, ISize, PortWrapper,
} from '../../'
import { noop } from '../../utils'
import { INodeDefaultProps, NodeDefault } from './Node.default'

export interface INodeWrapperProps {
Expand Down Expand Up @@ -94,8 +95,8 @@ export const NodeWrapper = ({
port={node.ports[portId]}
Component={Port}
onPortPositionChange={onPortPositionChange}
onLinkStart={config.readonly ? () => null : onLinkStart}
onLinkMove={config.readonly ? () => null : onLinkMove}
onLinkStart={config.readonly ? noop : onLinkStart}
onLinkMove={config.readonly ? noop : onLinkMove}
onLinkComplete={onLinkComplete}
onLinkCancel={onLinkCancel}
/>
Expand All @@ -122,8 +123,10 @@ export const NodeWrapper = ({
ref={compRef}
children={children}
onClick={(e) => {
onNodeClick({ config, nodeId: node.id })
e.stopPropagation()
if (!config.readonly) {
onNodeClick({ config, nodeId: node.id })
e.stopPropagation()
}
}}
isSelected={isSelected}
node={node}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './components'
export * from './container'
export * from './types'
export * from './constants'
export * from './utils'
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const noop = () => null