Skip to content

Commit

Permalink
chore(mesh-wide): create dataTypeNameMapping
Browse files Browse the repository at this point in the history
fix #434
  • Loading branch information
selankon committed Aug 21, 2024
1 parent 1ad9768 commit 7a7116b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
} from "plugins/lime-plugin-mesh-wide/src/hooks/useLocatedLinks";
import { useNodes } from "plugins/lime-plugin-mesh-wide/src/hooks/useNodes";
import { MacToMacLink } from "plugins/lime-plugin-mesh-wide/src/lib/links/PointToPointLink";
import { readableBytes } from "plugins/lime-plugin-mesh-wide/src/lib/utils";
import {
dataTypeNameMapping,
readableBytes,
} from "plugins/lime-plugin-mesh-wide/src/lib/utils";
import { useSetLinkReferenceState } from "plugins/lime-plugin-mesh-wide/src/meshWideQueries";
import {
BaseMacToMacLink,
Expand Down Expand Up @@ -315,13 +318,13 @@ export const LinkReferenceStatus = ({ reference }: LinkMapFeature) => {
let btnText = (
<Trans>
Set reference state for this
<br /> {reference.type} link
<br /> {dataTypeNameMapping(reference.type)}
</Trans>
);
if (isDown) {
btnText = (
<Trans>
Delete this {reference.type} link
Delete this {dataTypeNameMapping(reference.type)}
<br />
from reference state
</Trans>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Trans } from "@lingui/macro";

import { SharedStateDataTypeKeys } from "components/shared-state/SharedStateTypes";

import { Row } from "plugins/lime-plugin-mesh-wide/src/components/FeatureDetail/index";
import { dataTypeNameMapping } from "plugins/lime-plugin-mesh-wide/src/lib/utils";
import { ErrorsDetails } from "plugins/lime-plugin-mesh-wide/src/meshWideTypes";

export const ShowErrorsDetail = ({ errors }: { errors: ErrorsDetails }) => {
Expand Down Expand Up @@ -45,7 +48,7 @@ export const ShowErrorsDetail = ({ errors }: { errors: ErrorsDetails }) => {
return (
<div key={k} className={"flex flex-row gap-5"}>
<div className={"text-2xl font-bold"}>
{dataType}
{dataTypeNameMapping(dataType)}
</div>
{nodes && (
<Trans>
Expand All @@ -71,12 +74,19 @@ export const ShowErrorsDetail = ({ errors }: { errors: ErrorsDetails }) => {
Are they installed or properly initialized?
</Trans>
</Row>
{[...errors.meshWideDataErrors].map((data, k) => (
<div key={k}>
{JSON.stringify(data.queryKey, null, 2)}:{" "}
{data?.error?.toString()}
</div>
))}
{[...errors.meshWideDataErrors].map((data, k) => {
const queryKey = JSON.stringify(
data.queryKey,
null,
2
) as SharedStateDataTypeKeys;
return (
<div key={k}>
{dataTypeNameMapping(queryKey)}:{" "}
{data?.error?.toString()}
</div>
);
})}
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useForm } from "react-hook-form";
import { ModalActions, useModal } from "components/Modal/Modal";
import InputField from "components/inputs/InputField";

import { dataTypeNameMapping } from "plugins/lime-plugin-mesh-wide/src/lib/utils";
import { MeshWideMapDataTypeKeys } from "plugins/lime-plugin-mesh-wide/src/meshWideTypes";

const useActionModal = (
Expand Down Expand Up @@ -126,14 +127,19 @@ export const useSetLinkReferenceStateModal = () => {
cb: () => Promise<void>
) => {
let title = (
<Trans>Set reference state for this {dataType} link?</Trans>
<Trans>
Set reference state for this {dataTypeNameMapping(dataType)}?
</Trans>
);
let content = (
<Trans>This will set the reference state of this link:</Trans>
);
if (isDown) {
title = (
<Trans>Remove this {dataType} from the reference state</Trans>
<Trans>
Remove this {dataTypeNameMapping(dataType)} from the
reference state
</Trans>
);
content = (
<Trans>
Expand Down
25 changes: 23 additions & 2 deletions plugins/lime-plugin-mesh-wide/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { INodes } from "plugins/lime-plugin-mesh-wide/src/meshWideTypes";
import { t } from "@lingui/macro";

import { SharedStateDataTypeKeys } from "components/shared-state/SharedStateTypes";

import { isEmpty } from "utils/utils";
import { INodes } from "plugins/lime-plugin-mesh-wide/src/meshWideTypes";

export const readableBytes = (bytes: number) => {
const sizes = ["B", "KB", "MB", "GB", "TB"];
Expand Down Expand Up @@ -65,3 +67,22 @@ export const splitNodesByLocated = (nodeList: INodes): ISplitNodesByLocated => {

return { locatedNodes, nonLocatedNodes };
};

export const dataTypeNameMapping = (dataType: SharedStateDataTypeKeys) => {
switch (dataType) {
case "node_info":
return t`Node Info`;
case "node_info_ref":
return t`Node Info Reference`;
case "wifi_links_info":
return t`Wifi Links`;
case "wifi_links_info_ref":
return t`Wifi Links Reference`;
case "bat_links_info":
return t`Batman Links`;
case "bat_links_info_ref":
return t`Batman Links Reference`;
default:
return dataType;
}
};

0 comments on commit 7a7116b

Please sign in to comment.