-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[ML] explorer controller refactor #28750
[ML] explorer controller refactor #28750
Conversation
Pinging @elastic/ml-ui |
💔 Build Failed |
💔 Build Failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
💔 Build Failed |
💔 Build Failed |
💚 Build Succeeded |
💚 Build Succeeded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest changes LGTM!
…howing an empty view.
💔 Build Failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added a few nitpicks, feel free to ignore
stateUpdate.swimlaneViewByFieldName = VIEW_BY_JOB_LABEL; | ||
// enforce a state update for swimlaneViewByFieldName | ||
this.setState({ swimlaneViewByFieldName: VIEW_BY_JOB_LABEL }, () => { | ||
this.updateExplorer(stateUpdate, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistency nitpick - you're using stateUpdate
which has been updated with Object.assign
here, but a few lines down are creating the object on the fly using the spread operator.
Looks to me like either could be used, it would be good to be consistent. I'm pretty sure kibana's style guide used to have a rule about not using Object.assign
but i can't find it anymore.
const { dateFormatTz } = this.props; | ||
const { selectedCells, swimlaneViewByFieldName, selectedJobs } = this.state; | ||
this.setState({ | ||
tableData: await loadAnomaliesTableData( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, IMO this would read better if you created a tableData
variable just above the setState
call.
Personal preferences and all that, so ignore if you disagree
state = getExplorerDefaultState(); | ||
|
||
// helper to avoid calling `setState()` in the listener for chart updates. | ||
_isMounted = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only variable to start with an underscore, is this to designate its insignificance?
this.dragSelect.setSelectables(document.getElementsByClassName('sl-cell')); | ||
}; | ||
|
||
componentDidMount() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, i would normally expect to see the componentDidMount
function towards the top of the class
|
||
const currentSwimlaneType = _.get(this.state, 'selectedCells.type'); | ||
const currentShowTopFieldValues = _.get(this.state, 'selectedCells.showTopFieldValues', false); | ||
const newSwimlaneType = _.get(swimlaneSelectedCells, 'type'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, this could just be swimlaneSelectedCells.type
💚 Build Succeeded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ⚡️
Refactores the application logic of Anomaly Explorer to reduce relying on angularjs.
💚 Build Succeeded |
This was missed during the recent migrations to React of Anomaly Explorer in elastic#28750. It removes the now unnecessary `$scope.indexPatterns`.
This was missed during the recent migrations to React of Anomaly Explorer in #28750. It removes the now unnecessary `$scope.indexPatterns`.
This was missed during the recent migrations to React of Anomaly Explorer in elastic#28750. It removes the now unnecessary `$scope.indexPatterns`.
This was missed during the recent migrations to React of Anomaly Explorer in elastic#28750. It removes the now unnecessary `$scope.indexPatterns`.
This was missed during the recent migrations to React of Anomaly Explorer in elastic#28750. It removes the now unnecessary `$scope.indexPatterns`.
Summary
Refactors the application logic of Anomaly Explorer to reduce relying on angularjs. The updated event handling looks like this:
explorer_controller.js
has been reduced to a bare wrapper. All that's left is$scope
that's still necessary for now (e.g.jobs
because of the job selector) and related events.explorer_utils.js
is a collection of functions previously housed in inline inexplorer_controller.js
. The function have been refactored to be more pure so they don't rely on outer state so they work stand-alone. This new structure will allow us to write unit tests for these functions in a follow up.explorer_react_wrapper_directive.js
no longer needs to pass through that much$scope
fromexplorer_controller.js
, it's now really just a shallow wrapper that passed through some props without applying further transformation.explorer.js
replaced most ofexplorer.html
in a previous PR. Now it also includes previous methods fromexplorer_controller.js
which managed angularjs$scope
, but these methods have been refactored to manage Reactstate
.Further updates 22.01.2019:
explorer.js
state handling to be much more cleaned up and uni-directional. Data fetching andsetState()
is no longer in all kinds of different places, instead depending on actions (e.g. restoring a selection on reload, switching jobs, clicking on a cell) astateUpdate
update is prepared and passed on toupdateExplorer()
. Depending onstateUpdate
(e.g. active Selection or not)updateExplorer()
fetches necessary data and triggerssetState()
where appropriate. This results in much lesserrender()
calls and solves another race condition.loadOverallData()
is now only used 1 instead of 3 times throughout the code base,loadViewBySwimlaneData()
is used 2 times instead of 6 times.loadOverallData()
orloadViewBySwimlaneData()
now feature a simple caching/memoizing capability. This is useful for example when the view is just resized, then the existing data doesn't need to be fetched again from the server. Instead of more complex state handling which tries to find out if for exampleloadOverallData()
would need to be called again, using memoization the method can be just called again and acts as a state getter if the related method arguments didn't change.Review Checklist
AppState
. 031e176Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n supportDocumentation was added for features that require explanation or tutorialsThis was checked for keyboard-only and screenreader accessibilityFor maintainers
This includes a feature addition or change that requires a release note and was labeled appropriatelyPart of #18553 and #18374.