Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement mesh wide config stepper #459

Merged
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2e997fe
chore(meshconfig): implement WizardWrapper
selankon Sep 25, 2024
bbcdfe9
chore(meshconfig): implement useMeshWideConfigState
selankon Sep 25, 2024
eb57f55
chore(meshconfig): implement NodesListWrapper
selankon Oct 2, 2024
dedfb2f
chore(meshconfig): implement NodeInfoListItem
selankon Oct 3, 2024
3c69b2c
chore(meshconfig): fix mesh types
selankon Oct 3, 2024
5d2e014
chore(meshconfig): mock stepper types
selankon Oct 9, 2024
618671d
chore(meshconfig): implement lime config json parser
selankon Oct 10, 2024
3d91ec0
chore(meshconfig): implement entry edition
selankon Oct 10, 2024
e56ec34
chore(meshconfig): implement delete entry
selankon Oct 10, 2024
d63b6f3
chore(meshconfig): support list forms
selankon Oct 15, 2024
8b5b101
chore(meshconfig): implement add new section
selankon Oct 15, 2024
c7bcb4f
chore(meshconfig): implement add new config section
selankon Oct 15, 2024
9f20538
chore(meshconfig): implement add new list item
selankon Oct 15, 2024
c697949
chore(meshconfig): fix rebase
selankon Oct 25, 2024
c77a333
chore(meshconfig): implement add new configuration section
selankon Oct 25, 2024
112dec5
chore(meshconfig): bulk bugfix
selankon Oct 28, 2024
53e24dc
chore(meshconfig): fix form
selankon Oct 29, 2024
cf1a170
chore(meshconfig): fix form layout
selankon Oct 29, 2024
134a6b6
chore(meshconfig): fix form
selankon Oct 29, 2024
acb85e6
chore(meshconfig): implement is dirty
selankon Oct 30, 2024
b0c3e0a
chore(meshconfig): implement submit
selankon Oct 30, 2024
597a92f
chore(mesh-config): fix query keys
selankon Nov 4, 2024
9a17064
chore(mesh-config): implement api calls
selankon Nov 4, 2024
6941e61
chore(mesh-config): create standarized api call
selankon Nov 5, 2024
be47aa9
chore(mesh-config): reimplement parse community file
selankon Nov 5, 2024
c355afe
chore(mesh-config): mock base states
selankon Nov 8, 2024
ccfa68d
chore(mesh-config): refactor query keys
selankon Nov 8, 2024
15c3a54
chore(mesh-config): implement abort
selankon Nov 8, 2024
2465c17
chore(mesh-config): implement mutate new config
selankon Nov 8, 2024
75c569a
chore(mesh-config): improve mesh info messages
selankon Nov 8, 2024
cde4ed0
chore(mesh-config): implemented schedule safe rebot
selankon Nov 8, 2024
e83f702
chore(mesh-config): implemented confirm
selankon Nov 8, 2024
70903a1
chore(mesh-config): some bulkfix
selankon Nov 8, 2024
91c691c
chore(mesh-config): move common files
selankon Nov 12, 2024
18901be
chore(mesh-config): implement stepper states
selankon Nov 12, 2024
f1c8757
chore(mesh-config): implement applying
selankon Nov 12, 2024
f0e2bbc
chore(mesh-config): fixes key name
javierbrk Nov 21, 2024
a9b3ae7
chore(mesh-config): implement spanish translation
javierbrk Nov 21, 2024
ccd6cce
f_mc: fixes some text related to upgrade
javierbrk Nov 27, 2024
629ec2a
chore(mesh-config): fix parser to ignore \\t
selankon Dec 3, 2024
a3ded95
chore(mesh-config): fix full screen modal loading
selankon Dec 3, 2024
c035956
chore(mesh-config): fix message
selankon Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(mesh-config): create standarized api call
selankon committed Dec 3, 2024
commit 6941e61bc625fcc73cf545abe7fb89e854730030
32 changes: 11 additions & 21 deletions plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeApi.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
MeshUpgradeApiError,
callToRemoteNode,
} from "components/shared-state/SharedStateApi";
import { callToRemoteNode } from "components/shared-state/SharedStateApi";
import { sharedStateQueries } from "components/shared-state/SharedStateQueriesKeys";

import { meshUpgradeSharedStateKey } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeQueriesKeys";
@@ -11,20 +8,16 @@ import {
NodeMeshUpgradeInfo,
} from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeTypes";

import { ApiServiceParamsType, standarizedApiCall } from "utils/standarizedApi";
import api, { UhttpdService } from "utils/uhttpd.service";

// todo(kon): refactor this to use doSharedStateApiCall??
export const getMeshWideUpgradeInfo = async () => {
const query = sharedStateQueries.getFromSharedState(
meshUpgradeSharedStateKey
);
const res = await api.call(...query);
if (res.error) {
throw new Error(
`Error getting mesh wide upgrade info from shared state async, code error ${res.error}`
);
}
return res.data as MeshWideUpgradeInfo;
return standarizedApiCall<MeshWideUpgradeInfo>({
args: query as ApiServiceParamsType,
});
};

export const getMeshUpgradeNodeStatus = async () => {
@@ -76,13 +69,10 @@ const meshUpgradeApiCall = async (
customApi?: UhttpdService
) => {
const httpService = customApi || api;
const res = (await httpService.call(
"lime-mesh-upgrade",
method,
{}
)) as MeshWideRPCReturnTypes;
if (res.error) {
throw new MeshUpgradeApiError(res.error, res.code);
}
return res.code;
return (
(await standarizedApiCall({
apiService: httpService,
args: ["lime-mesh-upgrade", method, {}],
})) as MeshWideRPCReturnTypes
).code;
};
17 changes: 2 additions & 15 deletions src/components/shared-state/SharedStateApi.ts
Original file line number Diff line number Diff line change
@@ -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<T>({
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);
}
}
22 changes: 18 additions & 4 deletions src/components/shared-state/SharedStateQueriesKeys.ts
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 42 additions & 0 deletions src/utils/standarizedApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 <T>({
apiService = api,
args,
}: {
apiService?: UhttpdService;
args: ApiServiceParamsType;
}) => {
const res = await apiService.call(...args);
if (res?.error) {
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);
}
}