import { createSelector } from '@reduxjs/toolkit' import { RootState } from '../store' import { deserialize } from '../utils/system' import { selectAllActionRelationsProducedAttributes } from './attributes' const selectSelf = (state: RootState) => state /** * Select all actions as execution sequence for lambda * @returns */ export const selectAllActionRelationsAsExecution = () => createSelector(selectSelf, (state: RootState) => { const { actions, relations, pipeline } = state return pipeline.map(({ id, params, produce, consume }) => { const [relation] = relations.filter(rel => rel.id === id) const [action] = actions.filter( action => action.name === relation.actName ) const cmdOptions = Object.fromEntries( Object.entries(params).map(([key, value]) => { const attr = action.pAttributes.filter(attr => attr.id === key)[0] return [attr ? attr.name : key, value] }) ) const lAttributesMap = Object.fromEntries( action.lAttributes.map(attr => [attr.id, attr.name]) ) const rAttributesMap = Object.fromEntries( action.rAttributes.map(attr => [attr.id, attr.name]) ) const lAttributes = Object.entries(consume).map( ([key, value]) => `${lAttributesMap[key]}=${value}` ) const rAttributes = Object.entries(produce).map( ([key, value]) => `${key}=${rAttributesMap[value]}` ) const parts = deserialize(action.name) const actName = parts.cmd || parts.flt || parts.src || '' return { id: relation.id, rel: relation.rel, cmdId: action.name, cmdName: actName, cmdOptions, context: {}, lAttributes, rAttributes, } }) }) export const selectAllViewsAsOutput = () => createSelector(selectSelf, (state: RootState) => { const { views, labels } = state const allProducedAttributes = selectAllActionRelationsProducedAttributes()( state ) return views.map(({ id, label, layout, elements }) => ({ id, label, layout, elements: Object.entries(elements).map(([globalId, component]) => { const attribute = allProducedAttributes.filter( attr => attr.globalId === globalId )[0] const label = labels[globalId] || attribute.label return { name: attribute.globalId, datatype: attribute.datatype, label, component, } }), })) })