Skip to content

Commit

Permalink
chore(meshconfig): implement useMeshWideConfigState
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Sep 25, 2024
1 parent b1444ca commit e68ee86
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
28 changes: 27 additions & 1 deletion plugins/lime-plugin-mesh-wide-config/src/meshConfigApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
import { IMeshWideConfig } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigTypes";
import {
IMeshWideConfig,
MeshWideConfigState,
} from "plugins/lime-plugin-mesh-wide-config/src/meshConfigTypes";

export const getMeshWideConfigState = async () => meshWideConfigState;

export const getMeshWideConfig = async () => meshWideConfig;

const meshWideConfigState: MeshWideConfigState = {
node1: {
state: "DEFAULT",
timestamp: "2021-09-01T00:00:00Z",
main_node: "NO",
error: "",
node_ip: "",
bleachTTL: 0,
author: "node1",
},
node2: {
state: "DEFAULT",
timestamp: "2021-09-01T00:00:00Z",
main_node: "NO",
error: "",
node_ip: "",
bleachTTL: 0,
author: "node2",
},
};

const options = {
primary_interface: "eth0",
main_ipv4_address: "10.170.128.0/16/17",
Expand Down
22 changes: 19 additions & 3 deletions plugins/lime-plugin-mesh-wide-config/src/meshConfigQueries.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { useQuery } from "@tanstack/react-query";

import { getMeshWideConfig } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigApi";
import { IMeshWideConfig } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigTypes";
import {
getMeshWideConfig,
getMeshWideConfigState,
} from "plugins/lime-plugin-mesh-wide-config/src/meshConfigApi";
import {
IMeshWideConfig,
MeshWideConfigState,
} from "plugins/lime-plugin-mesh-wide-config/src/meshConfigTypes";

export function useMeshWideConfig(params) {
return useQuery<IMeshWideConfig>(
["lime-meshwide", "get_mesh_config"],
["lime-mesh-config", "get_mesh_config"],
getMeshWideConfig,
{
...params,
}
);
}

export function useMeshWideConfigState(params) {
return useQuery<MeshWideConfigState>(
["lime-mesh-config", "get_mesh_config_state"],
getMeshWideConfigState,
{
...params,
}
);
}
28 changes: 28 additions & 0 deletions plugins/lime-plugin-mesh-wide-config/src/meshConfigTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
import { MainNodeStatusType } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeTypes";

export interface IMeshWideSection {
name: string;
options: { [key: string]: string };
}

export type IMeshWideConfig = IMeshWideSection[];

export type ConfigUpdateState =
| "DEFAULT" // No transaction
| "READY_FOR_UPGRADE"
| "UPGRADE_SCHEDULED"
| "CONFIRMATION_PENDING"
| "CONFIRMED"
| "ABORTED"
| "ERROR";

export interface NodeMeshConfigInfo {
timestamp: string;
main_node: MainNodeStatusType;
error: string;
node_ip: string;
state: ConfigUpdateState;
}

export type MeshWideNodeConfigInfo = {
bleachTTL: number;
author: string;
} & NodeMeshConfigInfo;

export interface MeshWideConfigState {
[key: string]: MeshWideNodeConfigInfo;
}

0 comments on commit e68ee86

Please sign in to comment.