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);
}
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);
}
const pageIndex = getPageIndexById(workpadState, id);
const newIndex = pageIndex + position;
// TODO: do something better when given an invalid page id
if (pageIndex < 0) {
return workpadState;
}
// don't move pages past the first or last position
if (newIndex < 0 || newIndex >= workpadState.pages.length) {
return workpadState;
}
// remove and re-insert the page
const page = { ...workpadState.pages[pageIndex] };
let newState = insert(del(workpadState, `pages.${pageIndex}`), 'pages', page, newIndex);
// adjust the selected page index and return the new state
const selectedId = workpadState.pages[workpadState.page].id;
const newSelectedIndex = newState.pages.findIndex(page => page.id === selectedId);
newState = set(newState, 'page', newSelectedIndex);
// changes to the page require navigation
const router = routerProvider();
router.navigateTo('loadWorkpad', { id: newState.id, page: newState.page + 1 });
return newState;
},
update: state => im.set(state, 'hello', 'kitty'),
});
let newState = state;
if (action.payload.body) {
const { data, meta } = action.payload.body;
let normalizedData;
if (Array.isArray(data)) {
normalizedData = data.map(record => ({ id: record.id, type: record.type }));
} else if (data && data.id) {
normalizedData = { id: data.id, type: data.type };
} else {
normalizedData = null;
}
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'response'],
normalizedData,
);
if (meta) {
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'meta'],
meta
);
}
}
newState = immutable.set(
newState,
const invalidate = (state, actionName, key) => (
immutable.set(state, [actionName, key, 'invalid'], true)
);
newState,
[name, JSON.stringify(params), 'isLoading'],
false,
);
return newState;
} else if (metaType === 'error') {
let newState = state;
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'isLoading'],
false,
);
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'response'],
null,
);
if (action.payload instanceof Error) {
newState = immutable.set(
newState,
[name, JSON.stringify(params), 'error'],
action.payload.message
);
newState = immutable.del(
newState,
[name, JSON.stringify(params), 'headers'],
[transientActions.setFirstLoad]: (transientState, { payload }) => {
return set(transientState, 'isFirstLoad', Boolean(payload));
},
[switchComplexTab]: (state, { payload: { fieldId, groupId } }) => immutable.set(state, `${fieldId}.ui.current_tab`, groupId),
}, {}));
[actions.stylePage]: (workpadState, { payload }) => {
const pageIndex = workpadState.pages.findIndex(page => page.id === payload.pageId);
return set(workpadState, ['pages', pageIndex, 'style'], payload.style);
},