Skip to content

Commit

Permalink
Unify node and rel prop editing (#46)
Browse files Browse the repository at this point in the history
* Unify node and rel prop editing

* Unify node and rel prop editing
  • Loading branch information
QubitPi authored Dec 7, 2023
1 parent 3e09d23 commit 48a2a9a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export function DetailsPane({
</PaneHeader>
<PaneBody data-testid="viz-details-pane-body">
<PropertiesTable
isNode={vizItem.type === 'node'}
visibleProperties={visibleItemProperties}
onMoreClick={handleMorePropertiesClick}
moreStep={DETAILS_PANE_STEP_SIZE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
GraphVisualizer,
REL_ON_CANVAS_CREATE,
NODE_ON_CANVAS_CREATE,
NODE_PROP_UPDATE,
PROP_UPDATE,
NODE_LABEL_UPDATE,
REL_TYPE_UPDATE,
DETAILS_PANE_TITLE_UPDATE
Expand Down Expand Up @@ -315,6 +315,10 @@ LIMIT ${maxNewNeighbours}`
}
}
)

const cmd = 'MATCH (n) RETURN n;'
const action = executeCommand(cmd, { source: commandSources.rerunFrame })
this.props.bus.send(action.type, action)
}

if (event == NODE_LABEL_UPDATE) {
Expand Down Expand Up @@ -343,27 +347,33 @@ LIMIT ${maxNewNeighbours}`
}
}
)

const cmd = 'MATCH (n) RETURN n;'
const action = executeCommand(cmd, { source: commandSources.rerunFrame })
this.props.bus.send(action.type, action)
}

if (event == NODE_PROP_UPDATE) {
if (event == PROP_UPDATE) {
if (properties == null) {
throw new Error(
'A property map with nodeId, propKey, and propVal keys are required'
)
}

const nodeId = properties['nodeId']
const isNode = properties['isNode']
const nodeOrRelId = properties['nodeOrRelId']
const propKey = properties['propKey']
const propVal = properties['propVal']

const query = `MATCH (n) WHERE ID(n) = ${nodeId} SET n.${propKey} = "${propVal}"`
console.log(query)
const query = isNode
? `MATCH (n) WHERE ID(n) = ${nodeOrRelId} SET n.${propKey} = "${propVal}"`
: `MATCH ()-[r]-() WHERE ID(r) = ${nodeOrRelId} SET r.${propKey} = "${propVal}"`

this.props.bus.self(
CYPHER_REQUEST,
{
query,
params: { nodeId, propKey, propVal },
params: { nodeOrRelId, propKey, propVal },
queryType: NEO4J_BROWSER_USER_ACTION_QUERY
},
(response: any) => {
Expand All @@ -372,6 +382,10 @@ LIMIT ${maxNewNeighbours}`
}
}
)

const cmd = 'MATCH (n) RETURN n;'
const action = executeCommand(cmd, { source: commandSources.rerunFrame })
this.props.bus.send(action.type, action)
}

if (event == REL_ON_CANVAS_CREATE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('<DetailsPane />', () => {
}
return render(
<PropertiesTable
isNode={type === 'node'}
visibleProperties={propertyList}
onMoreClick={jest.fn()}
totalNumItems={propertyList.length}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,27 @@ import { ShowMoreOrAll } from '../ShowMoreOrAll/ShowMoreOrAll'
import { VizItemProperty } from 'neo4j-arc/common'
import {
GraphInteractionCallBack,
NODE_PROP_UPDATE
PROP_UPDATE
} from '../../../graph-visualization'

export const ELLIPSIS = '\u2026'
export const WIDE_VIEW_THRESHOLD = 900
export const MAX_LENGTH_NARROW = 150
export const MAX_LENGTH_WIDE = 300

type ExpandableValueProps = {
nodeId: string
isNode: boolean
nodeOrRelId: string
propKey: string
value: string
width: number
type: string
onGraphInteraction: GraphInteractionCallBack
}

function ExpandableValue({
nodeId,
isNode,
nodeOrRelId,
propKey,
value,
width,
Expand All @@ -76,8 +80,9 @@ function ExpandableValue({
onKeyUp={(event: any) => {
if (event.keyCode === 13) {
event.preventDefault()
onGraphInteraction(NODE_PROP_UPDATE, {
nodeId: nodeId,
onGraphInteraction(PROP_UPDATE, {
isNode: isNode,
nodeOrRelId: nodeOrRelId,
propKey: propKey,
propVal: event.currentTarget.textContent
})
Expand All @@ -97,14 +102,17 @@ function ExpandableValue({
}

type PropertiesViewProps = {
isNode: boolean
visibleProperties: VizItemProperty[]
onMoreClick: (numMore: number) => void
totalNumItems: number
moreStep: number
nodeInspectorWidth: number
onGraphInteraction?: GraphInteractionCallBack
}

export const PropertiesTable = ({
isNode,
visibleProperties,
totalNumItems,
onMoreClick,
Expand All @@ -131,7 +139,8 @@ export const PropertiesTable = ({
</KeyCell>
<ValueCell>
<ExpandableValue
nodeId={id}
isNode={isNode}
nodeOrRelId={id}
propKey={key}
value={value}
width={nodeInspectorWidth}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function DefaultDetailsPane({
</PaneHeader>
<PaneBody>
<PropertiesTable
isNode={vizItem.type === 'node'}
visibleProperties={visibleItemProperties}
onMoreClick={handleMorePropertiesClick}
moreStep={DETAILS_PANE_STEP_SIZE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { Visualization } from './visualization/Visualization'

export const NODE_ON_CANVAS_CREATE = 'NODE_ON_CANVAS_CREATE'
export const NODE_PROP_UPDATE = 'NODE_PROP_UPDATE'
export const PROP_UPDATE = 'PROP_UPDATE'
export const NODE_LABEL_UPDATE = 'NODE_LABEL_UPDATE'
export const REL_ON_CANVAS_CREATE = 'REL_ON_CANVAS_CREATE'
export const REL_TYPE_UPDATE = 'REL_TYPE_UPDATE'
Expand All @@ -42,10 +42,10 @@ export type GraphInteraction =
| 'NODE_UNPINNED'
| 'NODE_DISMISSED'
| typeof NODE_ON_CANVAS_CREATE
| typeof NODE_PROP_UPDATE
| typeof NODE_LABEL_UPDATE
| typeof REL_ON_CANVAS_CREATE
| typeof REL_TYPE_UPDATE
| typeof PROP_UPDATE
| typeof DETAILS_PANE_TITLE_UPDATE

export type GraphInteractionCallBack = (
Expand Down
2 changes: 1 addition & 1 deletion src/neo4j-arc/graph-visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type { OverviewPaneProps } from './GraphVisualizer/DefaultPanelContent/De
export {
REL_ON_CANVAS_CREATE,
NODE_ON_CANVAS_CREATE,
NODE_PROP_UPDATE,
PROP_UPDATE,
NODE_LABEL_UPDATE,
REL_TYPE_UPDATE,
DETAILS_PANE_TITLE_UPDATE
Expand Down
2 changes: 1 addition & 1 deletion src/neo4j-arc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neo4j-devtools-arc",
"version": "0.0.75",
"version": "0.0.76",
"main": "dist/neo4j-arc.js",
"author": "Neo4j Inc.",
"license": "GPL-3.0",
Expand Down

0 comments on commit 48a2a9a

Please sign in to comment.