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 wired role configuration #467

Draft
wants to merge 5 commits into
base: f/v3-candidate
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions plugins/lime-plugin-rx/src/rxApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
IGetInternetStatus,
StatusResponse,
SupportedPortRoles,
SwitchStatus,
} from "plugins/lime-plugin-rx/src/rxTypes";

import api from "utils/uhttpd.service";
Expand All @@ -10,3 +12,16 @@ export const getNodeStatus = (): Promise<StatusResponse> =>

export const getInternetStatus = (): Promise<IGetInternetStatus> =>
api.call("lime-metrics", "get_internet_status", {});

export type SetPortRoleArgs = { role: SupportedPortRoles } & Omit<
SwitchStatus,
"role"
>;

export const setPortRole = async (
newStatus: SetPortRoleArgs
): Promise<boolean> => {
console.log("Setting port role", newStatus);
await new Promise((resolve) => setTimeout(resolve, 2000));
return true;
};
29 changes: 27 additions & 2 deletions plugins/lime-plugin-rx/src/rxQueries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { useQuery } from "@tanstack/react-query";
import { MutationKey } from "@tanstack/query-core/src/types";
import {
UseMutationOptions,
useMutation,
useQuery,
} from "@tanstack/react-query";

import { getInternetStatus, getNodeStatus } from "./rxApi";
import { SupportedPortRoles } from "plugins/lime-plugin-rx/src/rxTypes";

import {
SetPortRoleArgs,
getInternetStatus,
getNodeStatus,
setPortRole,
} from "./rxApi";

const refetchInterval = 2000;

Expand All @@ -24,3 +36,16 @@ export function useInternetStatus(params?) {
...params,
});
}

export const useSetPortRole = (
options?: Omit<
UseMutationOptions<boolean, Error, SetPortRoleArgs>,
"mutationFn" | "mutationKey"
>
) => {
return useMutation<boolean, Error, SetPortRoleArgs>({
mutationFn: setPortRole,
mutationKey: ["useSetPortRole"] as MutationKey,
...options,
});
};
6 changes: 6 additions & 0 deletions plugins/lime-plugin-rx/src/rxTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ export interface IGetInternetStatus {
IPv4: { working: boolean };
status: string;
}

export enum SupportedPortRoles {
WAN = "wan",
LAN = "lan",
MESH = "mesh",
}
7 changes: 7 additions & 0 deletions plugins/lime-plugin-rx/src/sections/system.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ const SystemInfo = () => {

const boardData = bd as IGetBoardDataResponse;
const secNum = parseInt(node?.uptime, 10);
const ips =
node?.ips.map((ip) => ({
label: `IPv${ip.version}`,
value: ip.address,
})) || [];
const attributes = [
{
label: t`Uptime`,
value: toHHMMSS(node?.uptime, 0),
},
{ label: t`Device`, value: boardData.board_name },
{ label: t`Firmware`, value: boardData.release.description },
...ips,
];

return (
<div className="flex justify-start px-10">
<div className="grid grid-cols-4 gap-4">
Expand Down
Loading
Loading