Skip to content

Commit 8ff346c

Browse files
committed
Transform nodes response
1 parent 0bc5a85 commit 8ff346c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/QueryEditor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
5050
const { allDimensions, groupingByList, filters, units, fetchDimensions } = useFetchDimensions(baseUrl);
5151

5252
const filterList = React.useMemo(() => Object.keys(filters).map((s) => ({ label: s, value: s })), [filters]);
53-
const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.nm, value: c.nd })), [nodes]);
53+
const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.name, value: c.id })), [nodes]);
5454

5555
const { spaceId, roomId, nodes: allNodes, dimensions, groupBy, contextId, filterBy, filterValue } = query;
5656

@@ -102,7 +102,7 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
102102
if (allNodes && nodes.length > 0) {
103103
const filteredNodes: any[] = [];
104104
allNodes.forEach((element) => {
105-
const currentNode: any = nodes.find((n: any) => n.nd === element);
105+
const currentNode: any = nodes.find((n: any) => n.id === element);
106106
filteredNodes.push({ label: currentNode?.name, value: currentNode?.id });
107107
});
108108

@@ -116,7 +116,7 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
116116

117117
if (allNodes && nodes.length > 0) {
118118
allNodes.forEach((element) => {
119-
const currentNode: any = nodes.find((n: any) => n.nd === element);
119+
const currentNode: any = nodes.find((n: any) => n.id === element);
120120
filteredNodes.push({ label: currentNode?.name, value: currentNode?.id });
121121
});
122122
}

src/shared/hooks/useFetchNodes.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import React from 'react';
22
import { Post } from 'shared/utils/request';
33

4+
type Node = {
5+
nd: string;
6+
nm: string;
7+
[key: string]: any;
8+
};
9+
10+
const transformNodes = (nodes: Node[] = []) => nodes.map(({ nd, nm, ...rest }) => ({ id: nd, name: nm, ...rest }));
11+
412
export const getNodes = async (spaceId: string, roomId: string, baseUrl: string) => {
513
const response = await Post({
614
path: `/v3/spaces/${spaceId}/rooms/${roomId}/nodes`,
@@ -11,6 +19,7 @@ export const getNodes = async (spaceId: string, roomId: string, baseUrl: string)
1119
},
1220
},
1321
});
22+
1423
return response?.data?.nodes;
1524
};
1625

@@ -35,7 +44,7 @@ export const useFetchNodes = (baseUrl: string) => {
3544

3645
return {
3746
isError,
38-
nodes,
47+
nodes: transformNodes(nodes),
3948
fetchNodes,
4049
};
4150
};

0 commit comments

Comments
 (0)