Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function assignElementProperties(workpadState, pageId, elementId, props) {
const pageIndex = getPageIndexById(workpadState, pageId);
const elementsPath = ['pages', pageIndex, 'elements'];
const elementIndex = get(workpadState, elementsPath, []).findIndex(
element => element.id === elementId
);
if (pageIndex === -1 || elementIndex === -1) {
return workpadState;
}
// remove any AST value from the element caused by https://github.com/elastic/kibana-canvas/issues/260
// TODO: remove this after a bit of time
const cleanWorkpadState = del(workpadState, elementsPath.concat([elementIndex, 'ast']));
return assign(cleanWorkpadState, elementsPath.concat(elementIndex), props);
}
(state, nextElementIndex) => del(state, ['pages', pageIndex, 'elements', nextElementIndex]),
workpadState
[removeContainer]: (state, { payload }) => immutable.del(state, payload),
[setContainerUI]: (state, action) => setMetaOrUI(state, action, 'ui'),
return (state = { pendings: {}, errors: {} }, action) => {
switch (action.type) {
case PENDING: {
const key = makeKey(...action.meta.params)
return {
errors: immutable.del(state.errors, key),
pendings: {
...state.pendings,
[key]: true,
},
}
}
case FAILURE: {
const key = makeKey(...action.meta.params)
return {
errors: {
...state.errors,
[key]: action.payload,
},
pendings: immutable.del(state.pendings, key),
}
}
export const removeTreeItem = (tree: ITreeItem[], item: ITreeItem): ITreeItem[] => {
let newTree = tree;
const children = tree.filter(it => it.parent === item.id);
for (const child of children) {
newTree = removeTreeItem(newTree, child);
}
const treeItemIndex = newTree.findIndex(it => it.id === item.id);
return immutable.del(newTree, treeItemIndex.toString());
};
return {
errors: immutable.del(state.errors, key),
pendings: {
...state.pendings,
[key]: true,
},
}
}
case FAILURE: {
const key = makeKey(...action.meta.params)
return {
errors: {
...state.errors,
[key]: action.payload,
},
pendings: immutable.del(state.pendings, key),
}
}
case SUCCESS: {
const key = makeKey(...action.meta.params)
return {
...state,
pendings: immutable.del(state.pendings, key),
}
}
default:
return state
}
}
}
return props.reduce((obj, prop) => immutable.del(obj, prop), object)
}
[flushContext]: (transientState, { payload: elementId }) => {
return del(transientState, getFullPath([elementId, 'expressionContext']));
},
export const clearResources = (state, data) => {
switch (typeof data) {
case 'object': {
if (Array.isArray(data)) return data.reduce(clearResources, state);
const { type, id } = data;
return imm.del(state, ['resources', type, id]);
}
case 'string': return imm.set(state, ['resources', data], {});
case 'undefined': return imm.set(state, 'resources', {});
default: return state;
}
};