Skip to content

Commit

Permalink
chore(mesh-wide): Improve messages
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Jul 1, 2024
1 parent ceb3cf3 commit d6080ae
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const LinkFeatureDetail = ({ actual, reference }: LinkMapFeature) => {
};

export const LinkReferenceStatus = ({ reference }: LinkMapFeature) => {
const isNewNode = !reference;
const isNewLink = !reference;

const { errors } = usePointToPointErrors({
id: reference.id,
Expand Down Expand Up @@ -318,14 +318,29 @@ export const LinkReferenceStatus = ({ reference }: LinkMapFeature) => {
errorMessage = <Trans>Reference is not set or has errors</Trans>;
} else if (errors?.hasErrors) {
errorMessage = <Trans>This link has errors</Trans>;
} else if (isNewNode) {
} else if (isNewLink) {
errorMessage = (
<Trans>This Link is not registered on the reference state</Trans>
);
}

const hasError = errors?.hasErrors || referenceError;
const showSetReferenceButton = isDown || isNewNode || referenceError;
const showSetReferenceButton =
errors?.hasErrors || isDown || isNewLink || referenceError;

console.log(
"AAAAA",
"hasError",
hasError,
"showSetReferenceButton",
showSetReferenceButton,
"isDown",
isDown,
"isNewNode",
isNewLink,
"referenceError",
referenceError
);

return (
<StatusAndButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ const NodeDetails = ({ actual, reference, name }: NodeMapFeature) => {
const device = actual.device;
const macs = actual.macs;

let newMacs = [];
let notFoundMacs = [];
if (errors.includes(NodeErrorCodes.MACS_MISSMATCH)) {
notFoundMacs = getArrayDifference(reference.macs, macs);
newMacs = getArrayDifference(macs, reference.macs);
}

return (
<div>
<Row>
Expand Down Expand Up @@ -84,28 +91,54 @@ const NodeDetails = ({ actual, reference, name }: NodeMapFeature) => {
</TitleAndText>
</Row>
<Row>
<TitleAndText title={<Trans>Macs</Trans>}>
<TitleAndText title={<Trans>Macs ({macs.length})</Trans>}>
<div>
{macs.map((mac, k) => (
<div key={k}>{mac}</div>
))}
</div>
</TitleAndText>
{errors.includes(NodeErrorCodes.MACS_MISSMATCH) && (
<TitleAndText
title={<Trans>Macs not found</Trans>}
error={
<Trans>This macs are not on the actual state</Trans>
}
>
<>
{getArrayDifference(reference.macs, macs).map(
(mac, k) => (
<div key={k}>{mac}</div>
)
)}
</>
</TitleAndText>
<div className={"flex flex-col gap-4"}>
{notFoundMacs && (
<TitleAndText
title={
<Trans>
Macs not found ({notFoundMacs.length})
</Trans>
}
error={
<Trans>
This macs are not on the actual state
</Trans>
}
>
<>
{notFoundMacs.map((mac, k) => (
<div key={k}>{mac}</div>
))}
</>
</TitleAndText>
)}
{newMacs && (
<TitleAndText
title={
<Trans>New Macs ({newMacs.length})</Trans>
}
error={
<Trans>
This macs are not on the reference state
</Trans>
}
>
<>
{newMacs.map((mac, k) => (
<div key={k}>{mac}</div>
))}
</>
</TitleAndText>
)}
</div>
)}
</Row>
</div>
Expand Down Expand Up @@ -193,12 +226,13 @@ export const NodeReferenceStatus = ({ actual, reference }: NodeMapFeature) => {
);
}

const hasErrors = hasNodeErrors || referenceError || isNewNode;
const hasErrors = hasNodeErrors || referenceError;
const showSetReferenceButton = hasNodeErrors || isNewNode || referenceError;

return (
<StatusAndButton
isError={hasErrors}
btn={hasErrors && btnText}
btn={showSetReferenceButton && btnText}
onClick={setReferenceState}
>
{errorMessage}
Expand Down
12 changes: 6 additions & 6 deletions plugins/lime-plugin-mesh-wide/src/lib/nodes/processErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export const processNodeErrors = (
}
const sortedRefMacs = reference.macs.slice().sort();
const sortedActualMacs = actual.macs.slice().sort();

for (let i = 0; i < sortedRefMacs.length; i++) {
if (sortedRefMacs[i] !== sortedActualMacs[i]) {
errors.push(NodeErrorCodes.MACS_MISSMATCH);
break;
}
if (
!sortedRefMacs.every(
(value, index) => value === sortedActualMacs[index]
)
) {
errors.push(NodeErrorCodes.MACS_MISSMATCH);
}

return errors;
Expand Down

0 comments on commit d6080ae

Please sign in to comment.