Populate current namespace when getting source
parent
f23417221a
commit
5a73f1fdf0
|
@ -1,6 +1,7 @@
|
||||||
import {Source, Namespace, TimeRange} from 'src/types'
|
import {Source, Namespace, TimeRange} from 'src/types'
|
||||||
import {getSource} from 'src/shared/apis'
|
import {getSource} from 'src/shared/apis'
|
||||||
import {getDatabasesWithRetentionPolicies} from 'src/shared/apis/databases'
|
import {getDatabasesWithRetentionPolicies} from 'src/shared/apis/databases'
|
||||||
|
import {get} from 'src/utils/wrappers'
|
||||||
|
|
||||||
export enum ActionTypes {
|
export enum ActionTypes {
|
||||||
SetSource = 'LOGS_SET_SOURCE',
|
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 response = await getSource(sourceID)
|
||||||
const source = response.data
|
const source = response.data
|
||||||
const namespaces = await getDatabasesWithRetentionPolicies(source.links.proxy)
|
|
||||||
|
|
||||||
dispatch(setSource(source))
|
if (source) {
|
||||||
dispatch(setNamespaces(namespaces))
|
const namespaces = await getDatabasesWithRetentionPolicies(
|
||||||
|
get(source, 'links.proxy', '')
|
||||||
|
)
|
||||||
|
|
||||||
|
if (namespaces && namespaces.length > 0) {
|
||||||
|
dispatch(setNamespace(namespaces[0]))
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(setNamespaces(namespaces))
|
||||||
|
dispatch(setSource(source))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ interface SourceItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
currentNamespace: Namespace
|
||||||
availableSources: Source[]
|
availableSources: Source[]
|
||||||
currentSource: Source | null
|
currentSource: Source | null
|
||||||
currentNamespaces: Namespace[]
|
currentNamespaces: Namespace[]
|
||||||
|
@ -67,11 +68,13 @@ class LogViewerHeader extends PureComponent<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private get selectedNamespace(): string {
|
private get selectedNamespace(): string {
|
||||||
if (_.isEmpty(this.namespaceDropDownItems)) {
|
const {currentNamespace} = this.props
|
||||||
|
|
||||||
|
if (!currentNamespace) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.namespaceDropDownItems[0].text
|
return `${currentNamespace.database}.${currentNamespace.retentionPolicy}`
|
||||||
}
|
}
|
||||||
|
|
||||||
private get namespaceDropDownItems() {
|
private get namespaceDropDownItems() {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import React, {PureComponent} from 'react'
|
import React, {PureComponent} from 'react'
|
||||||
import {connect} from 'react-redux'
|
import {connect} from 'react-redux'
|
||||||
import {bindActionCreators} from 'redux'
|
|
||||||
import {getSourceAsync, setTimeRange, setNamespace} from 'src/logs/actions'
|
import {getSourceAsync, setTimeRange, setNamespace} from 'src/logs/actions'
|
||||||
import {getSourcesAsync} from 'src/shared/actions/sources'
|
import {getSourcesAsync} from 'src/shared/actions/sources'
|
||||||
import {Source, Namespace, TimeRange} from 'src/types'
|
import {Source, Namespace, TimeRange} from 'src/types'
|
||||||
|
@ -10,6 +9,7 @@ interface Props {
|
||||||
sources: Source[]
|
sources: Source[]
|
||||||
currentSource: Source | null
|
currentSource: Source | null
|
||||||
currentNamespaces: Namespace[]
|
currentNamespaces: Namespace[]
|
||||||
|
currentNamespace: Namespace
|
||||||
getSource: (sourceID: string) => void
|
getSource: (sourceID: string) => void
|
||||||
getSources: () => void
|
getSources: () => void
|
||||||
setTimeRange: (timeRange: TimeRange) => void
|
setTimeRange: (timeRange: TimeRange) => void
|
||||||
|
@ -44,7 +44,13 @@ class LogsPage extends PureComponent<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private get header(): JSX.Element {
|
private get header(): JSX.Element {
|
||||||
const {sources, currentSource, currentNamespaces, timeRange} = this.props
|
const {
|
||||||
|
sources,
|
||||||
|
currentSource,
|
||||||
|
currentNamespaces,
|
||||||
|
timeRange,
|
||||||
|
currentNamespace,
|
||||||
|
} = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LogViewerHeader
|
<LogViewerHeader
|
||||||
|
@ -55,6 +61,7 @@ class LogsPage extends PureComponent<Props> {
|
||||||
onChooseTimerange={this.handleChooseTimerange}
|
onChooseTimerange={this.handleChooseTimerange}
|
||||||
currentSource={currentSource}
|
currentSource={currentSource}
|
||||||
currentNamespaces={currentNamespaces}
|
currentNamespaces={currentNamespaces}
|
||||||
|
currentNamespace={currentNamespace}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -84,11 +91,11 @@ const mapStateToProps = ({
|
||||||
currentNamespace,
|
currentNamespace,
|
||||||
})
|
})
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = {
|
||||||
getSource: bindActionCreators(getSourceAsync, dispatch),
|
getSource: getSourceAsync,
|
||||||
getSources: bindActionCreators(getSourcesAsync, dispatch),
|
getSources: getSourcesAsync,
|
||||||
setTimeRange: bindActionCreators(setTimeRange, dispatch),
|
setTimeRange,
|
||||||
setNamespace: bindActionCreators(setNamespace, dispatch),
|
setNamespace,
|
||||||
})
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(LogsPage)
|
export default connect(mapStateToProps, mapDispatchToProps)(LogsPage)
|
||||||
|
|
Loading…
Reference in New Issue