Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { instanceId, parent } = plugin
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: {
case actions.SELECT_PLUGIN: {
return { ...state, selectedPlugin: action.payload.instanceId }
}
case actions.SELECT_DASHBOARD: {
return { ...state, selectedDashboard: action.payload.dashboardId }
}
case actions.UNSELECT_DASHBOARD: {
return { ...state, selectedDashboard: null, selectedPlugin: null }
}
case actions.REQUIRE_DASHBOARD_DELETION: {
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),
}
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(
set(`pluginInstances.${instanceId}`, {
...plugin,
x: 0,
y: 0,
cols: 1,
rows: 1,
instanceId,
parent: { plugin: selectedPlugin, prop: propName },
}),
push(`pluginInstances.${selectedPlugin}.props.${propName}.value`, instanceId),
)(state)
}
case actions.REORDER_SUB_PLUGINS: {
const {
instanceIds,
parent: { plugin, prop },
}),
push(`pluginInstances.${selectedPlugin}.props.${propName}.value`, instanceId),
)(state)
}
case actions.REORDER_SUB_PLUGINS: {
const {
instanceIds,
parent: { plugin, prop },
} = action.payload
return set(state, `pluginInstances.${plugin}.props.${prop}.value`, instanceIds)
}
case actions.ADD_PLUGIN: {
const instanceId = uuid()
const { selectedDashboard } = state
return selectedDashboard
? flow(
set('selectedPlugin', instanceId),
set(`pluginInstances.${instanceId}`, {
...action.payload.plugin,
x: action.payload.x,
y: action.payload.y,
cols: 1,
rows: 1,
instanceId,
}),
push(`dashboards.${selectedDashboard}.plugins`, instanceId),
)(state)
: state
}
case actions.DELETE_PLUGIN: {
const { plugin } = action.payload
const { selectedDashboard } = state
const clients = (state = initialState, action) => {
switch (action.type) {
case loadersActions.LOAD_CLIENTS_SUCCESSED: {
return { ...state, clients: action.payload.clients }
}
case actions.CLIENT_ASSOCIATION_STARTED: {
return set(state, `loading.${action.payload.client.id}`, true)
}
case actions.CLIENT_ASSOCIATION_SUCCESS: {
const { client } = action.payload
return flow(
unset(`loading.${client.id}`),
set(`clients.${client.id}`, client),
)(state)
}
case actions.CLIENT_ASSOCIATION_FAILED: {
const { client } = action.payload
return unset(state, `loading.${client.id}`)
}
case actions.REQUIRE_CLIENT_ASSOCIATION: {
const { client } = action.payload
return { ...state, associating: client }
}
case actions.CONFIRM_CLIENT_ASSOCIATION:
case actions.CANCEL_CLIENT_ASSOCIATION: {
return { ...state, associating: null }
}
(dashboards, pluginInstances, selectedName) => {
if (!selectedName || !dashboards[selectedName]) return null
return flow(
map('plugins', mapPluginInstancesToProps(pluginInstances)),
update('plugins', keyBy('instanceId')),
)(dashboards[selectedName])
},
)
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(
set(`pluginInstances.${instanceId}`, {
...plugin,
x: 0,
y: 0,