Skip to content

Commit

Permalink
chore(mesh-wide): fix reference state is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Sep 5, 2024
1 parent 70add54 commit d98afb0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,38 +285,23 @@ export const LinkReferenceStatus = ({

// Show confirmation modal before run mutations
const setReferenceState = useCallback(async () => {
confirmModal(
linkToShow.type,
Object.values(nodesToUpdate),
isDown,
async () => {
try {
const res = await callMutations();
if (res.errors.length) {
console.log("Errors");
throw new Error("Error setting new reference state!");
}
showToast({
text: <Trans>New reference state set!</Trans>,
});
} catch (error) {
showToast({
text: <Trans>Error setting new reference state!</Trans>,
});
} finally {
closeModal();
}
try {
const res = await callMutations();
if (res.errors.length) {
console.log("Errors");
throw new Error("Error setting new reference state!");
}
);
}, [
callMutations,
closeModal,
confirmModal,
isDown,
nodesToUpdate,
linkToShow.type,
showToast,
]);
showToast({
text: <Trans>New reference state set!</Trans>,
});
} catch (error) {
showToast({
text: <Trans>Error setting new reference state!</Trans>,
});
} finally {
closeModal();
}
}, [callMutations, closeModal, showToast]);

let btnText = (
<Trans>
Expand Down Expand Up @@ -354,7 +339,14 @@ export const LinkReferenceStatus = ({
<StatusAndButton
isError={hasError}
btn={showSetReferenceButton && btnText}
onClick={setReferenceState}
onClick={() =>
confirmModal({
dataType: linkToShow.type,
nodes: Object.values(nodesToUpdate),
isDown,
cb: setReferenceState,
})
}
>
{errorMessage}
</StatusAndButton>
Expand Down
17 changes: 11 additions & 6 deletions plugins/lime-plugin-mesh-wide/src/components/configPage/modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,17 @@ export const useSetNodeInfoReferenceStateModal = () => {
export const useSetLinkReferenceStateModal = () => {
const { toggleModal, setModalState, isModalOpen, closeModal } = useModal();

const confirmModal = (
dataType: MeshWideMapDataTypeKeys,
nodes: string[],
isDown: boolean,
cb: () => Promise<void>
) => {
const confirmModal = ({
dataType,
nodes,
isDown,
cb,
}: {
dataType: MeshWideMapDataTypeKeys;
nodes: string[];
isDown: boolean;
cb: () => Promise<void>;
}) => {
let title = (
<Trans>
Set reference state for this {dataTypeNameMapping(dataType)}?
Expand Down
12 changes: 10 additions & 2 deletions plugins/lime-plugin-mesh-wide/src/meshWideQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {

import { useMeshWideSyncCall } from "utils/meshWideSyncCall";
import { useSharedData } from "utils/useSharedData";
import { isEmpty } from "utils/utils";

const refetchInterval = 60000;

Expand Down Expand Up @@ -169,8 +170,9 @@ export const useSetLinkReferenceState = ({

let newReferenceLinks = (referenceData[hostname] ??
{}) as IBaseLink<typeof linkType>;
// This is a hotfix because backend returns an empty string somtimes
if (typeof newReferenceLinks !== "object") newReferenceLinks = {};

// This is a hotfix because backend returns an empty array sometimes
if (isEmpty(newReferenceLinks)) newReferenceLinks = {};

for (const mactomac of linkToUpdate.links) {
if (isDown) {
Expand All @@ -194,6 +196,12 @@ export const useSetLinkReferenceState = ({
},
} as ILinks<typeof linkType>
);
console.log("linkToUpdate", linkToUpdate);
console.log("newReferenceLinks", newReferenceLinks);
console.log("referenceData", referenceData);
console.log("data[hostname]", data[hostname]);
console.log("hostname", hostname);
console.log("queryKey", queryKey);
return doSharedStateApiCall<typeof linkType>(queryKey, ip);
},
ips: Object.keys(nodesToUpdate),
Expand Down

0 comments on commit d98afb0

Please sign in to comment.