Skip to content

Commit

Permalink
chore(mesh-wide): fix set ref state for new links
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Sep 5, 2024
1 parent 75c87fc commit 70add54
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ const SelectedLink = ({
);
};

const LinkFeatureDetail = ({ actual, reference }: LinkMapFeature) => {
const linkToShow = reference ?? actual;
const LinkFeatureDetail = ({ linkToShow, actual }: LinkMapFeature) => {
// const linkToShow = reference ?? actual;
const [selectedLink, setSelectedLink] = useState(0);
const { errors } = usePointToPointErrors({
id: linkToShow.id,
Expand Down Expand Up @@ -224,12 +224,15 @@ const LinkFeatureDetail = ({ actual, reference }: LinkMapFeature) => {
);
};

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

const { errors } = usePointToPointErrors({
id: reference.id,
type: reference.type,
id: linkToShow.id,
type: linkToShow.type,
});

const {
Expand All @@ -240,7 +243,7 @@ export const LinkReferenceStatus = ({ reference }: LinkMapFeature) => {

// Check if there are errors of global reference state to shown
const { reference: fetchDataReference } = getQueryByLinkType(
reference.type
linkToShow.type
);
const { data: referenceData, isError: isReferenceError } =
fetchDataReference({});
Expand All @@ -263,27 +266,27 @@ export const LinkReferenceStatus = ({ reference }: LinkMapFeature) => {
};
if (!allNodes) return {};
// Then reduce the nodes to update
return reference.nodes.reduce((acc, node) => {
return linkToShow.nodes.reduce((acc, node) => {
// If the node with node name exist get the ipv4 and hostname
if (allNodes[node]) {
acc[allNodes[node].ipv4] = allNodes[node].hostname;
}
return acc;
}, {});
}, [meshWideNodesReference, meshWideNodesActual, reference.nodes]);
}, [meshWideNodesReference, meshWideNodesActual, linkToShow.nodes]);

// Mutation to update the reference state
const { callMutations } = useSetLinkReferenceState({
linkType: reference.type,
linkToUpdate: reference,
linkType: linkToShow.type,
linkToUpdate: linkToShow,
isDown,
nodesToUpdate,
});

// Show confirmation modal before run mutations
const setReferenceState = useCallback(async () => {
confirmModal(
reference.type,
linkToShow.type,
Object.values(nodesToUpdate),
isDown,
async () => {
Expand Down Expand Up @@ -311,35 +314,36 @@ export const LinkReferenceStatus = ({ reference }: LinkMapFeature) => {
confirmModal,
isDown,
nodesToUpdate,
reference.type,
linkToShow.type,
showToast,
]);

let btnText = (
<Trans>
Set reference state for this
<br /> {dataTypeNameMapping(reference.type)}
<br /> {dataTypeNameMapping(linkToShow.type)}
</Trans>
);
if (isDown) {
btnText = (
<Trans>
Delete this {dataTypeNameMapping(reference.type)}
Delete this {dataTypeNameMapping(linkToShow.type)}
<br />
from reference state
</Trans>
);
}

let errorMessage = <Trans>Same status as in the reference state</Trans>;
if (referenceError) {
errorMessage = <Trans>Reference is not set or has errors</Trans>;
} else if (errors?.hasErrors) {
errorMessage = <Trans>This link has errors</Trans>;
} else if (isNewLink) {

if (isNewLink) {
errorMessage = (
<Trans>This Link is not registered on the reference state</Trans>
);
} else if (referenceError) {
errorMessage = <Trans>Reference is not set or has errors</Trans>;
} else if (errors?.hasErrors) {
errorMessage = <Trans>This link has errors</Trans>;
}

const hasError = errors?.hasErrors || referenceError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export const LinkLine = ({ referenceLink, actualLink }: ILinkLineProps) => {
const _setSelectedFeature = () => {
setSelectedMapFeature({
id: linkToShow.id,
feature: { reference: linkToShow, actual: actualLink },
feature: {
reference: referenceLink,
actual: actualLink,
linkToShow,
},
type: "link",
});
};
Expand Down
3 changes: 2 additions & 1 deletion plugins/lime-plugin-mesh-wide/src/meshWideTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export type INodes = { [key: string]: INodeInfo };

export type LinkMapFeature = {
actual: PontToPointLink;
reference: PontToPointLink;
reference?: PontToPointLink;
linkToShow: PontToPointLink;
};

export type NodeMapFeature = {
Expand Down

0 comments on commit 70add54

Please sign in to comment.