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);
}
[updateField]: (state, { payload: { fieldId, data }}) => immutable.assign(state, fieldId, data),
[markFieldAsInvalid]: (state, { payload: { fieldId, error } }) => immutable.assign(state, `${fieldId}.ui`, {
valid: false,
error: error,
}),
[combineActions(setupField, setUI)]: (state, { payload: { fieldId, ui }}) => immutable.assign(state, `${fieldId}.ui`, ui),
[setAssetValue]: (assetState, { payload }) => {
const { id, value } = payload;
const asset = get(assetState, [id]);
if (!asset) {
throw new Error(`Can not set asset data, id not found: ${id}`);
}
return assign(assetState, id, { value });
},