-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
WIP: [ML] NavMenu conversion to React #39325
Closed
alvarezmelissa87
wants to merge
14
commits into
elastic:master
from
alvarezmelissa87:ml-nav-menu-to-react
Closed
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ae0fad7
Create new react navigation menu directory
alvarezmelissa87 12c83dd
Create TopNav component with SuperDatePicker
alvarezmelissa87 e1d8799
create initial timefilter wrapper class
alvarezmelissa87 886d942
import timefilter wrapper for explorer view
alvarezmelissa87 48a6dc0
wip: topNav subscribes for changes from views
alvarezmelissa87 c273e93
SingleMetricview, chartUtils and anomaliesTableDirective to use timef…
alvarezmelissa87 2c878e0
timefilter wrapper keeps track of legacy events
alvarezmelissa87 4234501
TopNav incorporates timefilter wrapper
alvarezmelissa87 1f02fe4
Controllers use timefilter wrapper subscription method
alvarezmelissa87 0c385e9
use timefilter wrapper in directives, services, utils
alvarezmelissa87 fb462ee
use wrapper's setRefreshInterval subscriber method
alvarezmelissa87 1fb3307
Cleanup and type updates. Set dateFormat for datePicker
alvarezmelissa87 88828eb
ensure refresh watcher handler is triggered
alvarezmelissa87 22b43df
ensure refreshInterval event is passed on
alvarezmelissa87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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 { Subject } from 'rxjs'; | ||
import { timefilter as timefilterDep } from 'ui/timefilter'; | ||
import { RefreshInterval } from 'src/legacy/ui/public/timefilter/timefilter'; | ||
import { TimeRange } from 'src/legacy/ui/public/timefilter/time_history'; | ||
|
||
const timefilterUpdate$ = new Subject(); | ||
const refreshIntervalUpdate$ = new Subject(); | ||
|
||
class MlTimefilter { | ||
constructor() { | ||
// listen for original timefilter emitted events | ||
timefilterDep.on('fetch', this.emitUpdate); // setTime or setRefreshInterval called | ||
timefilterDep.on('refreshIntervalUpdate', this.emitRefreshIntervalUpdate); // setRefreshInterval called | ||
} | ||
|
||
emitUpdate() { | ||
timefilterUpdate$.next(); | ||
} | ||
|
||
emitRefreshIntervalUpdate() { | ||
refreshIntervalUpdate$.next(); | ||
} | ||
|
||
disableAutoRefreshSelector() { | ||
return timefilterDep.disableAutoRefreshSelector(); | ||
} | ||
|
||
disableTimeRangeSelector() { | ||
return timefilterDep.disableTimeRangeSelector(); | ||
} | ||
|
||
enableAutoRefreshSelector() { | ||
return timefilterDep.enableAutoRefreshSelector(); | ||
} | ||
|
||
enableTimeRangeSelector() { | ||
return timefilterDep.enableTimeRangeSelector(); | ||
} | ||
|
||
isAutoRefreshSelectorEnabled() { | ||
return timefilterDep.isAutoRefreshSelectorEnabled; | ||
} | ||
|
||
isTimeRangeSelectorEnabled() { | ||
return timefilterDep.isAutoRefreshSelectorEnabled; | ||
} | ||
|
||
getActiveBounds() { | ||
return timefilterDep.getActiveBounds(); | ||
} | ||
|
||
getRefreshInterval() { | ||
return timefilterDep.getRefreshInterval(); | ||
} | ||
|
||
getTime() { | ||
return timefilterDep.getTime(); | ||
} | ||
|
||
off(event: string) { | ||
timefilterDep.off(event, this.emitRefreshIntervalUpdate); | ||
} | ||
|
||
// in timefilter dependency - 'fetch', 'refreshIntervalUpdate' emitted | ||
setRefreshInterval(interval: RefreshInterval) { | ||
timefilterDep.setRefreshInterval(interval); | ||
} | ||
// in timefilter dependency - 'fetch' is emitted | ||
setTime(time: TimeRange) { | ||
timefilterDep.setTime(time); | ||
} | ||
// consumer must call unsubscribe on return value | ||
subscribeToUpdates(callback: () => void) { | ||
return timefilterUpdate$.subscribe(callback); | ||
} | ||
// consumer must call unsubscribe on return value | ||
subscribeToRefreshIntervalUpdate(callback: () => void) { | ||
return refreshIntervalUpdate$.subscribe(callback); | ||
} | ||
} | ||
|
||
export const timefilter = new MlTimefilter(); |
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
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
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
1 change: 1 addition & 0 deletions
1
x-pack/plugins/ml/public/components/navigation_menu/_index.scss
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 @@ | ||
@import 'navigation_menu' |
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/ml/public/components/navigation_menu/_navigation_menu.scss
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,7 @@ | ||
.mlNavigationMenu__tab { | ||
padding-bottom: 0; | ||
} | ||
|
||
.mlNavigationMenu__topNav { | ||
padding-top: $euiSizeS; | ||
} |
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,7 @@ | ||
/* | ||
* 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 './navigation_menu_react_wrapper_directive'; |
117 changes: 117 additions & 0 deletions
117
x-pack/plugins/ml/public/components/navigation_menu/navigation_menu.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,117 @@ | ||
/* | ||
* 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 React, { Fragment, SFC, useState } from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiTabs, EuiTab } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import chrome from 'ui/chrome'; | ||
import { TopNav } from './top_nav'; | ||
|
||
interface Tab { | ||
id: string; | ||
name: any; | ||
disabled: boolean; | ||
} | ||
|
||
interface Props { | ||
dateFormat: string; | ||
disableLinks: boolean; | ||
showTabs: boolean; | ||
tabId: string; | ||
timeHistory: any; | ||
} | ||
|
||
function moveToSelectedTab(selectedTabId: string) { | ||
window.location.href = `${chrome.getBasePath()}/app/ml#/${selectedTabId}`; | ||
} | ||
|
||
function getTabs(disableLinks: boolean): Tab[] { | ||
return [ | ||
{ | ||
id: 'jobs', | ||
name: i18n.translate('xpack.ml.navMenu.jobManagementTabLinkText', { | ||
defaultMessage: 'Job Management', | ||
}), | ||
disabled: disableLinks, | ||
}, | ||
{ | ||
id: 'explorer', | ||
name: i18n.translate('xpack.ml.navMenu.anomalyExplorerTabLinkText', { | ||
defaultMessage: 'Anomaly Explorer', | ||
}), | ||
disabled: disableLinks, | ||
}, | ||
{ | ||
id: 'timeseriesexplorer', | ||
name: i18n.translate('xpack.ml.navMenu.singleMetricViewerTabLinkText', { | ||
defaultMessage: 'Single Metric Viewer', | ||
}), | ||
disabled: disableLinks, | ||
}, | ||
{ | ||
id: 'data_frames', | ||
name: i18n.translate('xpack.ml.navMenu.dataFrameTabLinkText', { | ||
defaultMessage: 'Data Frames', | ||
}), | ||
disabled: false, | ||
}, | ||
{ | ||
id: 'datavisualizer', | ||
name: i18n.translate('xpack.ml.navMenu.dataVisualizerTabLinkText', { | ||
defaultMessage: 'Data Visualizer', | ||
}), | ||
disabled: false, | ||
}, | ||
{ | ||
id: 'settings', | ||
name: i18n.translate('xpack.ml.navMenu.settingsTabLinkText', { | ||
defaultMessage: 'Settings', | ||
}), | ||
disabled: disableLinks, | ||
}, | ||
]; | ||
} | ||
|
||
export const NavigationMenu: SFC<Props> = ({ | ||
dateFormat, | ||
disableLinks, | ||
showTabs, | ||
tabId, | ||
timeHistory, | ||
}) => { | ||
const [tabs] = useState(getTabs(disableLinks)); | ||
const [selectedTabId, setSelectedTabId] = useState(tabId); | ||
|
||
function onSelectedTabChanged(id: string) { | ||
moveToSelectedTab(id); | ||
setSelectedTabId(id); | ||
} | ||
|
||
function renderTabs() { | ||
return tabs.map((tab: Tab) => ( | ||
<EuiTab | ||
className="mlNavigationMenu__tab" | ||
onClick={() => onSelectedTabChanged(tab.id)} | ||
isSelected={tab.id === selectedTabId} | ||
disabled={tab.disabled} | ||
key={`${tab.id}-key`} | ||
> | ||
{tab.name} | ||
</EuiTab> | ||
)); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<EuiFlexGroup justifyContent="flexEnd" gutterSize="xs" className="mlNavigationMenu__topNav"> | ||
<EuiFlexItem grow={false}> | ||
<TopNav dateFormat={dateFormat} timeHistory={timeHistory} /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
{showTabs && <EuiTabs>{renderTabs()}</EuiTabs>} | ||
</Fragment> | ||
); | ||
}; |
55 changes: 55 additions & 0 deletions
55
...k/plugins/ml/public/components/navigation_menu/navigation_menu_react_wrapper_directive.js
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,55 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { NavigationMenu } from './navigation_menu'; | ||
import { isFullLicense } from '../../license/check_license'; | ||
import { timeHistory } from 'ui/timefilter/time_history'; | ||
import { uiModules } from 'ui/modules'; | ||
const module = uiModules.get('apps/ml'); | ||
|
||
import 'ui/directives/kbn_href'; | ||
|
||
|
||
module.directive('mlNavMenu', function (config) { | ||
return { | ||
restrict: 'E', | ||
transclude: true, | ||
link: function (scope, element, attrs) { | ||
const { name } = attrs; | ||
let showTabs = false; | ||
|
||
if (name === 'jobs' || | ||
name === 'settings' || | ||
name === 'data_frame' || | ||
name === 'datavisualizer' || | ||
name === 'filedatavisualizer' || | ||
name === 'timeseriesexplorer' || | ||
name === 'access-denied' || | ||
name === 'explorer') { | ||
showTabs = true; | ||
} | ||
const props = { | ||
dateFormat: config.get('dateFormat'), | ||
disableLinks: (isFullLicense() === false), | ||
showTabs, | ||
tabId: name, | ||
timeHistory | ||
}; | ||
|
||
ReactDOM.render(React.createElement(NavigationMenu, props), | ||
element[0] | ||
); | ||
|
||
element.on('$destroy', () => { | ||
ReactDOM.unmountComponentAtNode(element[0]); | ||
scope.$destroy(); | ||
}); | ||
} | ||
}; | ||
}); |
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/ml/public/components/navigation_menu/top_nav/index.ts
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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { TopNav } from './top_nav'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 name of this function and
subscribeToRefreshIntervalUpdate
are inconsistent. Maybe just drop thes
to givesubscribeToUpdate
or maybesubscribeToTimeFilterUpdate
?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.
subscribeToUpdates
listens forfetch
being emitted by the timefilter dependency - this happens both on time update and on refreshInterval update while thesubscribeToRefreshIntervalUpdate
only listens for the refreshInterval update event. That's why I had the naming that way.Maybe I can be more explicit?
subscribeToTimeAndRefreshIntervalUpdates
,subscribeToRefreshIntervalUpdate
, maybe if we need to only listen for the time update add asubscribeToTimeUpdate
? That way it will be very clear which events are being listened to? Open to ideas on this.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.
Ah ok, in that case I think
subscribeToUpdates
is fine as it is. Just add a comment clarifying that it happens for both types of update event. Adding asubscribeToTimeUpdate
probably worth adding for completeness.