Skip to content

Commit

Permalink
Merge pull request #4274 from jeff-phillips-18/error-message
Browse files Browse the repository at this point in the history
Bug 1801419: Show an error dialog when creation of a connection fails
  • Loading branch information
openshift-merge-robot committed Feb 14, 2020
2 parents 5f26bba + f317eaa commit f776af2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { moveNodeToGroup } from './components/moveNodeToGroup';
import { TYPE_CONNECTS_TO, TYPE_WORKLOAD, TYPE_KNATIVE_SERVICE, TYPE_EVENT_SOURCE } from './const';
import './components/GraphComponent.scss';
import { graphContextMenu, groupContextMenu } from './nodeContextMenu';
import { errorModal } from '@console/internal/components/modals';

type GraphProps = {
element: Graph;
Expand Down Expand Up @@ -224,6 +225,7 @@ const edgeDragSourceSpec = (
replaceTargetNode?: Node,
serviceBindingFlag?: boolean,
) => Promise<K8sResourceKind[] | K8sResourceKind>,
failureTitle: string = 'Error moving connection',
): DragSourceSpec<DragObjectWithType, Node, { dragging: boolean }, EdgeProps> => ({
item: { type },
operation: MOVE_CONNECTOR_OPERATION,
Expand All @@ -237,7 +239,14 @@ const edgeDragSourceSpec = (
end: (dropResult, monitor, props) => {
props.element.setEndPoint();
if (monitor.didDrop() && dropResult) {
callback(props.element.getSource(), dropResult, props.element.getTarget(), serviceBinding);
callback(
props.element.getSource(),
dropResult,
props.element.getTarget(),
serviceBinding,
).catch((error) => {
errorModal({ title: failureTitle, error: error.message, showIcon: true });
});
}
},
collect: (monitor) => ({
Expand All @@ -249,18 +258,26 @@ const createConnectorCallback = (serviceBinding: boolean) => (
source: Node,
target: Node | Graph,
): React.ReactElement[] | null => {
if (source === target) {
return null;
}

if (isGraph(target)) {
return graphContextMenu(target, source);
}
if (target.isGroup()) {
return groupContextMenu(target, source);
}
createConnection(source, target, null, serviceBinding);
createConnection(source, target, null, serviceBinding).catch((error) => {
errorModal({ title: 'Error creating connection', error: error.message });
});
return null;
};

const removeConnectorCallback = (edge: Edge): void => {
removeConnection(edge);
removeConnection(edge).catch((error) => {
errorModal({ title: 'Error removing connection', error: error.message });
});
return null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ export const createTopologyResourceConnection = (
serviceBindingFlag: boolean,
): Promise<K8sResourceKind[] | K8sResourceKind> => {
if (!source || !target || source === target) {
return Promise.reject();
return Promise.reject(new Error('Can not create a connection from a node to itself.'));
}

const sourceObj = getTopologyResourceObject(source);
Expand All @@ -830,7 +830,7 @@ export const createTopologyResourceConnection = (
.then(resolve)
.catch(reject);
})
.catch(resolve);
.catch(reject);
});
}

Expand Down

0 comments on commit f776af2

Please sign in to comment.