Merge pull request #1842 from influxdata/dataLoaders/multiple-value-config
Fix(ui/dataLoaders): Update config field modifierspull/10616/head
commit
551a2fc3ab
|
@ -12,7 +12,7 @@ import {Links} from 'src/types/v2/links'
|
||||||
import {Task, TaskStatus} from 'src/types/v2/tasks'
|
import {Task, TaskStatus} from 'src/types/v2/tasks'
|
||||||
import {OnboardingStepProps} from 'src/onboarding/containers/OnboardingWizard'
|
import {OnboardingStepProps} from 'src/onboarding/containers/OnboardingWizard'
|
||||||
import {ConfigurationState} from 'src/types/v2/dataLoaders'
|
import {ConfigurationState} from 'src/types/v2/dataLoaders'
|
||||||
import {TelegrafPluginInputCpu} from 'src/api'
|
import {TelegrafPluginInputCpu, TelegrafPluginInputRedis} from 'src/api'
|
||||||
|
|
||||||
export const links: Links = {
|
export const links: Links = {
|
||||||
authorizations: '/api/v2/authorizations',
|
authorizations: '/api/v2/authorizations',
|
||||||
|
@ -292,6 +292,15 @@ export const telegrafPlugin = {
|
||||||
active: true,
|
active: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const redisPlugin = {
|
||||||
|
name: TelegrafPluginInputRedis.NameEnum.Redis,
|
||||||
|
type: TelegrafPluginInputRedis.TypeEnum.Input,
|
||||||
|
config: {
|
||||||
|
servers: [],
|
||||||
|
password: '',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
export const influxDB2Plugin = {
|
export const influxDB2Plugin = {
|
||||||
name: 'influxdb_v2',
|
name: 'influxdb_v2',
|
||||||
type: 'output',
|
type: 'output',
|
||||||
|
|
|
@ -8,14 +8,26 @@ import dataLoadersReducer, {
|
||||||
import {
|
import {
|
||||||
setDataLoadersType,
|
setDataLoadersType,
|
||||||
addTelegrafPlugin,
|
addTelegrafPlugin,
|
||||||
|
addConfigValue,
|
||||||
|
removeConfigValue,
|
||||||
removeTelegrafPlugin,
|
removeTelegrafPlugin,
|
||||||
setActiveTelegrafPlugin,
|
setActiveTelegrafPlugin,
|
||||||
setTelegrafConfigID,
|
setTelegrafConfigID,
|
||||||
|
updateTelegrafPluginConfig,
|
||||||
} from 'src/onboarding/actions/dataLoaders'
|
} from 'src/onboarding/actions/dataLoaders'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {TelegrafPluginInputCpu, TelegrafPluginInputDisk} from 'src/api'
|
import {
|
||||||
import {DataLoaderType, ConfigurationState} from 'src/types/v2/dataLoaders'
|
TelegrafPluginInputCpu,
|
||||||
|
TelegrafPluginInputDisk,
|
||||||
|
TelegrafPluginInputRedis,
|
||||||
|
} from 'src/api'
|
||||||
|
import {
|
||||||
|
DataLoaderType,
|
||||||
|
ConfigurationState,
|
||||||
|
TelegrafPlugin,
|
||||||
|
} from 'src/types/v2/dataLoaders'
|
||||||
|
import {redisPlugin} from 'mocks/dummyData'
|
||||||
|
|
||||||
describe('dataLoader reducer', () => {
|
describe('dataLoader reducer', () => {
|
||||||
it('can set a type', () => {
|
it('can set a type', () => {
|
||||||
|
@ -129,4 +141,112 @@ describe('dataLoader reducer', () => {
|
||||||
|
|
||||||
expect(actual).toEqual(expected)
|
expect(actual).toEqual(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can update a plugin config field', () => {
|
||||||
|
const plugin = {
|
||||||
|
...redisPlugin,
|
||||||
|
config: {servers: [], password: ''},
|
||||||
|
}
|
||||||
|
const tp: TelegrafPlugin = {
|
||||||
|
name: TelegrafPluginInputRedis.NameEnum.Redis,
|
||||||
|
configured: ConfigurationState.Unconfigured,
|
||||||
|
active: true,
|
||||||
|
plugin,
|
||||||
|
}
|
||||||
|
const actual = dataLoadersReducer(
|
||||||
|
{...INITIAL_STATE, telegrafPlugins: [tp]},
|
||||||
|
updateTelegrafPluginConfig(
|
||||||
|
TelegrafPluginInputRedis.NameEnum.Redis,
|
||||||
|
'password',
|
||||||
|
'pa$$w0rd'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
...INITIAL_STATE,
|
||||||
|
telegrafPlugins: [
|
||||||
|
{
|
||||||
|
...tp,
|
||||||
|
plugin: {
|
||||||
|
...plugin,
|
||||||
|
config: {servers: [], password: 'pa$$w0rd'},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(actual).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can add a plugin config value', () => {
|
||||||
|
const plugin = {
|
||||||
|
...redisPlugin,
|
||||||
|
config: {servers: ['first'], password: ''},
|
||||||
|
}
|
||||||
|
const tp: TelegrafPlugin = {
|
||||||
|
name: TelegrafPluginInputRedis.NameEnum.Redis,
|
||||||
|
configured: ConfigurationState.Unconfigured,
|
||||||
|
active: true,
|
||||||
|
plugin,
|
||||||
|
}
|
||||||
|
const actual = dataLoadersReducer(
|
||||||
|
{...INITIAL_STATE, telegrafPlugins: [tp]},
|
||||||
|
addConfigValue(
|
||||||
|
TelegrafPluginInputRedis.NameEnum.Redis,
|
||||||
|
'servers',
|
||||||
|
'second'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
...INITIAL_STATE,
|
||||||
|
telegrafPlugins: [
|
||||||
|
{
|
||||||
|
...tp,
|
||||||
|
plugin: {
|
||||||
|
...plugin,
|
||||||
|
config: {servers: ['first', 'second'], password: ''},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(actual).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can remove a plugin config value', () => {
|
||||||
|
const plugin = {
|
||||||
|
...redisPlugin,
|
||||||
|
config: {servers: ['first', 'second'], password: ''},
|
||||||
|
}
|
||||||
|
const tp: TelegrafPlugin = {
|
||||||
|
name: TelegrafPluginInputRedis.NameEnum.Redis,
|
||||||
|
configured: ConfigurationState.Unconfigured,
|
||||||
|
active: true,
|
||||||
|
plugin,
|
||||||
|
}
|
||||||
|
const actual = dataLoadersReducer(
|
||||||
|
{...INITIAL_STATE, telegrafPlugins: [tp]},
|
||||||
|
removeConfigValue(
|
||||||
|
TelegrafPluginInputRedis.NameEnum.Redis,
|
||||||
|
'servers',
|
||||||
|
'first'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
...INITIAL_STATE,
|
||||||
|
telegrafPlugins: [
|
||||||
|
{
|
||||||
|
...tp,
|
||||||
|
plugin: {
|
||||||
|
...plugin,
|
||||||
|
config: {servers: ['second'], password: ''},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(actual).toEqual(expected)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import {createNewPlugin} from 'src/onboarding/utils/pluginConfigs'
|
import {
|
||||||
|
createNewPlugin,
|
||||||
|
updateConfigFields,
|
||||||
|
} from 'src/onboarding/utils/pluginConfigs'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {Action} from 'src/onboarding/actions/dataLoaders'
|
import {Action} from 'src/onboarding/actions/dataLoaders'
|
||||||
|
@ -67,10 +70,11 @@ export default (state = INITIAL_STATE, action: Action): DataLoadersState => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...tp,
|
...tp,
|
||||||
plugin: {
|
plugin: updateConfigFields(
|
||||||
...plugin,
|
plugin,
|
||||||
[action.payload.field]: action.payload.value,
|
action.payload.field,
|
||||||
},
|
action.payload.value
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tp
|
return tp
|
||||||
|
@ -90,10 +94,11 @@ export default (state = INITIAL_STATE, action: Action): DataLoadersState => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...tp,
|
...tp,
|
||||||
plugin: {
|
plugin: updateConfigFields(
|
||||||
...plugin,
|
plugin,
|
||||||
[action.payload.fieldName]: updatedConfigFieldValue,
|
action.payload.fieldName,
|
||||||
},
|
updatedConfigFieldValue
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tp
|
return tp
|
||||||
|
@ -117,10 +122,11 @@ export default (state = INITIAL_STATE, action: Action): DataLoadersState => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...tp,
|
...tp,
|
||||||
plugin: {
|
plugin: updateConfigFields(
|
||||||
...plugin,
|
plugin,
|
||||||
[action.payload.fieldName]: filteredConfigFieldValue,
|
action.payload.fieldName,
|
||||||
},
|
filteredConfigFieldValue
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tp
|
return tp
|
||||||
|
|
|
@ -14,6 +14,16 @@ export const getConfigFields = (
|
||||||
return telegrafPluginsInfo[pluginName].fields
|
return telegrafPluginsInfo[pluginName].fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const updateConfigFields = <T extends Plugin>(
|
||||||
|
plugin: T,
|
||||||
|
fieldName: string,
|
||||||
|
value: string[] | string
|
||||||
|
): T => {
|
||||||
|
return Object.assign({}, plugin, {
|
||||||
|
config: Object.assign({}, plugin.config, {[fieldName]: value}),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const createNewPlugin = (name: TelegrafPluginName): Plugin => {
|
export const createNewPlugin = (name: TelegrafPluginName): Plugin => {
|
||||||
return telegrafPluginsInfo[name].defaults
|
return telegrafPluginsInfo[name].defaults
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue