Load external links from /chronograf/v1 into Redux

pull/10616/head
Jared Scheib 2017-06-13 16:25:12 -07:00
parent f63cba3581
commit 4369be7b17
6 changed files with 44 additions and 11 deletions

View File

@ -36,6 +36,7 @@ import {
meReceived,
logoutLinkReceived,
} from 'shared/actions/auth'
import {linksReceived} from 'shared/actions/links'
import {errorThrown} from 'shared/actions/errors'
import 'src/style/chronograf.scss'
@ -87,11 +88,13 @@ const Root = React.createClass({
async startHeartbeat({shouldDispatchResponse}) {
try {
const {data: me, auth, logoutLink} = await getMe()
// These non-me objects are added to every response by some AJAX trickery
const {data: me, auth, logoutLink, external} = await getMe()
if (shouldDispatchResponse) {
dispatch(authReceived(auth))
dispatch(meReceived(me))
dispatch(logoutLinkReceived(logoutLink))
dispatch(linksReceived({external}))
}
setTimeout(() => {

View File

@ -0,0 +1,6 @@
import * as actionTypes from 'shared/constants/actionTypes'
export const linksReceived = links => ({
type: actionTypes.LINKS_RECEIVED,
payload: {links},
})

View File

@ -1 +1,3 @@
export const TEMPLATE_VARIABLE_SELECTED = 'TEMPLATE_VARIABLE_SELECTED'
export const LINKS_RECEIVED = 'LINKS_RECEIVED'

View File

@ -1,6 +1,7 @@
import app from './app'
import auth from './auth'
import errors from './errors'
import links from './links'
import notifications from './notifications'
import sources from './sources'
@ -8,6 +9,7 @@ export default {
app,
auth,
errors,
links,
notifications,
sources,
}

View File

@ -0,0 +1,21 @@
import * as actionTypes from 'shared/constants/actionTypes'
const initialState = {
external: {},
}
const linksReducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.LINKS_RECEIVED: {
const {links} = action.payload
return links
}
default: {
return state
}
}
}
export default linksReducer

View File

@ -2,6 +2,13 @@ import axios from 'axios'
let links
const generateResponseWithLinks = (response, {auth, logout, external}) => ({
...response,
auth: {links: auth},
logoutLink: logout,
external,
})
const AJAX = async ({
url,
resource,
@ -39,19 +46,11 @@ const AJAX = async ({
headers,
})
const {auth} = links
return {
...response,
auth: {links: auth},
logoutLink: links.logout,
}
return generateResponseWithLinks(response, links)
} catch (error) {
const {response} = error
const {auth} = links
throw {...response, auth: {links: auth}, logoutLink: links.logout} // eslint-disable-line no-throw-literal
throw generateResponseWithLinks(response, links) // eslint-disable-line no-throw-literal
}
}