Skip to content

Commit

Permalink
Updates per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Feb 26, 2020
1 parent 128472c commit af1fa27
Show file tree
Hide file tree
Showing 16 changed files with 350 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { withEditReviewAccess } from './withEditReviewAccess';
import HelmRelease from './components/groups/HelmRelease';
import AggregateEdge from './components/edges/AggregateEdge';
import TrafficConnector from './components/edges/TrafficConnector';
import CreateConnector from './components/edges/CreateConnector';

type NodeProps = {
element: Node;
Expand Down Expand Up @@ -94,9 +95,8 @@ class ComponentFactory {
this.hasServiceBinding = value;
}

withAddResourceConnector = () => {
return withCreateConnector(createConnectorCallback(this.hasServiceBinding), 'Add Resource');
};
withAddResourceConnector = () =>
withCreateConnector(createConnectorCallback(this.hasServiceBinding), CreateConnector);

getFactory = (): TopologyComponentFactory => {
return (kind, type): React.ComponentType<{ element: GraphElement }> | undefined => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const nodeDropTargetSpec: DropTargetSpec<
accept: [MOVE_CONNECTOR_DROP_TYPE, CREATE_CONNECTOR_DROP_TYPE],
canDrop: (item, monitor, props) => {
if (isEdge(item)) {
return item.getSource() !== props.element && item.getTarget() !== props.element;
return canDropEdgeOnNode(monitor.getOperation(), item, props.element);
}
if (item === props.element) {
return false;
Expand Down Expand Up @@ -177,11 +177,10 @@ const graphWorkloadDropTargetSpec: DropTargetSpec<
collect: (monitor) => {
const dragEditInProgress =
monitor.isDragging() && editOperations.includes(monitor.getOperation());
const dropHints = monitor.getDropHints() || [];
const dragCreate =
dragEditInProgress &&
monitor.getItemType() === CREATE_CONNECTOR_DROP_TYPE &&
dropHints[dropHints.length - 1] === 'create';
(monitor.getItemType() === CREATE_CONNECTOR_DROP_TYPE ||
monitor.getItemType() === MOVE_CONNECTOR_DROP_TYPE);
return {
dragEditInProgress,
dragCreate,
Expand Down Expand Up @@ -258,7 +257,7 @@ const edgeDragSourceSpec = (
},
end: (dropResult, monitor, props) => {
props.element.setEndPoint();
if (monitor.didDrop() && dropResult) {
if (monitor.didDrop() && dropResult && canDropEdgeOnNode('', props.element, dropResult)) {
callback(
props.element.getSource(),
dropResult,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@import '../topology-utils';

.odc-m-drag-active {
cursor: no-drop !important;
cursor: no-drop;
&.odc-m-valid-drop-target {
cursor: grab !important;
cursor: grab;
.odc-m-drag-create {
cursor: none;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import '../../topology-utils';

.odc-base-edge {
--edge--drag-active--cursor: grab;
--edge--stroke-width: 2px;
--edge--stroke-dasharray: 0;
--edge--stroke: #{$default-edge-stroke-color};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@import '../../topology-utils';

.odc-create-connector {
cursor: pointer;
&.is-dragging {
pointer-events: none;
}
&.topology-default-create-connector {
--create-connector-color: #{$interactive-stroke-color};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';
import * as classNames from 'classnames';
import { CreateConnectorRenderer, DefaultCreateConnector } from '@console/topology';

import './CreateConnector.scss';

const CreateConnector: CreateConnectorRenderer = ({ startPoint, endPoint, dragging, hints }) => {
const [hover, setHover] = React.useState(false);
const unsetHandle = React.useRef<number>();

React.useEffect(() => {
setHover(false);
clearTimeout(unsetHandle.current);
unsetHandle.current = window.setTimeout(() => {
setHover(dragging);
}, 2000);
return () => {
clearTimeout(unsetHandle.current);
};
}, [endPoint.x, endPoint.y, dragging]);

const classes = classNames('odc-create-connector', { 'is-dragging': dragging });
return (
<DefaultCreateConnector
className={classes}
startPoint={startPoint}
endPoint={endPoint}
dragging={dragging}
hints={hints}
tipContents={hover && dragging ? 'Add Resources' : null}
/>
);
};

export default CreateConnector;
6 changes: 3 additions & 3 deletions frontend/packages/topology/src/behavior/dnd-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type Unregister = () => void;
export interface DndManager {
registerSource(source: DragSource): [string, Unregister];
registerTarget(target: DropTarget): [string, Unregister];
getDropHints(): string[] | undefined;
getDropHints(): string[];
canDragSource(sourceId: string | undefined): boolean;
canDropOnTarget(targetId: string | undefined): boolean;
hasDropTarget(): boolean;
Expand Down Expand Up @@ -156,7 +156,7 @@ export interface HandlerManager {
}

export interface DragSourceMonitor extends HandlerManager {
getDropHints(): string[] | undefined;
getDropHints(): string[];
canDrag(): boolean;
isCancelled(): boolean;
isDragging(): boolean;
Expand All @@ -174,7 +174,7 @@ export interface DropTargetMonitor extends HandlerManager {
isDragging(): boolean;
isOver(options?: { shallow?: boolean }): boolean;
hasDropTarget(): boolean;
getDropHints(): string[] | undefined;
getDropHints(): string[];
getItemType(): Identifier | undefined;
getItem(): any;
getDropResult(): any;
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/topology/src/behavior/useDndDrag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const useDndDrag = <
receiveHandlerId: (sourceId: string | undefined): void => {
idRef.current = sourceId;
},
getDropHints: (): string[] | undefined => {
getDropHints: (): string[] => {
return dndManager.getDropHints();
},
canDrag: (): boolean => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/topology/src/behavior/useDndDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const useDndDrop = <
hasDropTarget: (): boolean => {
return dndManager.hasDropTarget();
},
getDropHints: (): string[] | undefined => {
getDropHints: (): string[] => {
return dndManager.getDropHints();
},
isOver(options?: { shallow?: boolean }): boolean {
Expand Down
8 changes: 4 additions & 4 deletions frontend/packages/topology/src/behavior/useDndManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export class DndManagerImpl implements DndManager {
private targets: { [key: string]: DropTarget } = {};

@computed
get dropHints(): string[] | undefined {
get dropHints(): string[] {
return this.state.targetIds
? (this.state.targetIds
.map((id) => {
const target = this.getTarget(id);
return target ? target.dropHint(this) : undefined;
return target ? target.dropHint(this) : [];
})
.filter((x) => x) as string[])
: undefined;
: [];
}

registerSource(source: DragSource): [string, Unregister] {
Expand All @@ -79,7 +79,7 @@ export class DndManagerImpl implements DndManager {
];
}

getDropHints(): string[] | undefined {
getDropHints(): string[] {
return this.dropHints;
}

Expand Down

0 comments on commit af1fa27

Please sign in to comment.