-
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
* create NavigationMenu and TopNav components * create timefilter wrapper class * update timefilter type file * use new navMenu * use legacy timefilter for initial conversion * remove comments * Move navMenu tabs into separate component * ensure dataFrame tab selected style works * update test * remove top padding when topNav not visible * add refresh button functionality
- Loading branch information
1 parent
2159313
commit 9ba01c9
Showing
16 changed files
with
387 additions
and
8 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
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/legacy/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/legacy/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; | ||
} |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/ml/public/components/navigation_menu/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. | ||
*/ | ||
|
||
import './navigation_menu_react_wrapper_directive'; |
44 changes: 44 additions & 0 deletions
44
x-pack/legacy/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,44 @@ | ||
/* | ||
* 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, FC } from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
import { TopNav } from './top_nav'; | ||
import { Tabs } from './tabs'; | ||
|
||
interface Props { | ||
dateFormat: string; | ||
disableLinks: boolean; | ||
forceRefresh: () => void; | ||
showTabs: boolean; | ||
tabId: string; | ||
timeHistory: any; | ||
timefilter: any; | ||
} | ||
|
||
export const NavigationMenu: FC<Props> = ({ | ||
dateFormat, | ||
disableLinks, | ||
forceRefresh, | ||
showTabs, | ||
tabId, | ||
timeHistory, | ||
timefilter, | ||
}) => ( | ||
<Fragment> | ||
<EuiFlexGroup justifyContent="flexEnd" gutterSize="xs"> | ||
<EuiFlexItem grow={false}> | ||
<TopNav | ||
dateFormat={dateFormat} | ||
timeHistory={timeHistory} | ||
timefilter={timefilter} | ||
forceRefresh={forceRefresh} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
{showTabs && <Tabs tabId={tabId} disableLinks={disableLinks} />} | ||
</Fragment> | ||
); |
63 changes: 63 additions & 0 deletions
63
...y/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,63 @@ | ||
/* | ||
* 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'; | ||
import { timefilter } from 'ui/timefilter'; | ||
import { Subject } from 'rxjs'; | ||
const module = uiModules.get('apps/ml'); | ||
|
||
import 'ui/directives/kbn_href'; | ||
|
||
|
||
module.directive('mlNavMenu', function (config, mlTimefilterRefreshService) { | ||
return { | ||
restrict: 'E', | ||
transclude: true, | ||
link: function (scope, element, attrs) { | ||
const { name } = attrs; | ||
let showTabs = false; | ||
|
||
if (name === 'jobs' || | ||
name === 'settings' || | ||
name === 'data_frames' || | ||
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, | ||
timefilter, | ||
forceRefresh: () => mlTimefilterRefreshService.next() | ||
}; | ||
|
||
ReactDOM.render(React.createElement(NavigationMenu, props), | ||
element[0] | ||
); | ||
|
||
element.on('$destroy', () => { | ||
ReactDOM.unmountComponentAtNode(element[0]); | ||
scope.$destroy(); | ||
}); | ||
} | ||
}; | ||
}) | ||
.service('mlTimefilterRefreshService', function () { | ||
return new Subject(); | ||
}); |
112 changes: 112 additions & 0 deletions
112
x-pack/legacy/plugins/ml/public/components/navigation_menu/tabs.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,112 @@ | ||
/* | ||
* 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, { FC, useState } from 'react'; | ||
import { EuiTabs, EuiTab } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import chrome from 'ui/chrome'; | ||
|
||
interface Tab { | ||
id: string; | ||
name: any; | ||
disabled: boolean; | ||
} | ||
|
||
interface TestSubjMap { | ||
[key: string]: string; | ||
} | ||
|
||
interface Props { | ||
disableLinks: boolean; | ||
tabId: string; | ||
} | ||
|
||
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, | ||
}, | ||
]; | ||
} | ||
|
||
const TAB_TEST_SUBJ_MAP: TestSubjMap = { | ||
jobs: 'mlTabJobManagement', | ||
explorer: 'mlTabAnomalyExplorer', | ||
timeseriesexplorer: 'mlTabSingleMetricViewer', | ||
data_frames: 'mlTabDataFrames', | ||
datavisualizer: 'mlTabDataVisualizer', | ||
settings: 'mlTabSettings', | ||
}; | ||
|
||
function moveToSelectedTab(selectedTabId: string) { | ||
window.location.href = `${chrome.getBasePath()}/app/ml#/${selectedTabId}`; | ||
} | ||
|
||
export const Tabs: FC<Props> = ({ tabId, disableLinks }) => { | ||
const [selectedTabId, setSelectedTabId] = useState(tabId); | ||
function onSelectedTabChanged(id: string) { | ||
moveToSelectedTab(id); | ||
setSelectedTabId(id); | ||
} | ||
|
||
const tabs = getTabs(disableLinks); | ||
|
||
return ( | ||
<EuiTabs> | ||
{tabs.map((tab: Tab) => ( | ||
<EuiTab | ||
className="mlNavigationMenu__tab" | ||
onClick={() => onSelectedTabChanged(tab.id)} | ||
isSelected={tab.id === selectedTabId} | ||
disabled={tab.disabled} | ||
key={`${tab.id}-key`} | ||
data-test-subj={TAB_TEST_SUBJ_MAP[tab.id]} | ||
> | ||
{tab.name} | ||
</EuiTab> | ||
))} | ||
</EuiTabs> | ||
); | ||
}; |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/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'; |
108 changes: 108 additions & 0 deletions
108
x-pack/legacy/plugins/ml/public/components/navigation_menu/top_nav/top_nav.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,108 @@ | ||
/* | ||
* 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, { FC, Fragment, useState, useEffect } from 'react'; | ||
import { EuiSuperDatePicker } from '@elastic/eui'; | ||
import { TimeHistory, TimeRange } from 'src/legacy/ui/public/timefilter/time_history'; | ||
import { Timefilter } from 'ui/timefilter'; | ||
|
||
interface Props { | ||
dateFormat: string; | ||
forceRefresh: () => void; | ||
timeHistory: TimeHistory; | ||
timefilter: Timefilter; | ||
} | ||
|
||
function getRecentlyUsedRanges(timeHistory: TimeHistory): Array<{ start: string; end: string }> { | ||
return timeHistory.get().map(({ from, to }: TimeRange) => { | ||
return { | ||
start: from, | ||
end: to, | ||
}; | ||
}); | ||
} | ||
|
||
export const TopNav: FC<Props> = ({ dateFormat, forceRefresh, timeHistory, timefilter }) => { | ||
const [refreshInterval, setRefreshInterval] = useState(timefilter.getRefreshInterval()); | ||
const [time, setTime] = useState(timefilter.getTime()); | ||
const [recentlyUsedRanges, setRecentlyUsedRanges] = useState(getRecentlyUsedRanges(timeHistory)); | ||
const [isAutoRefreshSelectorEnabled, setIsAutoRefreshSelectorEnabled] = useState( | ||
timefilter.isAutoRefreshSelectorEnabled | ||
); | ||
const [isTimeRangeSelectorEnabled, setIsTimeRangeSelectorEnabled] = useState( | ||
timefilter.isTimeRangeSelectorEnabled | ||
); | ||
|
||
useEffect(() => { | ||
timefilter.on('refreshIntervalUpdate', timefilterUpdateListener); | ||
timefilter.on('timeUpdate', timefilterUpdateListener); | ||
timefilter.on('enabledUpdated', timefilterUpdateListener); | ||
|
||
return function cleanup() { | ||
timefilter.off('refreshIntervalUpdate', timefilterUpdateListener); | ||
timefilter.off('timeUpdate', timefilterUpdateListener); | ||
timefilter.off('enabledUpdated', timefilterUpdateListener); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
// Force re-render with up-to-date values when isTimeRangeSelectorEnabled/isAutoRefreshSelectorEnabled are changed. | ||
timefilterUpdateListener(); | ||
}, [isTimeRangeSelectorEnabled, isAutoRefreshSelectorEnabled]); | ||
|
||
function timefilterUpdateListener() { | ||
setTime(timefilter.getTime()); | ||
setRefreshInterval(timefilter.getRefreshInterval()); | ||
setIsAutoRefreshSelectorEnabled(timefilter.isAutoRefreshSelectorEnabled); | ||
setIsTimeRangeSelectorEnabled(timefilter.isTimeRangeSelectorEnabled); | ||
} | ||
|
||
function updateFilter({ start, end }: { start: string; end: string }) { | ||
const newTime = { from: start, to: end }; | ||
// Update timefilter for controllers listening for changes | ||
timefilter.setTime(newTime); | ||
setTime(newTime); | ||
setRecentlyUsedRanges(getRecentlyUsedRanges(timeHistory)); | ||
} | ||
|
||
function updateInterval({ | ||
isPaused, | ||
refreshInterval: interval, | ||
}: { | ||
isPaused: boolean; | ||
refreshInterval: number; | ||
}) { | ||
const newInterval = { | ||
pause: isPaused, | ||
value: interval, | ||
}; | ||
// Update timefilter for controllers listening for changes | ||
timefilter.setRefreshInterval(newInterval); | ||
// Update state | ||
setRefreshInterval(newInterval); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
{(isAutoRefreshSelectorEnabled || isTimeRangeSelectorEnabled) && ( | ||
<div className="mlNavigationMenu__topNav"> | ||
<EuiSuperDatePicker | ||
start={time.from} | ||
end={time.to} | ||
isPaused={refreshInterval.pause} | ||
isAutoRefreshOnly={!isTimeRangeSelectorEnabled} | ||
refreshInterval={refreshInterval.value} | ||
onTimeChange={updateFilter} | ||
onRefresh={forceRefresh} | ||
onRefreshChange={updateInterval} | ||
recentlyUsedRanges={recentlyUsedRanges} | ||
dateFormat={dateFormat} | ||
/> | ||
</div> | ||
)} | ||
</Fragment> | ||
); | ||
}; |
Oops, something went wrong.