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
const { selectedDashboard } = state
return { ...state, deletingDashboard: action.payload.dashboardId }
}
case actions.DASHBOARD_DELETED: {
const { deletingDashboard } = state
return deletingDashboard
? flow(
set('deletingDashboard', null),
unset(`dashboards.${deletingDashboard}`),
)(state)
: { ...state, deletingDashboard: null }
}
case actions.CANCEL_DASHBOARD_DELETION: {
return { ...state, deletingDashboard: null }
}
case actions.DELETE_DASHBOARD: {
return unset(state, `dashboards.${action.payload.dashboardId}`)
}
case actions.ADD_DASHBOARD: {
const { dashboard } = action.payload
return flow(
set(`dashboards.${dashboard.id}`, dashboard),
set('selectedDashboard', dashboard.id),
)(state)
}
case actions.ADD_SUB_PLUGIN: {
const { selectedPlugin } = state
if (!selectedPlugin) return state
const { propName, plugin } = action.payload
const instanceId = uuid()
return flow(
return {
...state,
users: keyBy(users, 'id'),
}
}
case userActions.ADD_USER_SUCCESS: {
const { user } = action.payload
return set(state, `users.${user.id}`, user)
}
case userActions.UPDATE_USER_SUCCESS: {
const { user } = action.payload
return set(state, `users.${user.id}`, user)
}
case userActions.DELETE_USER_SUCCESS: {
const { id } = action.payload
return unset(state, `users.${id}`)
}
case userActions.EDIT_USER: {
const { user } = action.payload
const currentUser = { ...user, confirmPassword: '' }
return set(state, 'currentUser', currentUser)
}
case userActions.UPDATE_CURRENT_USER_PROPERTY: {
const { property, value } = action.payload
return set(state, `currentUser.${property}`, value)
}
case userActions.RESET_CURRENT_USER: {
return set(state, 'currentUser', initialState.currentUser)
}
default:
return state
}