Skip to content

Commit

Permalink
Display subflows in node palette
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaCWebDeveloper committed May 23, 2024
1 parent 731ecd2 commit fad04fa
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export const FlowCanvas: React.FC<FlowCanvasProps> = ({ flowId }) => {
);

const node = new CustomNodeModel({
name: entity.type,
name: entity.name,
color: entity.color,
extras: {
entity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from 'styled-components';

import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { useAppDispatch, useAppLogic, useAppSelector } from '../../redux/hooks';
import {
paletteNodeActions,
selectFilteredNodes,
Expand Down Expand Up @@ -32,16 +32,20 @@ const StyledNodePalette = styled.div`

export const NodePalette = () => {
const dispatch = useAppDispatch();

const flowLogic = useAppLogic().flow;
const nodes = useAppSelector(selectFilteredNodes);
const subflows = useAppSelector(
flowLogic.node.selectSubflowsAsPaletteNodes
);

const handleSearch = (query: string) => {
dispatch(paletteNodeActions.setSearchQuery(query));
};

return (
<StyledNodePalette className="node-palette">
<SearchBar onSearch={handleSearch} />
<NodeList nodes={nodes} />
<NodeList nodes={[...nodes, ...subflows]} />
</StyledNodePalette>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const NodeRedNode = ({
alt="Node Icon"
/>
)}
<span className="name">{instance?.name || entity.type}</span>
<span className="name">{instance?.name || entity.name}</span>
{children}
</StyledNode>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/flow-client/src/app/redux/modules/api/node.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const nodeApi = createApi({
...node,
id: type,
nodeRedId: node.id,
nodeRedName: node.name,
name: type,
type, // Assign each type to a new node
types: undefined, // Remove the types array
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ export class GraphLogic {
// Method to convert and update the flow based on the serialized graph from react-diagrams
updateFlowFromSerializedGraph(graph: SerializedGraph) {
return async (dispatch: AppDispatch, getState: () => RootState) => {
// const graph = JSON.parse(serializedGraph) as SerializedGraph;

// Assuming layers[1] contains nodes and layers[0] contains links
const nodeModels =
(
graph.layers.find(
Expand Down
27 changes: 25 additions & 2 deletions packages/flow-client/src/app/redux/modules/flow/node.logic.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { v4 as uuidv4 } from 'uuid';
import { PortModelAlignment } from '@projectstorm/react-diagrams';
import { createSelector } from '@reduxjs/toolkit';
import { v4 as uuidv4 } from 'uuid';

import { executeNodeFn } from '../../../red/execute-script';
import { AppDispatch, RootState } from '../../store';
import {
PaletteNodeEntity,
selectPaletteNodeById,
} from '../palette/node.slice';
import {
FlowNodeEntity,
PortModel,
SubflowEntity,
flowActions,
selectAllSubflows,
selectFlowNodeById,
} from './flow.slice';
import { AppDispatch, RootState } from '../../store';

type DirtyNodeChanges = Partial<
Omit<FlowNodeEntity, 'outputs'> & {
Expand Down Expand Up @@ -329,4 +332,24 @@ export class NodeLogic {
);
};
};

selectSubflowsAsPaletteNodes = createSelector(
[selectAllSubflows],
(subflows: SubflowEntity[]) => {
return subflows.map(
subflow =>
({
id: subflow.id,
nodeRedId: '',
nodeRedName: subflow.name,
name: subflow.name,
type: `subflow:${subflow.id}`,
category: subflow.category,
color: subflow.color,
module: 'subflows',
version: '1.0.0',
} as PaletteNodeEntity)
);
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EntityState,
PayloadAction,
} from '@reduxjs/toolkit';

import { RootState } from '../../store';

export const PALETTE_NODE_FEATURE_KEY = 'paletteNode';
Expand All @@ -31,6 +32,7 @@ export type PaletteNodeEntity = {
// Core properties
id: string;
nodeRedId: string;
nodeRedName: string;
name: string;
type: string;
category?: string;
Expand Down Expand Up @@ -123,7 +125,6 @@ export const paletteNodeSlice = createSlice({
// Custom action to set nodes
setNodes: paletteNodeAdapter.setAll,
},
// No extraReducers if fetching is handled by RTK Query
});

// Export reducer and actions
Expand Down

0 comments on commit fad04fa

Please sign in to comment.