Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1801419: Show an error dialog when creation of a connection fails #4274

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no icon here but there's an icon in the other error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oversight, I will update

});
return null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,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 @@ -825,7 +825,7 @@ export const createTopologyResourceConnection = (
.then(resolve)
.catch(reject);
})
.catch(resolve);
.catch(reject);
});
}

Expand Down