Skip to content

Commit

Permalink
Code refactoring and handling of multiple spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Palt committed Aug 16, 2024
1 parent cd36147 commit 6c7c2ee
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions cmd/ui/src/ducks/explore/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//
// SPDX-License-Identifier: Apache-2.0

import { OWNED_OBJECT_TAG, TIER_ZERO_TAG } from 'bh-shared-ui';
import { produce } from 'immer';
import * as types from 'src/ducks/explore/types';

Expand Down Expand Up @@ -50,36 +51,16 @@ const graphDataReducer = (state = initialGraphDataState, action: types.GraphActi
draft.export = action.payload;
} else if (action.type === types.TOGGLE_TIER_ZERO_NODE) {
const systemTags = state.chartProps.items[action.nodeId].data.system_tags;
// remove the tier zero tag from the node
if (systemTags.includes('admin_tier_0')) {
// check if node is marked as owned or not
{ systemTags.includes('owned') ?
draft.chartProps.items[action.nodeId].data.system_tags = 'owned' :
draft.chartProps.items[action.nodeId].data.system_tags = ''
}
} else {
// check if node is marked as owned or not
{ systemTags.includes('owned') ?
draft.chartProps.items[action.nodeId].data.system_tags = 'admin_tier_0 owned' :
draft.chartProps.items[action.nodeId].data.system_tags = 'admin_tier_0'
}
}
if (systemTags.includes(TIER_ZERO_TAG)) {
// Regex to remove multiple spaces in case of more system tags in the future
draft.chartProps.items[action.nodeId].data.system_tags = systemTags.replace(TIER_ZERO_TAG, '').trim().replace(/ {2,}/g, " ");
} else draft.chartProps.items[action.nodeId].data.system_tags = `${systemTags} ${TIER_ZERO_TAG}`;
} else if (action.type === types.TOGGLE_OWNED_OBJECT_NODE) {
const systemTags = state.chartProps.items[action.nodeId].data.system_tags;
// remove the owned object tag from the node
if (systemTags.includes('owned')) {
// check if node is marked as tier zero
{ systemTags.includes('admin_tier_0') ?
draft.chartProps.items[action.nodeId].data.system_tags = 'admin_tier_0' :
draft.chartProps.items[action.nodeId].data.system_tags = ''
}
} else {
// check if node is marked as tier zero
{ systemTags.includes('admin_tier_0') ?
draft.chartProps.items[action.nodeId].data.system_tags = 'admin_tier_0 owned' :
draft.chartProps.items[action.nodeId].data.system_tags = 'owned'
}
}
const systemTags = state.chartProps.items[action.nodeId].data.system_tags;
if (systemTags.includes(OWNED_OBJECT_TAG)) {
// Regex to remove multiple spaces in case of more system tags in the future
draft.chartProps.items[action.nodeId].data.system_tags = systemTags.replace(OWNED_OBJECT_TAG, '').trim().replace(/ {2,}/g, " ");
} else draft.chartProps.items[action.nodeId].data.system_tags = `${systemTags} ${OWNED_OBJECT_TAG}`;
}
return draft;
});
Expand Down

0 comments on commit 6c7c2ee

Please sign in to comment.