-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
These changes make the map work better with auto-refresh and with dragged nodes. Extract all event handling out of the Cytoscape component into a hook. Use React.memo to only render when the list of element ids has changed. Only do a fit on the layout if we're going from 0 to more than 0 elements. Instead of removing all the nodes on rerender, only remove the ones that aren't in the new list. Trigger a custom:data event instead of data when we receive fetched data. Before we triggered a data event which would trigger a layout if you called data() on an element. Don't trigger a deselect when we get new data, so popovers stay open when we get new data. Animate the layout on changes. When we do a layout, exclude selected nodes and nodes that have been dragged. When we set the time range to something low (like the default of 15m) and a fast refresh interval (1-3s) the edges we get back from the API are not consistent, so you can see the map changing frequently. See this video for an example: https://www.dropbox.com/s/jsq2bffxdw61xhu/77132.mov?dl=0 Fixes #73156. Fixes #76936.
- Loading branch information
Showing
4 changed files
with
299 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
x-pack/plugins/apm/public/components/app/ServiceMap/use_cytoscape_event_handlers.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { renderHook } from '@testing-library/react-hooks'; | ||
import cytoscape from 'cytoscape'; | ||
import { EuiTheme } from '../../../../../observability/public'; | ||
import { useCytoscapeEventHandlers } from './use_cytoscape_event_handlers'; | ||
import dagre from 'cytoscape-dagre'; | ||
|
||
cytoscape.use(dagre); | ||
|
||
const theme = ({ | ||
eui: { avatarSizing: { l: { size: 10 } } }, | ||
} as unknown) as EuiTheme; | ||
|
||
describe('useCytoscapeEventHandlers', () => { | ||
describe('when cytoscape is undefined', () => { | ||
it('runs', () => { | ||
expect(() => { | ||
renderHook(() => useCytoscapeEventHandlers({ cy: undefined, theme })); | ||
}).not.toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('when an element is dragged', () => { | ||
it('sets the hasBeenDragged data', () => { | ||
const cy = cytoscape({ elements: [{ data: { id: 'test' } }] }); | ||
|
||
renderHook(() => useCytoscapeEventHandlers({ cy, theme })); | ||
cy.getElementById('test').trigger('drag'); | ||
|
||
expect(cy.getElementById('test').data('hasBeenDragged')).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when a node is hovered', () => { | ||
it('applies the hover class', () => { | ||
const cy = cytoscape({ | ||
elements: [{ data: { id: 'test' } }], | ||
}); | ||
const node = cy.getElementById('test'); | ||
|
||
renderHook(() => useCytoscapeEventHandlers({ cy, theme })); | ||
node.trigger('mouseover'); | ||
|
||
expect(node.hasClass('hover')).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when a node is un-hovered', () => { | ||
it('removes the hover class', () => { | ||
const cy = cytoscape({ | ||
elements: [{ data: { id: 'test' }, classes: 'hover' }], | ||
}); | ||
const node = cy.getElementById('test'); | ||
|
||
renderHook(() => useCytoscapeEventHandlers({ cy, theme })); | ||
node.trigger('mouseout'); | ||
|
||
expect(node.hasClass('hover')).toEqual(false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.