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

N8 n 4156 stickies #3755

Merged
merged 4 commits into from
Jul 26, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/editor-ui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,6 @@ export const TEST_PIN_DATA = [
},
];
export const MAPPING_PARAMS = [`$evaluateExpression`, `$item`, `$jmespath`, `$node`, `$binary`, `$data`, `$env`, `$json`, `$now`, `$parameters`, `$position`, `$resumeWebhookUrl`, `$runIndex`, `$today`, `$workflow`, '$parameter'];

export const DEFAULT_STICKY_HEIGHT = 160;
export const DEFAULT_STICKY_WIDTH = 240;
21 changes: 19 additions & 2 deletions packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
/>
<div
:class="['add-sticky-button', showStickyButton ? 'visible-button' : '']"
@click="nodeTypeSelected(STICKY_NODE_TYPE)"
@click="addStickyNote"
>
<n8n-icon-button
size="medium"
Expand Down Expand Up @@ -154,7 +154,7 @@ import {
} from 'jsplumb';
import { MessageBoxInputData } from 'element-ui/types/message-box';
import { jsPlumb, OnConnectionBindInfo } from 'jsplumb';
import { MODAL_CANCEL, MODAL_CLOSE, MODAL_CONFIRMED, NODE_NAME_PREFIX, NODE_OUTPUT_DEFAULT_KEY, PLACEHOLDER_EMPTY_WORKFLOW_ID, QUICKSTART_NOTE_NAME, START_NODE_TYPE, STICKY_NODE_TYPE, VIEWS, WEBHOOK_NODE_TYPE, WORKFLOW_OPEN_MODAL_KEY } from '@/constants';
import { DEFAULT_STICKY_HEIGHT, DEFAULT_STICKY_WIDTH, MODAL_CANCEL, MODAL_CLOSE, MODAL_CONFIRMED, NODE_NAME_PREFIX, NODE_OUTPUT_DEFAULT_KEY, PLACEHOLDER_EMPTY_WORKFLOW_ID, QUICKSTART_NOTE_NAME, START_NODE_TYPE, STICKY_NODE_TYPE, VIEWS, WEBHOOK_NODE_TYPE, WORKFLOW_OPEN_MODAL_KEY } from '@/constants';
import { copyPaste } from '@/components/mixins/copyPaste';
import { externalHooks } from '@/components/mixins/externalHooks';
import { genericHelpers } from '@/components/mixins/genericHelpers';
Expand Down Expand Up @@ -227,6 +227,7 @@ interface AddNodeOptions {
dragAndDrop?: boolean;
}


export default mixins(
copyPaste,
externalHooks,
Expand Down Expand Up @@ -1371,6 +1372,22 @@ export default mixins(
this.createNodeActive = false;
},

addStickyNote() {
if (document.activeElement) {
(document.activeElement as HTMLElement).blur();
}

const offset: [number, number] = [...(this.$store.getters.getNodeViewOffsetPosition as [number, number])];

const position = CanvasHelpers.getMidCanvasPosition(this.nodeViewScale, offset);
position[0] -= DEFAULT_STICKY_WIDTH / 2;
position[1] -= DEFAULT_STICKY_HEIGHT / 2;
mutdmour marked this conversation as resolved.
Show resolved Hide resolved

this.addNodeButton(STICKY_NODE_TYPE, {
position,
});
},

nodeTypeSelected (nodeTypeName: string) {
this.addNodeButton(nodeTypeName);
this.createNodeActive = false;
Expand Down
4 changes: 4 additions & 0 deletions packages/editor-ui/src/views/canvasHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ export const getRelativePosition = (x: number, y: number, scale: number, offset:
];
};

export const getMidCanvasPosition = (scale: number, offset: XYPosition): XYPosition => {
return getRelativePosition((window.innerWidth - SIDEBAR_WIDTH) / 2, (window.innerHeight - HEADER_HEIGHT) / 2, scale, offset);
};

export const getBackgroundStyles = (scale: number, offsetPosition: XYPosition) => {
const squareSize = GRID_SIZE * scale;
const dotSize = 1 * scale;
Expand Down