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

fix(editor): Fix copy selection behavior #6112

Merged
merged 1 commit into from
May 2, 2023
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: 2 additions & 1 deletion packages/editor-ui/src/components/RunDataJson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import { useNDVStore } from '@/stores/ndv';
import MappingPill from './MappingPill.vue';
import { getMappedExpression } from '@/utils/mappingUtils';
import { useWorkflowsStore } from '@/stores/workflows';
import { nonExistingJsonPath } from '@/components/RunDataJsonActions.vue';

const runDataJsonActions = () => import('@/components/RunDataJsonActions.vue');

Expand Down Expand Up @@ -125,7 +126,7 @@ export default mixins(externalHooks).extend({
},
data() {
return {
selectedJsonPath: null as null | string,
selectedJsonPath: nonExistingJsonPath,
draggingPath: null as null | string,
displayMode: 'json',
};
Expand Down
20 changes: 15 additions & 5 deletions packages/editor-ui/src/components/RunDataJsonActions.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<template>
<div :class="$style.actionsGroup">
<el-dropdown trigger="click" @command="handleCopyClick">
<n8n-icon-button
Copy link
Contributor

@mutdmour mutdmour Apr 28, 2023

Choose a reason for hiding this comment

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

tests would be nice still though

v-if="noSelection"
:title="$locale.baseText('runData.copyToClipboard')"
icon="copy"
type="tertiary"
:circle="false"
@click="handleCopyClick({ command: 'value' })"
/>
<el-dropdown v-else trigger="click" @command="handleCopyClick">
<span class="el-dropdown-link">
<n8n-icon-button
:title="$locale.baseText('runData.copyToClipboard')"
Expand Down Expand Up @@ -47,7 +55,7 @@ type JsonPathData = {
};

// A path that does not exist so that nothing is selected by default
const nonExistingJsonPath = '_!^&*';
export const nonExistingJsonPath = '_!^&*';

export default mixins(genericHelpers, nodeHelpers, pinData, copyPaste).extend({
name: 'run-data-json-actions',
Expand Down Expand Up @@ -87,15 +95,17 @@ export default mixins(genericHelpers, nodeHelpers, pinData, copyPaste).extend({
activeNode(): INodeUi | null {
return this.ndvStore.activeNode;
},
noSelection() {
return this.selectedJsonPath === nonExistingJsonPath;
},
normalisedJsonPath(): string {
const isNotSelected = this.selectedJsonPath === nonExistingJsonPath;
return isNotSelected ? '[""]' : this.selectedJsonPath;
return this.noSelection ? '[""]' : this.selectedJsonPath;
},
},
methods: {
getJsonValue(): string {
let selectedValue = jp.query(this.jsonData, `$${this.normalisedJsonPath}`)[0];
if (this.selectedJsonPath === nonExistingJsonPath) {
if (this.noSelection) {
if (this.hasPinData) {
selectedValue = clearJsonKey(this.pinData as object);
} else {
Expand Down