Skip to content

Commit 25d069f

Browse files
Correct flow.api and red.logic implementations to correctly save translated data to Node-RED API
1 parent 33f8259 commit 25d069f

File tree

3 files changed

+190
-100
lines changed

3 files changed

+190
-100
lines changed

packages/flow-client/src/app/redux/modules/api/flow.api.ts

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,57 @@
11
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
22
import environment from '../../../../environment';
33

4-
// Type for Node-RED flows response/request
4+
// Base type for common properties
5+
export interface NodeRedBase {
6+
id: string;
7+
type: string;
8+
info: string;
9+
env: { name: string; type: string; value: string }[];
10+
}
11+
12+
// Type for regular Node-RED flows
13+
export interface NodeRedFlow extends NodeRedBase {
14+
type: 'tab';
15+
label: string;
16+
disabled: boolean;
17+
}
18+
19+
// Type for Node-RED subflows
20+
export interface NodeRedSubflow extends NodeRedBase {
21+
type: 'subflow';
22+
name: string;
23+
category: string;
24+
color: string;
25+
icon: string;
26+
in: NodeRedEndpoint[];
27+
out: NodeRedEndpoint[];
28+
}
29+
30+
// Type for nodes within flows or subflows
31+
export interface NodeRedNode extends NodeRedBase {
32+
name: string;
33+
x: number;
34+
y: number;
35+
z: string;
36+
wires: string[][];
37+
inputs?: number;
38+
outputs?: number;
39+
inputLabels?: string[];
40+
outputLabels?: string[];
41+
icon?: string;
42+
}
43+
44+
// Type for endpoints used in subflows (inputs and outputs)
45+
export interface NodeRedEndpoint {
46+
x: number;
47+
y: number;
48+
wires: { id: string; port?: number }[];
49+
}
50+
51+
// Composite type for all Node-RED objects
552
export interface NodeRedFlows {
6-
flows: unknown[];
53+
rev?: string;
54+
flows: NodeRedBase[];
755
}
856

957
// Define a service using a base URL and expected endpoints for flows
@@ -12,6 +60,11 @@ export const flowApi = createApi({
1260
baseQuery: fetchBaseQuery({
1361
baseUrl: environment.NODE_RED_API_ROOT,
1462
responseHandler: 'content-type',
63+
prepareHeaders: headers => {
64+
headers.set('Node-RED-API-Version', 'v2');
65+
headers.set('Node-RED-Deployment-Type', 'nodes');
66+
return headers;
67+
},
1568
}),
1669
tagTypes: ['Flow'], // For automatic cache invalidation and refetching
1770
endpoints: builder => ({
@@ -27,7 +80,7 @@ export const flowApi = createApi({
2780
}),
2881
// Endpoint to update all flows
2982
updateFlows: builder.mutation<NodeRedFlows, NodeRedFlows>({
30-
query: (flows) => ({
83+
query: flows => ({
3184
url: 'flows',
3285
method: 'POST',
3386
headers: {

packages/flow-client/src/app/redux/modules/flow/flow.logic.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import {
99
selectFlowEntityById,
1010
selectSubflowInOutByFlowId,
1111
selectSubflowInstancesByFlowId,
12-
FlowEntity,
1312
} from './flow.slice';
1413
import { GraphLogic } from './graph.logic';
1514
import { NodeLogic } from './node.logic';
16-
import { TreeLogic } from './tree.logic';
1715
import { RedLogic } from './red.logic';
16+
import { TreeLogic } from './tree.logic';
1817

1918
// checks if a given property has changed
2019
const objectHasChange = <T>(

0 commit comments

Comments
 (0)