From 5de1cc4cb7c9a96a3fc95e75274ec9c778407f30 Mon Sep 17 00:00:00 2001 From: Brandon Farmer Date: Tue, 12 Jun 2018 16:21:53 -0700 Subject: [PATCH] Select default telegraf database --- ui/src/logs/actions/index.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ui/src/logs/actions/index.ts b/ui/src/logs/actions/index.ts index aecc89780f..fa8ac6a897 100644 --- a/ui/src/logs/actions/index.ts +++ b/ui/src/logs/actions/index.ts @@ -427,14 +427,23 @@ export const setTimeRangeAsync = (timeRange: TimeRange) => async ( dispatch(setTableQueryConfigAsync()) } -export const populateNamespacesAsync = (proxyLink: string) => async ( - dispatch -): Promise => { +export const populateNamespacesAsync = ( + proxyLink: string, + source: Source = null +) => async (dispatch): Promise => { const namespaces = await getDatabasesWithRetentionPolicies(proxyLink) if (namespaces && namespaces.length > 0) { dispatch(setNamespaces(namespaces)) - dispatch(setNamespaceAsync(namespaces[0])) + if (source) { + const defaultNamespace = namespaces.find( + namespace => namespace.database === source.telegraf + ) + + dispatch(setNamespaceAsync(defaultNamespace)) + } else { + dispatch(setNamespaceAsync(namespaces[0])) + } } } @@ -448,7 +457,7 @@ export const getSourceAndPopulateNamespacesAsync = (sourceID: string) => async ( if (proxyLink) { dispatch(setSource(source)) - dispatch(populateNamespacesAsync(proxyLink)) + dispatch(populateNamespacesAsync(proxyLink, source)) } }