+
+
+ >
+ )}
+
+
+
+ );
+};
+
+export const AbortModal = ({
+ ...props
+}: Pick) => {
+ const { abort } = useMeshConfig();
+ const title = Abort current mesh wide configuration update?;
+ const content = (
+
+ This will the abort current configuration update process on all
+ nodes. Are you sure you want to proceed?
+
+ );
+ const btnTxt = Abort;
return (
Add new section}
- successBtnText={Add}
- {...rest}
- onSuccess={handleSubmit(onSuccess)}
+ title={title}
+ deleteBtnText={btnTxt}
+ onDelete={() => {
+ abort();
+ props.onClose();
+ }}
+ {...props}
>
-
- Name}
- register={register}
- />
-
+ {content}
);
};
+
+export const ScheduleSafeRebootModal = (
+ props: IUseParallelQueriesModalProps
+) => {
+ const { callMutations: startScheduleMeshUpgrade } =
+ useParallelReadyForApply();
+
+ let title = All nodes are ready;
+ let content = (
+
+ Apply configuration on all of them with a scheduled safe reboot?
+
+ );
+ if (!props.isSuccess) {
+ title = Some nodes are not ready;
+ content = (
+
+ Are you sure you want to apply the configuration to the nodes
+ that are ready?
+ This will make some of them to reboot
+
+ Check node list to see the network status
+
+ );
+ }
+
+ return (
+ {
+ startScheduleMeshUpgrade();
+ props.onClose();
+ }}
+ title={title}
+ {...props}
+ >
+ {content}
+
+ );
+};
+
+export const ConfirmModal = (props: IUseParallelQueriesModalProps) => {
+ const { callMutations } = useParallelConfirmConfig();
+ let title = All nodes applied the configuration;
+ let content = (
+
+ Confirm configuration works properlly for al updated nodes
+
+ );
+ // this is not yet imlemented since we are not storing any information of mesh previous state
+ if (!props.isSuccess) {
+ title = Some nodes don't upgraded properly;
+ content = (
+
+ Are you sure you want to confirm the upgrade?
+ Check node list to see the network status
+
+ );
+ }
+ return (
+ {
+ callMutations();
+ props.onClose();
+ }}
+ title={title}
+ {...props}
+ >
+ {content}
+
+ );
+};
diff --git a/plugins/lime-plugin-mesh-wide-config/src/containers/EditConfiguration.tsx b/plugins/lime-plugin-mesh-wide-config/src/containers/EditConfiguration.tsx
deleted file mode 100644
index d922c7233..000000000
--- a/plugins/lime-plugin-mesh-wide-config/src/containers/EditConfiguration.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import { Trans } from "@lingui/macro";
-
-import {
- FullScreenModal,
- IFullScreenModalProps,
-} from "components/Modal/FullScreenModal";
-
-import {
- AddNewSectionBtn,
- ConfigSection,
-} from "plugins/lime-plugin-mesh-wide-config/src/components/ConfigSection";
-import { MeshStatus } from "plugins/lime-plugin-mesh-wide-config/src/components/MeshStatus";
-import { useMeshWideConfig } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigQueries";
-
-const EditConfiguration = (props: Partial) => {
- const { data: meshWideConfig, isLoading } = useMeshWideConfig({});
-
- return (
- Mesh wide config}
- isLoading={isLoading}
- {...props}
- >
- {meshWideConfig && (
- <>
-
-
-
- Upgrade all network nodes at once. This proces will take a
- while and will require user interaction.
-
-
- {thisNode.upgrade_state === "ABORTED" && (
-
+ );
+};
+
+export default WizardWrapper;
diff --git a/src/components/shared-state/SharedStateApi.ts b/src/components/shared-state/SharedStateApi.ts
index 0b6743a9d..3437d7e86 100644
--- a/src/components/shared-state/SharedStateApi.ts
+++ b/src/components/shared-state/SharedStateApi.ts
@@ -7,9 +7,8 @@ import {
SharedStateReturnType,
} from "components/shared-state/SharedStateTypes";
-import { MeshUpgradeApiErrorTypes } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeTypes";
-
import { login } from "utils/queries";
+import { StandarizedApiError } from "utils/standarizedApi";
import { UhttpdService, default as defaultApi } from "utils/uhttpd.service";
async function syncDataType({
@@ -92,7 +91,7 @@ export async function callToRemoteNode({
return await apiCall(customApi);
} catch (error) {
let additionalInfo = "";
- if (error instanceof MeshUpgradeApiError) {
+ if (error instanceof StandarizedApiError) {
additionalInfo = `: ${error.message}`;
}
throw new RemoteNodeCallError(
@@ -116,15 +115,3 @@ export class RemoteNodeCallError extends Error {
Object.setPrototypeOf(this, RemoteNodeCallError.prototype);
}
}
-
-export class MeshUpgradeApiError extends Error {
- message: string;
- code: MeshUpgradeApiErrorTypes;
- constructor(message: string, code: MeshUpgradeApiErrorTypes) {
- super(message); // Pass the message to the Error constructor
- this.name = "MeshUpgradeApiError"; // Set the name of the error
- this.message = message;
- this.code = code;
- Object.setPrototypeOf(this, MeshUpgradeApiError.prototype);
- }
-}
diff --git a/src/components/shared-state/SharedStateQueriesKeys.ts b/src/components/shared-state/SharedStateQueriesKeys.ts
index 2c39e82cb..c284379cc 100644
--- a/src/components/shared-state/SharedStateQueriesKeys.ts
+++ b/src/components/shared-state/SharedStateQueriesKeys.ts
@@ -3,10 +3,24 @@ import {
SharedStateDataTypeKeys,
} from "components/shared-state/SharedStateTypes";
-const getFromSharedStateKey = ["shared-state-async", "get"];
-const insertIntoSharedStateKey = ["shared-state-async", "insert"];
-export const syncFromSharedStateKey = ["shared-state-async", "sync"];
-const publishAllFromSharedStateKey = ["shared-state-async", "publish_all"];
+import { ApiServiceParamsType } from "utils/standarizedApi";
+
+const getFromSharedStateKey: ApiServiceParamsType = [
+ "shared-state-async",
+ "get",
+];
+const insertIntoSharedStateKey: ApiServiceParamsType = [
+ "shared-state-async",
+ "insert",
+];
+export const syncFromSharedStateKey: ApiServiceParamsType = [
+ "shared-state-async",
+ "sync",
+];
+const publishAllFromSharedStateKey: ApiServiceParamsType = [
+ "shared-state-async",
+ "publish_all",
+];
/**
* Use this constant to get the query keys to be used as api call parameters.
diff --git a/src/components/shared-state/SharedStateTypes.ts b/src/components/shared-state/SharedStateTypes.ts
index 6f2496666..0395ca798 100644
--- a/src/components/shared-state/SharedStateTypes.ts
+++ b/src/components/shared-state/SharedStateTypes.ts
@@ -1,3 +1,4 @@
+import { MeshWideConfigState } from "plugins/lime-plugin-mesh-wide-config/src/meshConfigTypes";
import { MeshWideUpgradeInfo } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeTypes";
import {
IBabelLinks,
@@ -6,6 +7,10 @@ import {
IWifiLinks,
} from "plugins/lime-plugin-mesh-wide/src/meshWideTypes";
+export type MeshConfigTypes = {
+ mesh_config: MeshWideConfigState;
+};
+
export type MeshUpgradeTypes = {
mesh_wide_upgrade: MeshWideUpgradeInfo;
};
@@ -25,7 +30,8 @@ export type MeshWideMapReferenceTypes = AppendRef;
export type AllSharedStateTypes = MeshWideMapTypes &
MeshUpgradeTypes &
- MeshWideMapReferenceTypes;
+ MeshWideMapReferenceTypes &
+ MeshConfigTypes;
export type SharedStateDataTypeKeys = keyof AllSharedStateTypes;
diff --git a/src/components/status/statusAndButton.tsx b/src/components/status/statusAndButton.tsx
index 632c3e87e..3967b7264 100644
--- a/src/components/status/statusAndButton.tsx
+++ b/src/components/status/statusAndButton.tsx
@@ -1,6 +1,6 @@
import { VNode } from "preact";
-import { Button } from "components/buttons/button";
+import { Button, ButtonProps } from "components/buttons/button";
import { IStatusMessage, StatusMessage } from "components/status/statusMessage";
export type IStatusAndButton = {
@@ -8,6 +8,7 @@ export type IStatusAndButton = {
btnCancel?: VNode | string;
onClick?: () => void;
onClickCancel?: () => void;
+ btnProps?: ButtonProps;
} & IStatusMessage;
export const StatusAndButton = ({
@@ -17,6 +18,7 @@ export const StatusAndButton = ({
btnCancel,
onClick,
onClickCancel,
+ btnProps,
}: IStatusAndButton) => {
const containerClasses =
"flex flex-col items-center justify-center text-center bg-white py-5 gap-3";
@@ -26,11 +28,19 @@ export const StatusAndButton = ({
{children}
{btnCancel && (
-
);
diff --git a/src/utils/meshWideSyncCall.ts b/src/utils/meshWideSyncCall.ts
index 3b3a84c41..49bcdcc8a 100644
--- a/src/utils/meshWideSyncCall.ts
+++ b/src/utils/meshWideSyncCall.ts
@@ -7,7 +7,7 @@ import { RemoteNodeCallError } from "components/shared-state/SharedStateApi";
import queryCache from "utils/queryCache";
import { useSharedData } from "utils/useSharedData";
-interface IMutationFnVariables {
+export interface IMutationFnVariables {
ip: string;
variables?: TVariables;
}
diff --git a/src/utils/standarizedApi.ts b/src/utils/standarizedApi.ts
new file mode 100644
index 000000000..7107990b4
--- /dev/null
+++ b/src/utils/standarizedApi.ts
@@ -0,0 +1,45 @@
+import { MeshUpgradeApiErrorTypes } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeTypes";
+
+import api, { UhttpdService } from "utils/uhttpd.service";
+
+export type ApiServiceParamsType = [string, string, object?];
+
+// This a util function for standarizes API return calls
+// During the development some methods are thought to have a specific return type:
+// {
+// data: T;
+// error: number;
+// }
+// This is a wrapper function to do the calls to the methods that contains this return type
+// Pass the array of arguments that api.call method needs.
+export const standarizedApiCall = async ({
+ apiService = api,
+ args,
+}: {
+ apiService?: UhttpdService;
+ args: ApiServiceParamsType;
+}) => {
+ if (args.length === 2) {
+ args.push({});
+ }
+ const res = await apiService.call(...args);
+ if (res?.error && res?.error !== "0" && res?.error !== 0) {
+ throw new StandarizedApiError(res.error, res.code);
+ }
+ if (res.data) return res.data as T;
+ // Fallback to return the response if there is no data
+ return res as T;
+};
+
+export class StandarizedApiError extends Error {
+ message: string;
+ code: MeshUpgradeApiErrorTypes;
+
+ constructor(message: string, code: MeshUpgradeApiErrorTypes) {
+ super(message); // Pass the message to the Error constructor
+ this.name = "MeshUpgradeApiError"; // Set the name of the error
+ this.message = message;
+ this.code = code;
+ Object.setPrototypeOf(this, StandarizedApiError.prototype);
+ }
+}