Skip to content

Commit

Permalink
Merge pull request #1630 from decentdao/typing-mapChildNodes
Browse files Browse the repository at this point in the history
Add proper typing to `mapChildNodes` function
  • Loading branch information
adamgall authored May 5, 2024
2 parents 30de55b + fb6aebb commit 216e88b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/hooks/DAO/loaders/useFractalNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export const useFractalNode = (
const { daos } = result.data;
const dao = daos[0];
if (dao) {
const { parentAddress, name, hierarchy, snapshotENS, proposalTemplatesHash } = dao;
const { parentAddress, name, snapshotENS, proposalTemplatesHash } = dao;

const currentNode: Node = {
nodeHierarchy: {
parentAddress,
childNodes: mapChildNodes(hierarchy),
childNodes: mapChildNodes(dao),
},
daoName: name as string,
daoAddress: getAddress(_daoAddress),
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/DAO/loaders/useLoadDAONode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export const useLoadDAONode = () => {
const { daos } = result.data;
const dao = daos[0];
if (dao) {
const { parentAddress, name, hierarchy, snapshotENS } = dao;
const { parentAddress, name, snapshotENS } = dao;

const currentNode: Node = {
nodeHierarchy: {
parentAddress,
childNodes: mapChildNodes(hierarchy),
childNodes: mapChildNodes(dao),
},
daoName: name as string,
daoAddress: getAddress(_daoAddress),
Expand Down
22 changes: 18 additions & 4 deletions src/utils/hierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
export const mapChildNodes = (_hierarchy: any) => {
return _hierarchy.map((node: any) => {
import { DAO } from '../../.graphclient';
import { Node } from '../types';

type DAOQueryNode = Pick<
DAO,
| 'id'
| 'address'
| 'parentAddress'
| 'name'
| 'snapshotENS'
| 'proposalTemplatesHash'
| 'hierarchy'
>;

export const mapChildNodes = (dao: DAOQueryNode) => {
return dao.hierarchy.map((node: DAO): Node => {
return {
nodeHierarchy: {
parentAddress: node.parentAddress,
childNodes: mapChildNodes(node.hierarchy),
childNodes: mapChildNodes(node),
},
daoName: node.name,
daoName: node.name === null || node.name === undefined ? null : node.name,
daoAddress: node.address,
};
});
Expand Down

0 comments on commit 216e88b

Please sign in to comment.