Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const removeChilds = (pluginInstances, instanceId) => {
const plugin = pluginInstances[instanceId]
if (!plugin) return pluginInstances
const pluginListProps = pickBy(plugin.props, { type: 'pluginList' })
const pluginsToRemove = flatten(map(values(pluginListProps), 'value'))
if (!pluginsToRemove.lenght) return pluginInstances
const cleanedPluginInstances = omit(pluginInstances, pluginsToRemove)
return reduce(pluginsToRemove, removeChilds, cleanedPluginInstances)
}
return flow(
update(`pluginInstances`, pluginInstances => removeChilds(pluginInstances, instanceId)),
unset(`pluginInstances.${instanceId}`),
pull(
parent
? `pluginInstances.${parent.plugin}.props.${parent.prop}.value`
: `dashboards.${selectedDashboard}.plugins`,
instanceId,
),
set(`selectedPlugin`, parent && parent.plugin),
)(state)
}
case actions.CHANGE_PROP: {
const { instanceId, prop, value } = action.payload
return set(state, `pluginInstances.${instanceId}.props.${prop.name}.value`, value)
}
case actions.SAVE_LAYOUT: {
const { layout } = action.payload
parent
? `pluginInstances.${parent.plugin}.props.${parent.prop}.value`
: `dashboards.${selectedDashboard}.plugins`,
instanceId,
),
set(`selectedPlugin`, parent && parent.plugin),
)(state)
}
case actions.CHANGE_PROP: {
const { instanceId, prop, value } = action.payload
return set(state, `pluginInstances.${instanceId}.props.${prop.name}.value`, value)
}
case actions.SAVE_LAYOUT: {
const { layout } = action.payload
const { selectedDashboard } = state
return selectedDashboard ? update(state, `pluginInstances`, updatePlugins(layout)) : state
}
case actions.UPDATE_CONFIG: {
const { selectedDashboard } = state
const { property, value } = action.payload
const parsedValue = parseFloat(value)
return selectedDashboard
? set(
state,
`dashboards.${selectedDashboard}.${property}`,
isNaN(parsedValue) ? value : parsedValue,
)
: state
}
case loadActions.LOAD_DASHBOARDS_SUCCESSED: {
const { dashboards, user } = action.payload
const plugins = _chain(dashboards)
(dashboards, pluginInstances, selectedName) => {
if (!selectedName || !dashboards[selectedName]) return null
return flow(
map('plugins', mapPluginInstancesToProps(pluginInstances)),
update('plugins', keyBy('instanceId')),
)(dashboards[selectedName])
},
)