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

Merged
merged 5 commits into from
Dec 3, 2024
Merged
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
Prev Previous commit
Next Next commit
copy using ClipboardItem to support Safari. other review concerns add…
…ressed. added some minor positioning fixes as well.
rfellows committed Nov 21, 2024
commit 0386c582f9a6bddb8b1d0ac0a03d3c14fdfc8659
Original file line number Diff line number Diff line change
@@ -134,13 +134,6 @@ export class CanvasUtils {
this.breadcrumbs = breadcrumbs;
});

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

this.store
.select(selectScale)
.pipe(takeUntilDestroyed(this.destroyRef))
Original file line number Diff line number Diff line change
@@ -80,14 +80,12 @@ export class CopyPasteService {
.forEach((values: any[]) => {
values.forEach((value) => {
if (value.position) {
const newPos = this.canvasView.getCanvasPosition(value.position);
value.position.x = (newPos?.x || value.position.x) + offset * (pasteIncrement + 1);
value.position.y = (newPos?.y || value.position.y) + offset * (pasteIncrement + 1);
value.position.x += offset * (pasteIncrement + 1);
value.position.y += offset * (pasteIncrement + 1);
} else if (value.bends) {
value.bends.forEach((bend: Position) => {
const newPos = this.canvasView.getCanvasPosition(bend);
bend.x = (newPos?.x || bend.x) + offset * (pasteIncrement + 1);
bend.y = (newPos?.y || bend.y) + offset * (pasteIncrement + 1);
bend.x += offset * (pasteIncrement + 1);
bend.y += offset * (pasteIncrement + 1);
});
}
});
@@ -237,7 +235,7 @@ export class CopyPasteService {
acc.left = Math.min(acc.left, bend.x);
acc.top = Math.min(acc.top, bend.y);
acc.right = Math.max(acc.right, bend.x);
acc.right = Math.max(acc.bottom, bend.y);
acc.bottom = Math.max(acc.bottom, bend.y);
});
} else {
acc.left = Math.min(acc.left, current.position.x);
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ import { Snippet, SnippetComponentRequest } from '../state/flow';
import { ClusterConnectionService } from '../../../service/cluster-connection.service';
import { ComponentType } from 'libs/shared/src';
import { Client } from '../../../service/client.service';
import { Position } from '../state/shared';

@Injectable({ providedIn: 'root' })
export class SnippetService {
@@ -97,16 +96,6 @@ export class SnippetService {
return this.httpClient.put(`${SnippetService.API}/snippets/${snippetId}`, payload);
}

copySnippet(snippetId: string, pasteLocation: Position, groupId: string): Observable<any> {
const payload: any = {
disconnectedNodeAcknowledged: this.clusterConnectionService.isDisconnectionAcknowledged(),
originX: pasteLocation.x,
originY: pasteLocation.y,
snippetId
};
return this.httpClient.post(`${SnippetService.API}/process-groups/${groupId}/snippet-instance`, payload);
}

deleteSnippet(snippetId: string): Observable<any> {
const params = new HttpParams({
fromObject: {
Original file line number Diff line number Diff line change
@@ -2237,7 +2237,12 @@ export class FlowEffects {
};
return from(this.copyPasteService.copy(copyRequest)).pipe(
switchMap((response) => {
return from(navigator.clipboard.writeText(JSON.stringify(response, null, 2))).pipe(
// if (typeof ClipboardItem && navigator.clipboard.write) {
const copyBlob = new Blob([JSON.stringify(response, null, 2)], { type: 'text/plain' });
const clipboardItem: ClipboardItem = new ClipboardItem({
'text/plain': copyBlob
});
return from(navigator.clipboard.write([clipboardItem])).pipe(
switchMap(() => {
return of(
FlowActions.copySuccess({
@@ -2249,10 +2254,30 @@ export class FlowEffects {
})
);
}),
catchError(() => {
catchError((e) => {
console.log(e);
return of(FlowActions.flowSnackbarError({ error: 'Copy failed' }));
})
);
// } else {
// return from(navigator.clipboard.writeText(JSON.stringify(response, null, 2))).pipe(
// switchMap(() => {
// return of(
// FlowActions.copySuccess({
// response: {
// copyResponse: response,
// processGroupId,
// pasteCount: 0
// } as CopyResponseContext
// })
// );
// }),
// catchError((e) => {
// console.log(e);
// return of(FlowActions.flowSnackbarError({ error: 'Copy failed' }));
// })
// );
// }
}),
catchError((errorResponse: HttpErrorResponse) => of(this.snackBarOrFullScreenError(errorResponse)))
);
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ import { CanvasUtils } from '../../service/canvas-utils.service';
import { CanvasActionsService } from '../../service/canvas-actions.service';
import { MatDialog } from '@angular/material/dialog';
import { CopyResponseEntity } from '../../../../state/copy';
import { snackBarError } from '../../../../state/error/error.actions';

@Component({
selector: 'fd-canvas',
@@ -707,22 +708,16 @@ export class Canvas implements OnInit, OnDestroy {

const textToPaste = event.clipboardData?.getData('text/plain');
if (textToPaste) {
try {
const copyResponse: CopyResponseEntity = JSON.parse(textToPaste);
// make sure at least one of the properties are set
if (Object.keys(copyResponse).length > 0) {
if (copyResponse) {
this.store.dispatch(
paste({
request: copyResponse
})
);
event.preventDefault();
}
}
} catch (e) {
// attempting to paste something other than CopyResponseEntity, ignore it
return;
const copyResponse: CopyResponseEntity | null = this.toCopyResponseEntity(textToPaste);
if (copyResponse) {
this.store.dispatch(
paste({
request: copyResponse
})
);
event.preventDefault();
} else {
this.store.dispatch(snackBarError({ error: 'Cannot paste: incompatible format' }));
}
}
}
@@ -740,4 +735,35 @@ export class Canvas implements OnInit, OnDestroy {
event.preventDefault();
}
}

private toCopyResponseEntity(json: string): CopyResponseEntity | null {
try {
const copyResponse: CopyResponseEntity = JSON.parse(json);
const supportedKeys: string[] = [
'processGroups',
'remoteProcessGroups',
'processors',
'inputPorts',
'outputPorts',
'connections',
'labels',
'funnels'
];

// ensure at least one of the copyable component types has something to paste
const hasCopiedContent = Object.entries(copyResponse).some((entry) => {
return supportedKeys.includes(entry[0]) && Array.isArray(entry[1]) && entry[1].length > 0;
});

if (hasCopiedContent) {
return copyResponse;
}

// attempting to paste something other than CopyResponseEntity
return null;
} catch (e) {
// attempting to paste something other than CopyResponseEntity
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -18,9 +18,6 @@
*/

import { Injectable } from '@angular/core';
import { Actions } from '@ngrx/effects';

@Injectable()
export class CopyEffects {
constructor(private actions$: Actions) {}
}
export class CopyEffects {}