Commit 300987bb authored by Kushal Pandya's avatar Kushal Pandya

Add methods to remove & format node object

parent 8d8a9563
......@@ -8,7 +8,9 @@ export default class GeoNodesStore {
}
setNodes(nodes) {
this.state.nodes = nodes;
this.state.nodes = nodes.map(
node => GeoNodesStore.formatNode(node),
);
}
getNodes() {
......@@ -19,6 +21,16 @@ export default class GeoNodesStore {
this.state.nodeDetails[nodeId] = GeoNodesStore.formatNodeDetails(nodeDetails);
}
removeNode(node) {
const indexOfRemovedNode = this.state.nodes.indexOf(node);
if (indexOfRemovedNode > -1) {
this.state.nodes.splice(indexOfRemovedNode, 1);
if (this.state.nodeDetails[node.id]) {
delete this.state.nodeDetails[node.id];
}
}
}
getPrimaryNodeVersion() {
return {
version: this.state.primaryVersion,
......@@ -30,6 +42,22 @@ export default class GeoNodesStore {
return this.state.nodeDetails[nodeId];
}
static formatNode(rawNode) {
const { id, url, primary, current, enabled } = rawNode;
return {
id,
url,
primary,
current,
enabled,
nodeActionActive: false,
basePath: rawNode._links.self,
repairPath: rawNode._links.repair,
editPath: rawNode.web_edit_url,
statusPath: rawNode._links.status,
};
}
static formatNodeDetails(rawNodeDetails) {
return {
id: rawNodeDetails.geo_node_id,
......@@ -41,8 +69,9 @@ export default class GeoNodesStore {
primaryVersion: rawNodeDetails.primaryVersion,
primaryRevision: rawNodeDetails.primaryRevision,
replicationSlotWAL: rawNodeDetails.replication_slots_max_retained_wal_bytes,
missingOAuthApplication: rawNodeDetails.missing_oauth_application,
missingOAuthApplication: rawNodeDetails.missing_oauth_application || false,
storageShardsMatch: rawNodeDetails.storage_shards_match,
syncStatusUnavailable: rawNodeDetails.sync_status_unavailable || false,
replicationSlots: {
totalCount: rawNodeDetails.replication_slots_count || 0,
successCount: rawNodeDetails.replication_slots_used_count || 0,
......
......@@ -22,7 +22,7 @@ describe('GeoNodesStore', () => {
describe('setNodes', () => {
it('sets nodes list to state', () => {
store.setNodes(mockNodes);
expect(store.getNodes()).toBe(mockNodes);
expect(store.getNodes().length).toBe(mockNodes.length);
});
});
......@@ -33,6 +33,28 @@ describe('GeoNodesStore', () => {
});
});
describe('removeNode', () => {
it('removes node from store state', () => {
store.setNodes(mockNodes);
const nodeToBeRemoved = store.getNodes()[1];
store.removeNode(nodeToBeRemoved);
store.getNodes().forEach((node) => {
expect(node.id).not.toBe(nodeToBeRemoved);
});
});
});
describe('formatNode', () => {
it('returns formatted raw node object', () => {
const node = GeoNodesStore.formatNode(mockNodes[0]);
expect(node.id).toBe(mockNodes[0].id);
expect(node.url).toBe(mockNodes[0].url);
expect(node.basePath).toBe(mockNodes[0]._links.self);
expect(node.repairPath).toBe(mockNodes[0]._links.repair);
expect(node.nodeActionActive).toBe(false);
});
});
describe('formatNodeDetails', () => {
it('returns formatted raw node details object', () => {
const nodeDetails = GeoNodesStore.formatNodeDetails(rawMockNodeDetails);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment