import { createSelector } from 'reselect' ; import memoize from 'lodash/memoize' ; import { Map } from 'immutable' ; import { Port } from '../api' ; import { PORT_SINK , PORT_SOURCE } from '../constants/flowdesigner.constants' ; import { PortRecordMap , PortRecord , NodeRecordMap , LinkRecordMap , State , LinkRecord , } from '../customTypings/index.d' ; const getNodes = ( state ) : NodeRecordMap => state . get ( 'nodes' ) ; const getPorts = ( state ) : PortRecordMap => state . get ( 'ports' ) ; const getLinks = ( state ) : LinkRecordMap => state . get ( 'links' ) ; /**
 * return a list of outgoing port for this node
 */ export function outPort ( state , nodeId ) { return state . getIn ( [ 'out' , nodeId ] ) || Map ( ) ; } /**
 * return a list of ingoing port for this node
 */ export function inPort ( state , nodeId ) { return state . getIn ( [ 'in' , nodeId ] ) || Map ( ) ; } return { getPortsForNode } export const getPortsForNode = createSelector ( getPorts , ( ports ) : PortRecord => memoize ( ( nodeId ) => ports . filter ( ( port ) => Port . getNodeId ( port ) === nodeId ) ) ) ; return export const getEmitterPorts = createSelector ( getPorts , ( ports ) : PortRecord => ports . filter ( ( port ) => Port . getTopology ( port ) === PORT_SOURCE ) ) ; return export const getSinkPorts = createSelector ( getPorts , ( ports ) : PortRecord => ports . filter ( ( port ) => Port . getTopology ( port ) === PORT_SINK ) ) ; /**
 * Create and return function who will return all Emitter ports for a specific node
 */ export const getEmitterPortsForNode = createSelector ( getEmitterPorts , ( ports ) : PortRecord => ( nodeId ) => ports . filter ( ( port ) => Port . getNodeId ( port ) === nodeId ) ) ; /**
 * Create and return function who will return all Sink ports for a specific node
 */ export const getSinkPortsForNode = createSelector ( getSinkPorts , ( ports ) : PortRecord => ( nodeId ) => ports . filter ( ( port ) => Port . getNodeId ( port ) === nodeId ) ) ; return export const getFreeSinkPorts = createSelector ( [ getSinkPorts , getLinks ] , ( sinkPorts , links ) => { return sinkPorts . filter ( ( sinkPort ) => ! links . find ( ( link ) => link . targetId === Port . getId ( sinkPort ) ) ) as PortRecordMap ; } ) ; return export const getFreeEmitterPorts = createSelector ( [ getEmitterPorts , getLinks ] , ( emitterPorts , links ) => emitterPorts . filter ( ( emitterPort ) => ! links . find ( ( link ) => link . sourceId === Port . getId ( emitterPort ) ) ) ) ; return export const getActionKeyedPorts = createSelector ( getFreeSinkPorts , ( freeSinkPorts ) => freeSinkPorts . filter ( ( sinkPort ) => sinkPort . accessKey ) ) ; export const getDetachedPorts = createSelector ( [ getPorts , getNodes ] , ( ports , nodes ) => ports . filter ( ( port ) => ! nodes . find ( ( node ) => node . id === Port . getNodeId ( port ) ) ) ) ;