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

[NIFI-13977] - Updated Copy/Paste in UI to align with new backend API #9536

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { LoginConfigurationEffects } from './state/login-configuration/login-con
import { BannerTextEffects } from './state/banner-text/banner-text.effects';
import { MAT_TOOLTIP_DEFAULT_OPTIONS, MatTooltipDefaultOptions } from '@angular/material/tooltip';
import { CLIPBOARD_OPTIONS, provideMarkdown } from 'ngx-markdown';
import { CopyEffects } from './state/copy/copy.effects';

const entry = localStorage.getItem('disable-animations');
let disableAnimations: string = entry !== null ? JSON.parse(entry).item : '';
Expand Down Expand Up @@ -97,7 +98,8 @@ export const customTooltipDefaults: MatTooltipDefaultOptions = {
ComponentStateEffects,
DocumentationEffects,
ClusterSummaryEffects,
PropertyVerificationEffects
PropertyVerificationEffects,
CopyEffects
),
StoreDevtoolsModule.instrument({
maxAge: 25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
navigateToEditCurrentProcessGroup,
navigateToManageComponentPolicies,
openChangeColorDialog,
paste,
reloadFlow,
selectComponents,
startComponents,
Expand All @@ -40,12 +39,10 @@ import {
} from '../state/flow/flow.actions';
import {
ChangeColorRequest,
CopyComponentRequest,
DeleteComponentRequest,
DisableComponentRequest,
EnableComponentRequest,
MoveComponentRequest,
PasteRequest,
SelectedComponent,
StartComponentRequest,
StopComponentRequest
Expand All @@ -57,6 +54,7 @@ import { MatDialog } from '@angular/material/dialog';
import { CanvasView } from './canvas-view.service';
import { ComponentType } from 'libs/shared/src';
import { Client } from '../../../service/client.service';
import { CopyRequest, CopyRequestEntity } from '../../../state/copy';

export type CanvasConditionFunction = (selection: d3.Selection<any, any, any, any>) => boolean;
export type CanvasActionFunction = (selection: d3.Selection<any, any, any, any>, extraArgs?: any) => void;
Expand Down Expand Up @@ -139,45 +137,65 @@ export class CanvasActionsService {
return this.canvasUtils.isCopyable(selection);
},
action: (selection: d3.Selection<any, any, any, any>) => {
const origin = this.canvasUtils.getOrigin(selection);
const dimensions = this.canvasView.getSelectionBoundingClientRect(selection);
const copyRequestEntity: CopyRequestEntity = {};
const request: CopyRequest = {
copyRequestEntity
};

const components: CopyComponentRequest[] = [];
selection.each((d) => {
components.push({
id: d.id,
type: d.type,
uri: d.uri,
entity: d
});
switch (d.type) {
case ComponentType.Processor:
if (!copyRequestEntity.processors) {
copyRequestEntity.processors = [];
}
copyRequestEntity.processors.push(d.id);
break;
case ComponentType.ProcessGroup:
if (!copyRequestEntity.processGroups) {
copyRequestEntity.processGroups = [];
}
copyRequestEntity.processGroups.push(d.id);
break;
case ComponentType.Connection:
if (!copyRequestEntity.connections) {
copyRequestEntity.connections = [];
}
copyRequestEntity.connections.push(d.id);
break;
case ComponentType.RemoteProcessGroup:
if (!copyRequestEntity.remoteProcessGroups) {
copyRequestEntity.remoteProcessGroups = [];
}
copyRequestEntity.remoteProcessGroups.push(d.id);
break;
case ComponentType.InputPort:
if (!copyRequestEntity.inputPorts) {
copyRequestEntity.inputPorts = [];
}
copyRequestEntity.inputPorts.push(d.id);
break;
case ComponentType.OutputPort:
if (!copyRequestEntity.outputPorts) {
copyRequestEntity.outputPorts = [];
}
copyRequestEntity.outputPorts.push(d.id);
break;
case ComponentType.Label:
if (!copyRequestEntity.labels) {
copyRequestEntity.labels = [];
}
copyRequestEntity.labels.push(d.id);
break;
case ComponentType.Funnel:
if (!copyRequestEntity.funnels) {
copyRequestEntity.funnels = [];
}
copyRequestEntity.funnels.push(d.id);
break;
}
});

this.store.dispatch(
copy({
request: {
components,
origin,
dimensions
}
})
);
}
},
paste: {
id: 'paste',
condition: () => {
return this.canvasUtils.isPastable();
},
action: (selection, extraArgs) => {
const pasteRequest: PasteRequest = {};
if (extraArgs?.pasteLocation) {
pasteRequest.pasteLocation = extraArgs.pasteLocation;
}
this.store.dispatch(
paste({
request: pasteRequest
})
);
this.store.dispatch(copy({ request }));
}
},
selectAll: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
selectBreadcrumbs,
selectCanvasPermissions,
selectConnections,
selectCopiedSnippet,
selectCurrentParameterContext,
selectCurrentProcessGroupId,
selectParentProcessGroupId
Expand Down Expand Up @@ -135,12 +134,12 @@ export class CanvasUtils {
this.breadcrumbs = breadcrumbs;
});

this.store
.select(selectCopiedSnippet)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((copiedSnippet) => {
this.copiedSnippet = copiedSnippet;
});
// this.store
// .select(selectCopiedSnippet)
// .pipe(takeUntilDestroyed(this.destroyRef))
// .subscribe((copiedSnippet) => {
// this.copiedSnippet = copiedSnippet;
// });
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have been removed?


this.store
.select(selectScale)
Expand Down Expand Up @@ -1011,7 +1010,7 @@ export class CanvasUtils {
}

public isPastable(): boolean {
return this.canvasPermissions.canWrite && this.copiedSnippet != null;
return this.canvasPermissions.canWrite;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ export class CanvasView {
this.canvasInitialized = true;
}

public getCanvasBoundingClientRect(): DOMRect | null {
const canvasContainer: any = document.getElementById('canvas-container');
if (canvasContainer == null) {
return null;
}

return canvasContainer.getBoundingClientRect() as DOMRect;
}

// filters zoom events as programmatically modifying the translate or scale now triggers the handlers
private isBirdseyeEvent(): boolean {
return this.birdseyeTranslateInProgress;
Expand Down Expand Up @@ -252,26 +261,19 @@ export class CanvasView {
}

/**
* Determines if a bounding box is fully in the current viewable canvas area.
* Determines if a bounding box is in the current viewable canvas area.
*
* @param {type} boundingBox Bounding box to check.
* @param {boolean} strict If true, the entire bounding box must be in the viewport.
* If false, only part of the bounding box must be in the viewport.
* @returns {boolean}
*/
public isBoundingBoxInViewport(boundingBox: any, strict: boolean): boolean {
const selection: any = this.canvasUtils.getSelection();
if (selection.size() !== 1) {
return false;
}

const canvasContainer: any = document.getElementById('canvas-container');
if (!canvasContainer) {
return false;
}

const yOffset = canvasContainer.getBoundingClientRect().top;

// scale the translation
const translate = [this.x / this.k, this.y / this.k];

Expand All @@ -287,8 +289,8 @@ export class CanvasView {

const left = Math.ceil(boundingBox.x);
const right = Math.floor(boundingBox.x + boundingBox.width);
const top = Math.ceil(boundingBox.y - yOffset / this.k);
const bottom = Math.floor(boundingBox.y - yOffset / this.k + boundingBox.height);
const top = Math.ceil(boundingBox.y);
const bottom = Math.floor(boundingBox.y + boundingBox.height);

if (strict) {
return !(left < screenLeft || right > screenRight || top < screenTop || bottom > screenBottom);
Expand Down Expand Up @@ -497,6 +499,13 @@ export class CanvasView {
return bbox;
}

/**
* Translates a position to the space visible on the canvas
*
* @param position
*
* @returns {Position | null}
*/
public getCanvasPosition(position: Position): Position | null {
const canvasContainer: any = document.getElementById('canvas-container');
if (!canvasContainer) {
Expand Down Expand Up @@ -528,7 +537,11 @@ export class CanvasView {
return null;
}

private centerBoundingBox(boundingBox: any): void {
/**
* Centers the canvas to a bounding box. If a scale is provided, it will zoom to that scale.
* @param {type} boundingBox
*/
public centerBoundingBox(boundingBox: any): void {
let scale: number = this.k;
if (boundingBox.scale != null) {
scale = boundingBox.scale;
Expand Down
Loading