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

Fix re-run for Cypher queries to target original DB #1061

Merged
merged 6 commits into from
Feb 17, 2020
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
33 changes: 33 additions & 0 deletions e2e_tests/integration/multi-db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,38 @@ describe('Multi database', () => {
.first()
resultFrame.should('contain', 'could not be found')
})
if (isEnterpriseEdition()) {
it('re-runs query from frame action button on original db', () => {
cy.executeCommand(':clear')
cy.executeCommand(':use neo4j')
cy.executeCommand(':clear')
cy.executeCommand('RETURN "Test string"')
cy.executeCommand(':use system')

// Close first frame
cy.get('[title="Close"]', { timeout: 10000 })
.first()
.click()

// Make sure it's closed
cy.get('[data-testid="frame"]', { timeout: 10000 }).should(
'have.length',
1
)

// Click re-run
cy.get('[data-testid="rerunFrameButton"]', { timeout: 10000 })
.first()
.click()

// Make sure we have what we expect
cy.get('[data-testid="frame"]', { timeout: 10000 })
.first()
.should(frame => {
expect(frame).to.contain('"Test string"')
expect(frame).to.not.contain('ERROR')
})
})
}
}
})
5 changes: 4 additions & 1 deletion src/browser/modules/DecoratedText/TextCommand.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ const mapDispatchToProps = dispatch => {
}
}

export default connect(mapStateToProps, mapDispatchToProps)(TextCommand)
export default connect(
mapStateToProps,
mapDispatchToProps
)(TextCommand)
13 changes: 7 additions & 6 deletions src/browser/modules/Frame/FrameTitlebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ class FrameTitlebar extends Component {
<FrameButton
data-testid="rerunFrameButton"
title="Rerun"
onClick={() =>
props.onReRunClick(frame.cmd, frame.id, frame.requestId)
}
onClick={() => props.onReRunClick(frame)}
>
<RefreshIcon />
</FrameButton>
Expand Down Expand Up @@ -295,11 +293,11 @@ const mapDispatchToProps = (dispatch, ownProps) => {
}
dispatch(remove(id))
},
onReRunClick: (cmd, id, requestId) => {
onReRunClick: ({ cmd, useDb, id, requestId }) => {
if (requestId) {
dispatch(cancelRequest(requestId))
}
dispatch(commands.executeCommand(cmd, id))
dispatch(commands.executeCommand(cmd, { id, useDb }))
},
togglePinning: (id, isPinned) => {
isPinned ? dispatch(unpin(id)) : dispatch(pin(id))
Expand All @@ -308,5 +306,8 @@ const mapDispatchToProps = (dispatch, ownProps) => {
}

export default withBus(
connect(mapStateToProps, mapDispatchToProps)(FrameTitlebar)
connect(
mapStateToProps,
mapDispatchToProps
)(FrameTitlebar)
)
9 changes: 7 additions & 2 deletions src/browser/modules/Stream/StyleFrame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ const StyleStatusbar = ({ resetStyleAction, rerunAction, onResetClick }) => {
const mapStateToProps = (state, ownProps) => {
return {
resetStyleAction: executeSystemCommand(`${getCmdChar(state)}style reset`),
rerunAction: executeCommand(ownProps.frame.cmd, ownProps.frame.id)
rerunAction: executeCommand(ownProps.frame.cmd, {
id: ownProps.frame.id
})
}
}
const mapDispatchToProps = dispatch => ({
Expand All @@ -93,6 +95,9 @@ const mapDispatchToProps = dispatch => ({
}
})

const Statusbar = connect(mapStateToProps, mapDispatchToProps)(StyleStatusbar)
const Statusbar = connect(
mapStateToProps,
mapDispatchToProps
)(StyleStatusbar)

export default StyleFrame
19 changes: 14 additions & 5 deletions src/shared/modules/commands/commandsDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,27 @@ export default function reducer(state = initialState, action) {

// Action creators

export const executeCommand = (cmd, id, requestId, parentId) => {
export const executeCommand = (
cmd,
{ id, requestId, parentId, useDb } = {}
) => {
return {
type: COMMAND_QUEUED,
cmd,
id,
requestId,
parentId
parentId,
useDb
}
}

export const executeSingleCommand = (cmd, id, requestId) => {
export const executeSingleCommand = (cmd, { id, requestId, useDb } = {}) => {
return {
type: SINGLE_COMMAND_QUEUED,
cmd,
id,
requestId
requestId,
useDb
}
}

Expand Down Expand Up @@ -162,7 +167,11 @@ export const handleCommandEpic = (action$, store) =>
if (statements.length === 1) {
// Single command
return store.dispatch(
executeSingleCommand(statements[0], action.id, action.requestId)
executeSingleCommand(statements[0], {
id: action.id,
requestId: action.requestId,
useDb: action.useDb
})
)
}
const parentId = action.parentId || v4()
Expand Down
48 changes: 35 additions & 13 deletions src/shared/modules/commands/commandsDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ describe('commandsDuck', () => {
const cmd = 'RETURN 1'
const id = 2
const requestId = 'xxx'
const action = commands.executeSingleCommand(cmd, id, requestId)
const action = commands.executeSingleCommand(cmd, {
id,
requestId
})
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand Down Expand Up @@ -138,7 +141,9 @@ describe('commandsDuck', () => {
const cmd = store.getState().settings.cmdchar + 'param'
const cmdString = cmd + ' x: 2'
const id = 1
const action = commands.executeSingleCommand(cmdString, id)
const action = commands.executeSingleCommand(cmdString, {
id
})

bus.take('NOOP', currentAction => {
// Then
Expand Down Expand Up @@ -172,7 +177,9 @@ describe('commandsDuck', () => {
const cmd = store.getState().settings.cmdchar + 'param'
const cmdString = cmd + ' x => 2'
const id = 1
const action = commands.executeSingleCommand(cmdString, id)
const action = commands.executeSingleCommand(cmdString, {
id
})
bolt.routedWriteTransaction = jest.fn(() =>
Promise.resolve({
records: [{ get: () => 2 }]
Expand Down Expand Up @@ -205,7 +212,9 @@ describe('commandsDuck', () => {
const cmd = store.getState().settings.cmdchar + 'params'
const cmdString = cmd + ' {x: 2, y: 3}'
const id = 1
const action = commands.executeSingleCommand(cmdString, id)
const action = commands.executeSingleCommand(cmdString, {
id
})
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand All @@ -232,7 +241,9 @@ describe('commandsDuck', () => {
// Given
const cmdString = store.getState().settings.cmdchar + 'params'
const id = 1
const action = commands.executeSingleCommand(cmdString, id)
const action = commands.executeSingleCommand(cmdString, {
id
})
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand All @@ -254,7 +265,9 @@ describe('commandsDuck', () => {
const cmd = store.getState().settings.cmdchar + 'config'
const cmdString = cmd + ' "x": 2'
const id = 1
const action = commands.executeSingleCommand(cmdString, id)
const action = commands.executeSingleCommand(cmdString, {
id
})
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand All @@ -281,7 +294,9 @@ describe('commandsDuck', () => {
const cmd = store.getState().settings.cmdchar + 'config'
const cmdString = cmd + ' {"x": 2, "y":3}'
const id = 1
const action = commands.executeSingleCommand(cmdString, id)
const action = commands.executeSingleCommand(cmdString, {
id
})
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand Down Expand Up @@ -309,7 +324,9 @@ describe('commandsDuck', () => {
const cmd = store.getState().settings.cmdchar + 'config'
const cmdString = cmd
const id = 1
const action = commands.executeSingleCommand(cmdString, id)
const action = commands.executeSingleCommand(cmdString, {
id
})
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand All @@ -336,7 +353,9 @@ describe('commandsDuck', () => {
const cmd = store.getState().settings.cmdchar + 'style'
const cmdString = cmd
const id = 1
const action = commands.executeSingleCommand(cmdString, id)
const action = commands.executeSingleCommand(cmdString, {
id
})
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand All @@ -361,7 +380,7 @@ describe('commandsDuck', () => {
test('does the right thing for list queries', done => {
const cmd = store.getState().settings.cmdchar + 'queries'
const id = 1
const action = commands.executeSingleCommand(cmd, id)
const action = commands.executeSingleCommand(cmd, { id })

bus.take('NOOP', currentAction => {
expect(store.getActions()).toEqual([
Expand All @@ -385,7 +404,10 @@ describe('commandsDuck', () => {
const cmd = comment + '\n' + actualCommand
const id = 2
const requestId = 'xxx'
const action = commands.executeSingleCommand(cmd, id, requestId)
const action = commands.executeSingleCommand(cmd, {
id,
requestId
})
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand Down Expand Up @@ -413,7 +435,7 @@ describe('commandsDuck', () => {
const cmdString = 'history'
const cmd = comment + '\n' + store.getState().settings.cmdchar + cmdString
const id = 1
const action = commands.executeSingleCommand(cmd, id)
const action = commands.executeSingleCommand(cmd, { id })
const cmdChar = store.getState().settings.cmdchar

bus.take('NOOP', currentAction => {
Expand Down Expand Up @@ -441,7 +463,7 @@ describe('commandsDuck', () => {
const serverCmd = 'disconnect'
const cmd = store.getState().settings.cmdchar + 'server ' + serverCmd
const id = 3
const action = commands.executeSingleCommand(cmd, id)
const action = commands.executeSingleCommand(cmd, { id })
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
Expand Down
5 changes: 4 additions & 1 deletion src/shared/modules/commands/cypher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ describe('tx metadata with cypher', () => {
const bus = createBus()
bus.applyReduxMiddleware(createEpicMiddleware(handleSingleCommandEpic))
const $$responseChannel = 'test-channel'
const action = executeSingleCommand('RETURN 1', 'id', 'rqid')
const action = executeSingleCommand('RETURN 1', {
id: 'id',
requestId: 'rqid'
})
action.$$responseChannel = $$responseChannel

bus.send(action.type, action)
Expand Down
3 changes: 2 additions & 1 deletion src/shared/modules/commands/helpers/cypher.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const handleCypherCommand = (
requestId: action.requestId,
cancelable: true,
...txMetadata,
autoCommit
autoCommit,
useDb: action.useDb
}
)
put(send('cypher', id))
Expand Down
10 changes: 7 additions & 3 deletions src/shared/modules/commands/multiCommands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ describe('handleCommandEpic', () => {
const cmd = 'RETURN 1'
const id = 2
const requestId = 'xxx'
const action = commands.executeCommand(cmd, id, requestId)
const action = commands.executeCommand(cmd, { id, requestId })
bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
action,
commands.clearErrorMessage(),
addHistory(action.cmd, maxHistory),
commands.executeSingleCommand(cmd, id, requestId),
commands.executeSingleCommand(cmd, { id, requestId }),
{ type: 'NOOP' }
])
done()
Expand All @@ -94,7 +94,11 @@ describe('handleCommandEpic', () => {
const id = 2
const requestId = 'xxx'
const parentId = 'yyy'
const action = commands.executeCommand(cmd, id, requestId, parentId)
const action = commands.executeCommand(cmd, {
id,
requestId,
parentId
})

bus.take('NOOP', currentAction => {
// Then
Expand Down
Loading