Populate current namespace when getting source

pull/10616/head
Brandon Farmer 2018-05-23 12:11:00 -07:00
parent f23417221a
commit 5a73f1fdf0
3 changed files with 34 additions and 14 deletions

View File

@ -1,6 +1,7 @@
import {Source, Namespace, TimeRange} from 'src/types'
import {getSource} from 'src/shared/apis'
import {getDatabasesWithRetentionPolicies} from 'src/shared/apis/databases'
import {get} from 'src/utils/wrappers'
export enum ActionTypes {
SetSource = 'LOGS_SET_SOURCE',
@ -73,11 +74,20 @@ export const setTimeRange = (timeRange: TimeRange): SetTimeRangeAction => ({
},
})
export const getSourceAsync = sourceID => async dispatch => {
export const getSourceAsync = (sourceID: string) => async dispatch => {
const response = await getSource(sourceID)
const source = response.data
const namespaces = await getDatabasesWithRetentionPolicies(source.links.proxy)
dispatch(setSource(source))
dispatch(setNamespaces(namespaces))
if (source) {
const namespaces = await getDatabasesWithRetentionPolicies(
get(source, 'links.proxy', '')
)
if (namespaces && namespaces.length > 0) {
dispatch(setNamespace(namespaces[0]))
}
dispatch(setNamespaces(namespaces))
dispatch(setSource(source))
}
}

View File

@ -12,6 +12,7 @@ interface SourceItem {
}
interface Props {
currentNamespace: Namespace
availableSources: Source[]
currentSource: Source | null
currentNamespaces: Namespace[]
@ -67,11 +68,13 @@ class LogViewerHeader extends PureComponent<Props> {
}
private get selectedNamespace(): string {
if (_.isEmpty(this.namespaceDropDownItems)) {
const {currentNamespace} = this.props
if (!currentNamespace) {
return ''
}
return this.namespaceDropDownItems[0].text
return `${currentNamespace.database}.${currentNamespace.retentionPolicy}`
}
private get namespaceDropDownItems() {

View File

@ -1,6 +1,5 @@
import React, {PureComponent} from 'react'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import {getSourceAsync, setTimeRange, setNamespace} from 'src/logs/actions'
import {getSourcesAsync} from 'src/shared/actions/sources'
import {Source, Namespace, TimeRange} from 'src/types'
@ -10,6 +9,7 @@ interface Props {
sources: Source[]
currentSource: Source | null
currentNamespaces: Namespace[]
currentNamespace: Namespace
getSource: (sourceID: string) => void
getSources: () => void
setTimeRange: (timeRange: TimeRange) => void
@ -44,7 +44,13 @@ class LogsPage extends PureComponent<Props> {
}
private get header(): JSX.Element {
const {sources, currentSource, currentNamespaces, timeRange} = this.props
const {
sources,
currentSource,
currentNamespaces,
timeRange,
currentNamespace,
} = this.props
return (
<LogViewerHeader
@ -55,6 +61,7 @@ class LogsPage extends PureComponent<Props> {
onChooseTimerange={this.handleChooseTimerange}
currentSource={currentSource}
currentNamespaces={currentNamespaces}
currentNamespace={currentNamespace}
/>
)
}
@ -84,11 +91,11 @@ const mapStateToProps = ({
currentNamespace,
})
const mapDispatchToProps = dispatch => ({
getSource: bindActionCreators(getSourceAsync, dispatch),
getSources: bindActionCreators(getSourcesAsync, dispatch),
setTimeRange: bindActionCreators(setTimeRange, dispatch),
setNamespace: bindActionCreators(setNamespace, dispatch),
})
const mapDispatchToProps = {
getSource: getSourceAsync,
getSources: getSourcesAsync,
setTimeRange,
setNamespace,
}
export default connect(mapStateToProps, mapDispatchToProps)(LogsPage)