Skip to content

Commit

Permalink
Add guards to node details networking functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Ellis committed Apr 16, 2020
1 parent 74694e0 commit b1de52b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
24 changes: 11 additions & 13 deletions legacy/src/app/controllers/node_details_networking.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ export function NodeNetworkingController(
}
];

$scope.isBond = item => item.type === "bond";
$scope.isBridge = item => item.type === "bridge";
$scope.isInterface = item => item.type === "physical";
$scope.isBond = item => item.type && item.type === "bond";
$scope.isBridge = item => item.type && item.type === "bridge";
$scope.isInterface = item => item.type && item.type === "physical";

// Sets loaded to true if both the node has been loaded at the
// other required managers for this scope have been loaded.
Expand Down Expand Up @@ -2029,18 +2029,16 @@ export function NodeNetworkingController(
// Return true when a bridge can be created based on the current
// selection. Only can be done if no aliases are selected and only
// one interface is selected.
$scope.canCreateBridge = function() {
if ($scope.selectedMode !== SELECTION_MODE.SINGLE) {
return false;
}
var nic = getSelectedInterfaces()[0];
if (
nic.type === INTERFACE_TYPE.ALIAS ||
nic.type === INTERFACE_TYPE.BRIDGE
) {
$scope.canCreateBridge = () => {
const selectedInterfaces = getSelectedInterfaces();
const nic = selectedInterfaces.length && selectedInterfaces[0];

if ($scope.selectedMode !== SELECTION_MODE.SINGLE || !nic) {
return false;
}
return true;
return !(
nic.type === INTERFACE_TYPE.ALIAS || nic.type === INTERFACE_TYPE.BRIDGE
);
};

// Return true when the create bridge view is being shown.
Expand Down
6 changes: 3 additions & 3 deletions legacy/src/app/partials/node-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,9 @@ <h2 class="p-heading--four">Create bridge</h2>
<td class="p-double-row" aria-label="Fabric">
<div class="p-double-row__rows-container">
<div class="p-double-row__main-row">
<div title="{$ interface.fabric.name || 'Disconnected' $}">
{$ interface.fabric.name $}
<span data-ng-if="!interface.fabric.name">Disconnected</span>
<div title="{$ interface.fabric && interface.fabric.name || 'Disconnected' $}">
{$ interface.fabric && interface.fabric.name $}
<span data-ng-if="!(interface.fabric && interface.fabric.name)">Disconnected</span>
</div>
</div>
<div class="p-double-row__muted-row">
Expand Down

0 comments on commit b1de52b

Please sign in to comment.