Skip to content

Commit

Permalink
content-editable can be persisted into database
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Oct 18, 2023
1 parent 536cdd8 commit 1481441
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const DETAILS_PANE_STEP_SIZE = 1000
export function DetailsPane({
vizItem,
graphStyle,
nodeInspectorWidth
nodeInspectorWidth,
onGraphInteraction
}: DetailsPaneProps): JSX.Element {
const [maxPropertiesCount, setMaxPropertiesCount] = useState(
DETAILS_PANE_STEP_SIZE
Expand Down Expand Up @@ -93,6 +94,7 @@ export function DetailsPane({
moreStep={DETAILS_PANE_STEP_SIZE}
totalNumItems={allItemProperties.length}
nodeInspectorWidth={nodeInspectorWidth}
onGraphInteraction={onGraphInteraction}
/>
</PaneBody>
</PaneWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
GraphInteractionCallBack,
GraphModel,
GraphVisualizer,
NODE_ON_CANVAS_CREATE
NODE_ON_CANVAS_CREATE,
NODE_PROP_UPDATE
} from 'neo4j-arc/graph-visualization'

import { StyledVisContainer } from './VisualizationView.styled'
Expand Down Expand Up @@ -277,6 +278,33 @@ LIMIT ${maxNewNeighbours}`
}

onGraphInteraction: GraphInteractionCallBack = (event, properties) => {
if (event == NODE_PROP_UPDATE) {
if (properties == null) {
throw new Error('')
}

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

const query = `MATCH (n) WHERE ID(n) = ${nodeId} SET n.${propKey} = "${propVal}"`
console.log(query)

this.props.bus.self(
CYPHER_REQUEST,
{
query,
params: { nodeId, propKey, propVal },
queryType: NEO4J_BROWSER_USER_ACTION_QUERY
},
(response: any) => {
if (!response.success) {
throw new Error(response.error)
}
}
)
}

if (event == NODE_ON_CANVAS_CREATE) {
if (properties == null) {
throw new Error(
Expand Down
58 changes: 39 additions & 19 deletions src/neo4j-arc/common/components/PropertiesTable/PropertiesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,31 @@ import {
import { ClipboardCopier } from '../ClipboardCopier'
import { ShowMoreOrAll } from '../ShowMoreOrAll/ShowMoreOrAll'
import { VizItemProperty } from 'neo4j-arc/common'
import {
GraphInteractionCallBack,
NODE_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
propKey: string
value: string
width: number
type: string
onGraphInteraction: GraphInteractionCallBack
}

// https://stackoverflow.com/a/49639256
const ContentEditable = ({ children }: any): JSX.Element => {
return (
<div
contentEditable="true"
onInput={e =>
console.log('content editable clicked!!!' + e.currentTarget.textContent)
}
>
{children}
</div>
)
}

function ExpandableValue({ value, width, type }: ExpandableValueProps) {
function ExpandableValue({
nodeId,
propKey,
value,
width,
type,
onGraphInteraction
}: ExpandableValueProps) {
const [expanded, setExpanded] = useState(false)

const maxLength =
Expand All @@ -71,7 +70,16 @@ function ExpandableValue({ value, width, type }: ExpandableValueProps) {
valueShown += valueIsTrimmed ? ELLIPSIS : ''

return (
<ContentEditable>
<div
contentEditable="true"
onInput={e =>
onGraphInteraction(NODE_PROP_UPDATE, {
nodeId: nodeId,
propKey: propKey,
propVal: e.currentTarget.textContent
})
}
>
{type.startsWith('Array') && '['}
<ClickableUrls text={valueShown} />
{valueIsTrimmed && (
Expand All @@ -80,7 +88,7 @@ function ExpandableValue({ value, width, type }: ExpandableValueProps) {
</StyledExpandValueButton>
)}
{type.startsWith('Array') && ']'}
</ContentEditable>
</div>
)
}

Expand All @@ -90,14 +98,23 @@ type PropertiesViewProps = {
totalNumItems: number
moreStep: number
nodeInspectorWidth: number
onGraphInteraction?: GraphInteractionCallBack
}
export const PropertiesTable = ({
visibleProperties,
totalNumItems,
onMoreClick,
moreStep,
nodeInspectorWidth
nodeInspectorWidth,
onGraphInteraction
}: PropertiesViewProps): JSX.Element => {
let id = ''
for (let i = 0; i < visibleProperties.length; i++) {
if (visibleProperties[i].key == '<id>') {
id = visibleProperties[i].value
}
}

return (
<>
<StyledInlineList>
Expand All @@ -110,9 +127,12 @@ export const PropertiesTable = ({
</KeyCell>
<ValueCell>
<ExpandableValue
nodeId={id}
propKey={key}
value={value}
width={nodeInspectorWidth}
type={type}
onGraphInteraction={onGraphInteraction ?? (() => undefined)}
/>
</ValueCell>
<CopyCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ import { PaneBody, PaneHeader, PaneTitle, PaneWrapper } from './styled'
import { NodeLabel } from './NodeLabel'
import { RelType } from './RelType'
import { GraphStyleModel } from '../../models/GraphStyle'
import { GraphInteractionCallBack } from '../Graph/GraphEventHandlerModel'

export const DETAILS_PANE_STEP_SIZE = 1000
export type DetailsPaneProps = {
vizItem: NodeItem | RelationshipItem
graphStyle: GraphStyleModel
nodeInspectorWidth: number
onGraphInteraction?: GraphInteractionCallBack
}
export function DefaultDetailsPane({
vizItem,
graphStyle,
nodeInspectorWidth
nodeInspectorWidth,
onGraphInteraction
}: DetailsPaneProps): JSX.Element {
const [maxPropertiesCount, setMaxPropertiesCount] = useState(
DETAILS_PANE_STEP_SIZE
Expand Down Expand Up @@ -99,6 +102,7 @@ export function DefaultDetailsPane({
moreStep={DETAILS_PANE_STEP_SIZE}
totalNumItems={allItemProperties.length}
nodeInspectorWidth={nodeInspectorWidth}
onGraphInteraction={onGraphInteraction}
/>
</PaneBody>
</PaneWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ 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 type GraphInteraction =
| 'NODE_EXPAND'
| 'NODE_UNPINNED'
| 'NODE_DISMISSED'
| 'NODE_ON_CANVAS_CREATE'
| typeof NODE_ON_CANVAS_CREATE
| typeof NODE_PROP_UPDATE

export type GraphInteractionCallBack = (
event: GraphInteraction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export class GraphVisualizer extends Component<
}}
DetailsPaneOverride={this.props.DetailsPaneOverride}
OverviewPaneOverride={this.props.OverviewPaneOverride}
onGraphInteraction={this.props.onGraphInteraction}
/>
</StyledFullSizeContainer>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { Resizable } from 're-resizable'
import { GraphStats } from '../utils/mapper'
import { GraphStyleModel } from '../models/GraphStyle'
import { VizItem } from '../types'
import { GraphInteractionCallBack } from './Graph/GraphEventHandlerModel'

interface NodeInspectorPanelProps {
expanded: boolean
Expand All @@ -51,6 +52,7 @@ interface NodeInspectorPanelProps {
width: number
DetailsPaneOverride?: React.FC<DetailsPaneProps>
OverviewPaneOverride?: React.FC<OverviewPaneProps>
onGraphInteraction?: GraphInteractionCallBack
}

export const defaultPanelWidth = (): number =>
Expand All @@ -68,7 +70,8 @@ export class NodeInspectorPanel extends Component<NodeInspectorPanelProps> {
toggleExpanded,
width,
DetailsPaneOverride,
OverviewPaneOverride
OverviewPaneOverride,
onGraphInteraction
} = this.props
const relevantItems = ['node', 'relationship']
const hoveringNodeOrRelationship =
Expand Down Expand Up @@ -120,6 +123,7 @@ export class NodeInspectorPanel extends Component<NodeInspectorPanelProps> {
vizItem={shownEl}
graphStyle={graphStyle}
nodeInspectorWidth={width}
onGraphInteraction={onGraphInteraction}
/>
) : (
<OverviewPane
Expand Down
5 changes: 4 additions & 1 deletion src/neo4j-arc/graph-visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ export { GraphVisualizer } from './GraphVisualizer/GraphVisualizer'
export type { DetailsPaneProps } from './GraphVisualizer/DefaultPanelContent/DefaultDetailsPane'
export type { OverviewPaneProps } from './GraphVisualizer/DefaultPanelContent/DefaultOverviewPane'

export { NODE_ON_CANVAS_CREATE } from './GraphVisualizer/Graph/GraphEventHandlerModel'
export {
NODE_ON_CANVAS_CREATE,
NODE_PROP_UPDATE
} from './GraphVisualizer/Graph/GraphEventHandlerModel'
export type { GraphInteractionCallBack } from './GraphVisualizer/Graph/GraphEventHandlerModel'

0 comments on commit 1481441

Please sign in to comment.