-
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
[Dashboard] Deangularize Nav Bar #55443
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2292391
First version of moving navbar to React
c57762b
Refactor search bar logic a bit
34e32b2
Remove setting of popover own focus
7b6787f
Removing setting of absolute time range
09a463f
Execute query as soon as saved query is updated
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
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import _, { uniq } from 'lodash'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import angular from 'angular'; | ||
|
||
import { Subscription } from 'rxjs'; | ||
|
@@ -44,6 +45,7 @@ import { | |
SavedQuery, | ||
syncAppFilters, | ||
syncQuery, | ||
TimeRange, | ||
} from '../../../../../../plugins/data/public'; | ||
|
||
import { | ||
|
@@ -83,12 +85,14 @@ import { | |
removeQueryParam, | ||
unhashUrl, | ||
} from '../../../../../../plugins/kibana_utils/public'; | ||
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../../plugins/navigation/public'; | ||
|
||
export interface DashboardAppControllerDependencies extends RenderDeps { | ||
$scope: DashboardAppScope; | ||
$route: any; | ||
$routeParams: any; | ||
indexPatterns: IndexPatternsContract; | ||
navigation: NavigationStart; | ||
dashboardConfig: any; | ||
config: any; | ||
confirmModal: ConfirmModalFn; | ||
|
@@ -119,6 +123,7 @@ export class DashboardAppController { | |
core: { notifications, overlays, chrome, injectedMetadata, uiSettings, savedObjects, http }, | ||
history, | ||
kbnUrlStateStorage, | ||
navigation, | ||
}: DashboardAppControllerDependencies) { | ||
const filterManager = queryService.filterManager; | ||
const queryFilter = filterManager; | ||
|
@@ -183,7 +188,6 @@ export class DashboardAppController { | |
if (!container || isErrorEmbeddable(container)) { | ||
return; | ||
} | ||
|
||
let panelIndexPatterns: IndexPattern[] = []; | ||
Object.values(container.getChildIds()).forEach(id => { | ||
const embeddable = container.getChild(id); | ||
|
@@ -261,6 +265,41 @@ export class DashboardAppController { | |
}; | ||
}; | ||
|
||
$scope.showFilterBar = () => | ||
$scope.model.filters.length > 0 || !dashboardStateManager.getFullScreenMode(); | ||
|
||
const getNavBarProps = () => { | ||
const isFullScreenMode = dashboardStateManager.getFullScreenMode(); | ||
return { | ||
appName: 'dashboard', | ||
config: isFullScreenMode ? undefined : $scope.topNavMenu, | ||
showSearchBar: !isFullScreenMode, | ||
showFilterBar: $scope.showFilterBar() && !isFullScreenMode, | ||
showSaveQuery: $scope.showSaveQuery, | ||
noPadding: isFullScreenMode, | ||
query: $scope.model.query, | ||
savedQuery: $scope.savedQuery, | ||
screenTitle: $scope.screenTitle, | ||
onQuerySubmit: (payload: { dateRange: TimeRange; query?: Query }): void => { | ||
if (!payload.query) { | ||
$scope.updateQueryAndFetch({ query: $scope.model.query, dateRange: payload.dateRange }); | ||
} else { | ||
$scope.updateQueryAndFetch({ query: payload.query, dateRange: payload.dateRange }); | ||
} | ||
}, | ||
indexPatterns: $scope.indexPatterns, | ||
filters: $scope.model.filters, | ||
onFiltersUpdated: $scope.onFiltersUpdated, | ||
isRefreshPaused: $scope.model.refreshInterval.pause, | ||
refreshInterval: $scope.model.refreshInterval.value, | ||
onSaved: $scope.onQuerySaved, | ||
onSavedQueryUpdated: $scope.onSavedQueryUpdated, | ||
onClearSavedQuery: $scope.onClearSavedQuery, | ||
onRefreshChange: $scope.onRefreshChange, | ||
timeHistory: queryService.timefilter.history, | ||
}; | ||
}; | ||
const dashboardNavBar = document.getElementById('dashboardChrome'); | ||
const updateState = () => { | ||
// Following the "best practice" of always have a '.' in your ng-models – | ||
// https://github.com/angular/angular.js/wiki/Understanding-Scopes | ||
|
@@ -277,13 +316,19 @@ export class DashboardAppController { | |
$scope.screenTitle = dashboardStateManager.getTitle(); | ||
}; | ||
|
||
const updateNavBar = () => { | ||
ReactDOM.render(<navigation.ui.TopNavMenu {...getNavBarProps()} />, dashboardNavBar); | ||
}; | ||
|
||
updateState(); | ||
updateNavBar(); | ||
|
||
let dashboardContainer: DashboardContainer | undefined; | ||
let inputSubscription: Subscription | undefined; | ||
let outputSubscription: Subscription | undefined; | ||
|
||
const dashboardDom = document.getElementById('dashboardViewport'); | ||
|
||
const dashboardFactory = embeddables.getEmbeddableFactory( | ||
DASHBOARD_CONTAINER_TYPE | ||
) as DashboardContainerFactory; | ||
|
@@ -335,6 +380,7 @@ export class DashboardAppController { | |
$scope.$evalAsync(() => { | ||
if (dirty) { | ||
updateState(); | ||
updateNavBar(); | ||
} | ||
}); | ||
}); | ||
|
@@ -370,6 +416,7 @@ export class DashboardAppController { | |
dashboardStateManager.registerChangeListener(status => { | ||
this.appStatus.dirty = status.dirty || !dash.id; | ||
updateState(); | ||
updateNavBar(); | ||
}); | ||
|
||
dashboardStateManager.applyFilters( | ||
|
@@ -448,22 +495,25 @@ export class DashboardAppController { | |
} | ||
}; | ||
|
||
$scope.updateQueryAndFetch = function({ query, dateRange }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here - seems like this is only used from within react |
||
$scope.updateQueryAndFetch = function(payload) { | ||
const dateRange = payload.dateRange; | ||
const newQuery = payload.query; | ||
if (dateRange) { | ||
timefilter.setTime(dateRange); | ||
} | ||
|
||
const oldQuery = $scope.model.query; | ||
if (_.isEqual(oldQuery, query)) { | ||
if (_.isEqual(oldQuery, newQuery)) { | ||
// The user can still request a reload in the query bar, even if the | ||
// query is the same, and in that case, we have to explicitly ask for | ||
// a reload, since no state changes will cause it. | ||
lastReloadRequestTime = new Date().getTime(); | ||
refreshDashboardContainer(); | ||
} else { | ||
$scope.model.query = query; | ||
$scope.model.query = newQuery; | ||
dashboardStateManager.applyFilters($scope.model.query, $scope.model.filters); | ||
} | ||
updateNavBar(); | ||
}; | ||
|
||
$scope.onRefreshChange = function({ isPaused, refreshInterval }) { | ||
|
@@ -480,14 +530,17 @@ export class DashboardAppController { | |
|
||
$scope.onQuerySaved = savedQuery => { | ||
$scope.savedQuery = savedQuery; | ||
updateNavBar(); | ||
}; | ||
|
||
$scope.onSavedQueryUpdated = savedQuery => { | ||
$scope.savedQuery = { ...savedQuery }; | ||
updateStateFromSavedQuery(savedQuery); | ||
}; | ||
|
||
$scope.onClearSavedQuery = () => { | ||
delete $scope.savedQuery; | ||
delete $scope.model.query; | ||
dashboardStateManager.setSavedQueryId(undefined); | ||
dashboardStateManager.applyFilters( | ||
{ | ||
|
@@ -497,11 +550,10 @@ export class DashboardAppController { | |
}, | ||
queryFilter.getGlobalFilters() | ||
); | ||
// Making this method sync broke the updates. | ||
// Temporary fix, until we fix the complex state in this file. | ||
setTimeout(() => { | ||
queryFilter.setFilters(queryFilter.getGlobalFilters()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you do a replace all of |
||
}, 0); | ||
updateNavBar(); | ||
}; | ||
|
||
const updateStateFromSavedQuery = (savedQuery: SavedQuery) => { | ||
|
@@ -521,18 +573,20 @@ export class DashboardAppController { | |
} | ||
// Making this method sync broke the updates. | ||
// Temporary fix, until we fix the complex state in this file. | ||
setTimeout(() => { | ||
queryFilter.setFilters(allFilters); | ||
}, 0); | ||
queryFilter.setFilters(allFilters); | ||
updateNavBar(); | ||
}; | ||
|
||
$scope.$watch('savedQuery', (newSavedQuery: SavedQuery) => { | ||
if (!newSavedQuery) return; | ||
dashboardStateManager.setSavedQueryId(newSavedQuery.id); | ||
|
||
updateStateFromSavedQuery(newSavedQuery); | ||
}); | ||
|
||
$scope.$watch('indexPatterns', () => { | ||
updateNavBar(); | ||
}); | ||
|
||
$scope.$watch( | ||
() => { | ||
return dashboardStateManager.getSavedQueryId(); | ||
|
@@ -556,8 +610,8 @@ export class DashboardAppController { | |
$scope.indexPatterns = []; | ||
|
||
$scope.$watch('model.query', (newQuery: Query) => { | ||
const query = migrateLegacyQuery(newQuery) as Query; | ||
$scope.updateQueryAndFetch({ query }); | ||
const legacyQuery = migrateLegacyQuery(newQuery) as Query; | ||
$scope.updateQueryAndFetch({ query: legacyQuery }); | ||
}); | ||
|
||
$scope.$watch( | ||
|
@@ -574,6 +628,7 @@ export class DashboardAppController { | |
next: () => { | ||
updateState(); | ||
refreshDashboardContainer(); | ||
updateNavBar(); | ||
}, | ||
}) | ||
); | ||
|
@@ -583,6 +638,7 @@ export class DashboardAppController { | |
next: () => { | ||
updateState(); | ||
refreshDashboardContainer(); | ||
updateNavBar(); | ||
}, | ||
}) | ||
); | ||
|
@@ -703,9 +759,6 @@ export class DashboardAppController { | |
}); | ||
} | ||
|
||
$scope.showFilterBar = () => | ||
$scope.model.filters.length > 0 || !dashboardStateManager.getFullScreenMode(); | ||
|
||
$scope.showAddPanel = () => { | ||
dashboardStateManager.setFullScreenMode(false); | ||
/* | ||
|
@@ -768,7 +821,6 @@ export class DashboardAppController { | |
return response; | ||
}); | ||
}; | ||
|
||
const dashboardSaveModal = ( | ||
<DashboardSaveModal | ||
onSave={onSave} | ||
|
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.
Do we need to put this on the scope? Seems like it not used anymore from within angular