Skip to content

Commit

Permalink
refactor(networknodes): fix api format
Browse files Browse the repository at this point in the history
  • Loading branch information
germanferrero committed Jan 27, 2022
1 parent f29f46d commit 2e7bf51
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
22 changes: 11 additions & 11 deletions plugins/lime-plugin-delete-nodes/deleteNodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jest.mock('plugins/lime-plugin-network-nodes/src/networkNodesApi');

describe('delete nodes page', () => {
beforeEach(() => {
getNodes.mockImplementation(async () => [
{ hostname: 'node1', status: 'recently_reachable' },
{ hostname: 'node2', status: 'recently_reachable' },
{ hostname: 'node3', status: 'recently_reachable' },
{ hostname: 'node4', status: 'unreachable' },
{ hostname: 'node5', status: 'unreachable' },
{ hostname: 'node6', status: 'unreachable' },
{ hostname: 'node7', status: 'unreachable' },
{ hostname: 'node8', status: 'gone' },
{ hostname: 'node9', status: 'gone' },
]);
getNodes.mockImplementation(async () => ({
'node1': { hostname: 'node1', status: 'recently_reachable' },
'node2': { hostname: 'node2', status: 'recently_reachable' },
'node3': { hostname: 'node3', status: 'recently_reachable' },
'node4': { hostname: 'node4', status: 'unreachable' },
'node5': { hostname: 'node5', status: 'unreachable' },
'node6': { hostname: 'node6', status: 'unreachable' },
'node7': { hostname: 'node7', status: 'unreachable' },
'node8': { hostname: 'node8', status: 'gone' },
'node9': { hostname: 'node9', status: 'gone' },
}));
markNodesAsGone.mockImplementation(async () => []);
});

Expand Down
2 changes: 1 addition & 1 deletion plugins/lime-plugin-delete-nodes/src/deleteNodesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import I18n from 'i18n-js';
export const DeleteNodesPage_ = ({ nodes, onDelete, isSubmitting, isSuccess }) => {
const [selectedNodes, { toggle, has, reset }] = useSet(new Set([]));
const [showSuccess, setshowSuccess] = useState(false);
const unreachableNodes = nodes.filter(n => n.status === "unreachable");
const unreachableNodes = Object.values(nodes).filter(n => n.status === "unreachable");

useEffect(() => {
if (isSuccess) {
Expand Down
9 changes: 5 additions & 4 deletions plugins/lime-plugin-network-nodes/src/networkNodesQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export const useNetworkNodes = () =>
export const useMarkNodesAsGone = () => useMutation(markNodesAsGone, {
onSuccess: hostnames => queryCache.setQueryData(['network-nodes', 'get_nodes'],
old => {
const result = old.map(
node => hostnames.indexOf(node.hostname) != -1 ? { ...node, status: "gone" } : node
)
const result = old;
hostnames.forEach(hostname => {
result[hostname] = {...old[hostname], status: "gone"}
});
return result;
}
)
})
})
22 changes: 11 additions & 11 deletions plugins/lime-plugin-reachable-nodes/reachableNodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import { render } from 'utils/test_utils';
jest.mock('plugins/lime-plugin-network-nodes/src/networkNodesApi');

beforeEach(() => {
getNodes.mockImplementation(async () => [
{ hostname: 'node1', status: 'recently_reachable' },
{ hostname: 'node2', status: 'recently_reachable' },
{ hostname: 'node3', status: 'recently_reachable' },
{ hostname: 'node4', status: 'unreachable' },
{ hostname: 'node5', status: 'unreachable' },
{ hostname: 'node6', status: 'unreachable' },
{ hostname: 'node7', status: 'unreachable' },
{ hostname: 'node8', status: 'gone' },
{ hostname: 'node9', status: 'gone' },
]);
getNodes.mockImplementation(async () => ({
'node1': { hostname: 'node1', status: 'recently_reachable' },
'node2': { hostname: 'node2', status: 'recently_reachable' },
'node3': { hostname: 'node3', status: 'recently_reachable' },
'node4': { hostname: 'node4', status: 'unreachable' },
'node5': { hostname: 'node5', status: 'unreachable' },
'node6': { hostname: 'node6', status: 'unreachable' },
'node7': { hostname: 'node7', status: 'unreachable' },
'node8': { hostname: 'node8', status: 'gone' },
'node9': { hostname: 'node9', status: 'gone' },
}));
markNodesAsGone.mockImplementation(async () => []);
});

Expand Down
7 changes: 3 additions & 4 deletions plugins/lime-plugin-reachable-nodes/src/reachableNodesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const PageHelp = () => (
);

const PageTabs = ({ nodes, ...props }) => {
const nReachable = nodes.filter(n => n.status === "recently_reachable").length;
const nUnreachable = nodes.filter(n => n.status === "unreachable").length;
const nReachable = Object.values(nodes).filter(n => n.status === "recently_reachable").length;
const nUnreachable = Object.values(nodes).filter(n => n.status === "unreachable").length;
const tabs = [
{ key: 'recently_reachable', repr: I18n.t('Reachable (%{howMany})', { howMany: nReachable }) },
{ key: 'unreachable', repr: I18n.t('Unreachable (%{howMany})', { howMany: nUnreachable }) },
Expand All @@ -39,7 +39,6 @@ const PageTabs = ({ nodes, ...props }) => {
export const ReachableNodesPage_ = ({ nodes }) => {
const [ selectedGroup, setselectedGroup ] = useState('recently_reachable');
const [ unfoldedNode, setunfoldedNode ] = useState(null);

function changeUnfolded(hostname) {
if (unfoldedNode == hostname) {
setunfoldedNode(null);
Expand All @@ -56,7 +55,7 @@ export const ReachableNodesPage_ = ({ nodes }) => {
</div>
</div>
<List>
{nodes
{Object.values(nodes)
.filter(n => n.status === selectedGroup)
.sort((a, b) => a.hostname > b.hostname)
.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const UpgradedNodesPage = () => {

useEffect(() => {
if (nodes && newVersion) {
const taggedNodes = [...nodes].map(
const taggedNodes = [...Object.values(nodes)].map(
n => ({
...n,
group: n.fw_version === newVersion.version ? 'upgraded' : 'not_upgraded'
Expand Down
12 changes: 6 additions & 6 deletions plugins/lime-plugin-upgraded-nodes/upgradedNodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jest.mock('plugins/lime-plugin-firmware/src/firmwareApi');

describe('upgradedNodes', () => {
beforeEach(() => {
getNodes.mockImplementation(async () => [
{ hostname: 'node1', status: 'unreachable', fw_version: 'LibreRouterOS 1.4' },
{ hostname: 'node2', status: 'recently_reachable', fw_version: 'LibreRouterOS 1.4' },
{ hostname: 'node3', status: 'unreachable', fw_version: 'LibreRouterOS 1.3' },
{ hostname: 'node4', status: 'recently_reachable', fw_version: 'LibreRouterOS 1.3' },
]);
getNodes.mockImplementation(async () => ({
'node1': { hostname: 'node1', status: 'unreachable', fw_version: 'LibreRouterOS 1.4' },
'node2': { hostname: 'node2', status: 'recently_reachable', fw_version: 'LibreRouterOS 1.4' },
'node3': { hostname: 'node3', status: 'unreachable', fw_version: 'LibreRouterOS 1.3' },
'node4': { hostname: 'node4', status: 'recently_reachable', fw_version: 'LibreRouterOS 1.3' },
}));
getNewVersion.mockImplementation(async () => ({
version: 'LibreRouterOS 1.4'
}))
Expand Down

0 comments on commit 2e7bf51

Please sign in to comment.