Skip to content

Commit 32f864c

Browse files
feat(cypher): add execute cypher button to details pane
1 parent 993200a commit 32f864c

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

src/browser/modules/Stream/CypherFrame/VisualizationView/PropertiesPanelContent/DetailsPane.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,30 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
import React, { useState } from 'react'
20+
import React, { useCallback, useState } from 'react'
2121

2222
import { ClipboardCopier, PropertiesTable, upperFirst } from 'neo4j-arc/common'
2323

2424
import { StyleableNodeLabel } from './StyleableNodeLabel'
2525
import { StyleableRelType } from './StyleableRelType'
2626
import { PaneBody, PaneHeader, PaneTitle, PaneWrapper } from './styled'
2727
import { DetailsPaneProps } from 'neo4j-arc'
28+
import { withBus } from 'react-suber'
29+
import {
30+
commandSources,
31+
executeCommand
32+
} from 'project-root/src/shared/modules/commands/commandsDuck'
2833

2934
export const DETAILS_PANE_STEP_SIZE = 1000
30-
export function DetailsPane({
35+
36+
function DetailsPaneRender({
3137
vizItem,
3238
graphStyle,
3339
nodeInspectorWidth,
3440
nodes,
35-
relationships
36-
}: DetailsPaneProps): JSX.Element {
41+
relationships,
42+
bus
43+
}: DetailsPaneProps & { bus: any }): JSX.Element {
3744
const [maxPropertiesCount, setMaxPropertiesCount] = useState(
3845
DETAILS_PANE_STEP_SIZE
3946
)
@@ -51,7 +58,14 @@ export function DetailsPane({
5158
const handleMorePropertiesClick = (numMore: number) => {
5259
setMaxPropertiesCount(maxPropertiesCount + numMore)
5360
}
61+
const executeCypher = useCallback(
62+
(cmd: string) => {
63+
const action = executeCommand(cmd, { source: commandSources.button })
5464

65+
bus.send(action.type, action)
66+
},
67+
[bus]
68+
)
5569
return (
5670
<PaneWrapper>
5771
<PaneHeader>
@@ -99,8 +113,15 @@ export function DetailsPane({
99113
moreStep={DETAILS_PANE_STEP_SIZE}
100114
totalNumItems={allItemProperties.length}
101115
nodeInspectorWidth={nodeInspectorWidth}
116+
executeCypher={executeCypher}
102117
/>
103118
</PaneBody>
104119
</PaneWrapper>
105120
)
106121
}
122+
123+
const DetailsPaneWithBus = withBus(DetailsPaneRender)
124+
125+
export function DetailsPane(props: DetailsPaneProps) {
126+
return <DetailsPaneWithBus {...props} />
127+
}

src/neo4j-arc/common/components/PropertiesTable/PropertiesTable.style.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export const KeyCell = styled.td`
6767
padding: 2px;
6868
width: 30%;
6969
`
70-
70+
export const CypherExecDiv = styled.div`
71+
margin-top: 10px;
72+
`
7173
export const CopyCell = styled.td`
7274
padding: 2px 5px;
7375
display: flex;

src/neo4j-arc/common/components/PropertiesTable/PropertiesTable.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import React, { useState } from 'react'
2222
import { ClickableUrls } from '../ClickableUrls'
2323
import {
2424
AlternatingTable,
25-
CopyCell,
25+
CypherExecDiv,
2626
KeyCell,
2727
StyledExpandValueButton,
2828
StyledInlineList,
@@ -75,13 +75,15 @@ type PropertiesViewProps = {
7575
totalNumItems: number
7676
moreStep: number
7777
nodeInspectorWidth: number
78+
executeCypher?: (cmd: string) => any
7879
}
7980
export const PropertiesTable = ({
8081
visibleProperties,
8182
totalNumItems,
8283
onMoreClick,
8384
moreStep,
84-
nodeInspectorWidth
85+
nodeInspectorWidth,
86+
executeCypher
8587
}: PropertiesViewProps): JSX.Element => {
8688
return (
8789
<>
@@ -100,13 +102,30 @@ export const PropertiesTable = ({
100102
type={type}
101103
/>
102104
</ValueCell>
103-
<CopyCell>
105+
<td>
104106
<ClipboardCopier
105107
titleText={'Copy key and value'}
106108
textToCopy={`${key}: ${value}`}
107109
iconSize={12}
108110
/>
109-
</CopyCell>
111+
{key === 'cypher' && executeCypher && value && (
112+
<CypherExecDiv>
113+
<button
114+
title={'Execute cypher'}
115+
onClick={() => {
116+
if (executeCypher && value) {
117+
executeCypher(value)
118+
}
119+
}}
120+
>
121+
<i
122+
className="fa fa-external-link"
123+
aria-hidden="true"
124+
></i>
125+
</button>
126+
</CypherExecDiv>
127+
)}
128+
</td>
110129
</tr>
111130
))}
112131
</tbody>

0 commit comments

Comments
 (0)