Skip to content

Commit

Permalink
fix(editor): Fix SQL editor issue (#7236)
Browse files Browse the repository at this point in the history
Github issue / Community forum post (link here to close automatically):
  • Loading branch information
michael-radency authored and netroy committed Sep 25, 2023
1 parent bada252 commit 539f954
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 165 deletions.
58 changes: 28 additions & 30 deletions cypress/e2e/13-pinning.cy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// import {
// HTTP_REQUEST_NODE_NAME,
// MANUAL_TRIGGER_NODE_NAME,
// PIPEDRIVE_NODE_NAME,
// EDIT_FIELDS_SET_NODE_NAME,
// } from '../constants';
import {
HTTP_REQUEST_NODE_NAME,
MANUAL_TRIGGER_NODE_NAME,
PIPEDRIVE_NODE_NAME,
EDIT_FIELDS_SET_NODE_NAME,
} from '../constants';
import { WorkflowPage, NDV } from '../pages';

const workflowPage = new WorkflowPage();
Expand Down Expand Up @@ -69,35 +69,33 @@ describe('Data pinning', () => {
ndv.getters.outputTbodyCell(1, 0).should('include.text', 1);
});

//TODO: Update Edit Fields (Set) node to a new version
// it('Should be able to reference paired items in a node located before pinned data', () => {
// workflowPage.actions.addInitialNodeToCanvas(MANUAL_TRIGGER_NODE_NAME);
// workflowPage.actions.addNodeToCanvas(HTTP_REQUEST_NODE_NAME, true, true);
// ndv.actions.setPinnedData([{ http: 123 }]);
// ndv.actions.close();
it('Should be able to reference paired items in a node located before pinned data', () => {
workflowPage.actions.addInitialNodeToCanvas(MANUAL_TRIGGER_NODE_NAME);
workflowPage.actions.addNodeToCanvas(HTTP_REQUEST_NODE_NAME, true, true);
ndv.actions.setPinnedData([{ http: 123 }]);
ndv.actions.close();

// workflowPage.actions.addNodeToCanvas(PIPEDRIVE_NODE_NAME, true, true);
// ndv.actions.setPinnedData(Array(3).fill({ pipedrive: 123 }));
// ndv.actions.close();
workflowPage.actions.addNodeToCanvas(PIPEDRIVE_NODE_NAME, true, true);
ndv.actions.setPinnedData(Array(3).fill({ pipedrive: 123 }));
ndv.actions.close();

// workflowPage.actions.addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME, true, true);
// setExpressionOnStringValueInSet(`{{ $('${HTTP_REQUEST_NODE_NAME}').item`);
workflowPage.actions.addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME, true, true);
setExpressionOnStringValueInSet(`{{ $('${HTTP_REQUEST_NODE_NAME}').item`);

// const output = '[Object: {"json": {"http": 123}, "pairedItem": {"item": 0}}]';
const output = '[Object: {"json": {"http": 123}, "pairedItem": {"item": 0}}]';

// cy.get('div').contains(output).should('be.visible');
// });
cy.get('div').contains(output).should('be.visible');
});
});

// function setExpressionOnStringValueInSet(expression: string) {
// cy.get('button').contains('Execute node').click();
// cy.get('input[placeholder="Add Value"]').click();
// cy.get('span').contains('String').click();
function setExpressionOnStringValueInSet(expression: string) {
cy.get('button').contains('Execute node').click();
cy.get('.fixed-collection-parameter > :nth-child(2) > .button > span').click();

// ndv.getters.nthParam(3).contains('Expression').invoke('show').click();
ndv.getters.nthParam(4).contains('Expression').invoke('show').click();

// ndv.getters
// .inlineExpressionEditorInput()
// .clear()
// .type(expression, { parseSpecialCharSequences: false });
// }
ndv.getters
.inlineExpressionEditorInput()
.clear()
.type(expression, { parseSpecialCharSequences: false });
}
207 changes: 95 additions & 112 deletions cypress/e2e/16-webhook-node.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WorkflowPage, NDV, CredentialsModal } from '../pages';
import { v4 as uuid } from 'uuid';
// import { cowBase64 } from '../support/binaryTestFiles';
import { BACKEND_BASE_URL } from '../constants';
import { cowBase64 } from '../support/binaryTestFiles';
import { BACKEND_BASE_URL, EDIT_FIELDS_SET_NODE_NAME } from '../constants';
import { getVisibleSelect } from '../utils';

const workflowPage = new WorkflowPage();
Expand Down Expand Up @@ -102,39 +102,31 @@ describe('Webhook Trigger node', async () => {
simpleWebhookCall({ method: 'PUT', webhookPath: uuid(), executeNow: true });
});

//TODO: Update Edit Fields (Set) node to a new version
// it('should listen for a GET request and respond with Respond to Webhook node', () => {
// const webhookPath = uuid();
// simpleWebhookCall({
// method: 'GET',
// webhookPath,
// executeNow: false,
// respondWith: 'Respond to Webhook',
// });

// ndv.getters.backToCanvas().click();

// workflowPage.actions.addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME);
// workflowPage.actions.openNode(EDIT_FIELDS_SET_NODE_NAME);
// cy.get('.add-option').click();
// getVisibleSelect().find('.el-select-dropdown__item').contains('Number').click();
// cy.get('.fixed-collection-parameter')
// .getByTestId('parameter-input-name')
// .clear()
// .type('MyValue');
// cy.get('.fixed-collection-parameter').getByTestId('parameter-input-value').clear().type('1234');
// ndv.getters.backToCanvas().click({ force: true });

// workflowPage.actions.addNodeToCanvas('Respond to Webhook');

// workflowPage.actions.executeWorkflow();
// cy.wait(waitForWebhook);

// cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
// expect(response.status).to.eq(200);
// expect(response.body.MyValue).to.eq(1234);
// });
// });
it('should listen for a GET request and respond with Respond to Webhook node', () => {
const webhookPath = uuid();
simpleWebhookCall({
method: 'GET',
webhookPath,
executeNow: false,
respondWith: 'Respond to Webhook',
});

ndv.getters.backToCanvas().click();

addEditFields();

ndv.getters.backToCanvas().click({ force: true });

workflowPage.actions.addNodeToCanvas('Respond to Webhook');

workflowPage.actions.executeWorkflow();
cy.wait(waitForWebhook);

cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.MyValue).to.eq(1234);
});
});

it('should listen for a GET request and respond custom status code 201', () => {
const webhookPath = uuid();
Expand All @@ -153,83 +145,64 @@ describe('Webhook Trigger node', async () => {
});
});

//TODO: Update Edit Fields (Set) node to a new version
// it('should listen for a GET request and respond with last node', () => {
// const webhookPath = uuid();
// simpleWebhookCall({
// method: 'GET',
// webhookPath,
// executeNow: false,
// respondWith: 'Last Node',
// });
// ndv.getters.backToCanvas().click();

// workflowPage.actions.addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME);
// workflowPage.actions.openNode(EDIT_FIELDS_SET_NODE_NAME);
// cy.get('.add-option').click();
// getVisibleSelect().find('.el-select-dropdown__item').contains('Number').click();
// cy.get('.fixed-collection-parameter')
// .getByTestId('parameter-input-name')
// .find('input')
// .clear()
// .type('MyValue');
// cy.get('.fixed-collection-parameter')
// .getByTestId('parameter-input-value')
// .find('input')
// .clear()
// .type('1234');
// ndv.getters.backToCanvas().click({ force: true });

// workflowPage.actions.executeWorkflow();
// cy.wait(waitForWebhook);

// cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
// expect(response.status).to.eq(200);
// expect(response.body.MyValue).to.eq(1234);
// });
// });

//TODO: Update Edit Fields (Set) node to a new version
// it('should listen for a GET request and respond with last node binary data', () => {
// const webhookPath = uuid();
// simpleWebhookCall({
// method: 'GET',
// webhookPath,
// executeNow: false,
// respondWith: 'Last Node',
// responseData: 'First Entry Binary',
// });
// ndv.getters.backToCanvas().click();

// workflowPage.actions.addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME);
// workflowPage.actions.openNode(EDIT_FIELDS_SET_NODE_NAME);
// cy.get('.add-option').click();
// getVisibleSelect().find('.el-select-dropdown__item').contains('String').click();
// cy.get('.fixed-collection-parameter').getByTestId('parameter-input-name').clear().type('data');
// cy.get('.fixed-collection-parameter')
// .getByTestId('parameter-input-value')
// .clear()
// .find('input')
// .invoke('val', cowBase64)
// .trigger('blur');
// ndv.getters.backToCanvas().click();

// workflowPage.actions.addNodeToCanvas('Move Binary Data');
// workflowPage.actions.zoomToFit();

// workflowPage.actions.openNode('Move Binary Data');
// cy.getByTestId('parameter-input-mode').click();
// getVisibleSelect().find('.option-headline').contains('JSON to Binary').click();
// ndv.getters.backToCanvas().click();

// workflowPage.actions.executeWorkflow();
// cy.wait(waitForWebhook);

// cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
// expect(response.status).to.eq(200);
// expect(Object.keys(response.body).includes('data')).to.be.true;
// });
// });
it('should listen for a GET request and respond with last node', () => {
const webhookPath = uuid();
simpleWebhookCall({
method: 'GET',
webhookPath,
executeNow: false,
respondWith: 'Last Node',
});
ndv.getters.backToCanvas().click();

addEditFields();

ndv.getters.backToCanvas().click({ force: true });

workflowPage.actions.executeWorkflow();
cy.wait(waitForWebhook);

cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.MyValue).to.eq(1234);
});
});

it('should listen for a GET request and respond with last node binary data', () => {
const webhookPath = uuid();
simpleWebhookCall({
method: 'GET',
webhookPath,
executeNow: false,
respondWith: 'Last Node',
responseData: 'First Entry Binary',
});
ndv.getters.backToCanvas().click();

workflowPage.actions.addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME);
workflowPage.actions.openNode(EDIT_FIELDS_SET_NODE_NAME);
cy.get('.fixed-collection-parameter > :nth-child(2) > .button > span').click();
ndv.getters.nthParam(2).type('data');
ndv.getters.nthParam(4).invoke('val', cowBase64).trigger('blur');

ndv.getters.backToCanvas().click();

workflowPage.actions.addNodeToCanvas('Move Binary Data');
workflowPage.actions.zoomToFit();

workflowPage.actions.openNode('Move Binary Data');
cy.getByTestId('parameter-input-mode').click();
getVisibleSelect().find('.option-headline').contains('JSON to Binary').click();
ndv.getters.backToCanvas().click();

workflowPage.actions.executeWorkflow();
cy.wait(waitForWebhook);

cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => {
expect(response.status).to.eq(200);
expect(Object.keys(response.body).includes('data')).to.be.true;
});
});

it('should listen for a GET request and respond with an empty body', () => {
const webhookPath = uuid();
Expand Down Expand Up @@ -332,3 +305,13 @@ describe('Webhook Trigger node', async () => {
});
});
});

const addEditFields = () => {
workflowPage.actions.addNodeToCanvas(EDIT_FIELDS_SET_NODE_NAME);
workflowPage.actions.openNode(EDIT_FIELDS_SET_NODE_NAME);
cy.get('.fixed-collection-parameter > :nth-child(2) > .button > span').click();
ndv.getters.nthParam(2).type('MyValue');
ndv.getters.nthParam(3).click();
cy.get('div').contains('Number').click();
ndv.getters.nthParam(4).type('1234');
};
26 changes: 26 additions & 0 deletions cypress/e2e/29-sql-editor.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { WorkflowPage, NDV } from '../pages';

const workflowPage = new WorkflowPage();
const ndv = new NDV();

describe('SQL editors', () => {
beforeEach(() => {
workflowPage.actions.visit();
});

it('should preserve changes when opening-closing Postgres node', () => {
workflowPage.actions.addInitialNodeToCanvas('Manual');
workflowPage.actions.addNodeToCanvas('Postgres');
workflowPage.actions.openNode('Postgres');
ndv.getters.parameterInput('operation').click();
cy.get('div').contains('Execute Query').click();
cy.get('div.cm-activeLine').type('SELECT * FROM `testTable`');
ndv.actions.close();
workflowPage.actions.openNode('Postgres');
cy.get('div.cm-activeLine').type('{end} LIMIT 10');
ndv.actions.close();
workflowPage.actions.openNode('Postgres');

cy.get('div.cm-activeLine').contains('SELECT * FROM `testTable` LIMIT 10');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export default defineComponent({
...readOnlyEditorExtensions,
EditorState.readOnly.of(isReadOnly),
EditorView.editable.of(!isReadOnly),
codeNodeEditorTheme({ isReadOnly }),
codeNodeEditorTheme({ isReadOnly, customMinHeight: this.rows }),
];
if (!isReadOnly) {
Expand Down Expand Up @@ -354,16 +354,8 @@ export default defineComponent({
const [languageSupport, ...otherExtensions] = this.languageExtensions;
extensions.push(this.languageCompartment.of(languageSupport), ...otherExtensions);
let doc = this.modelValue ?? this.placeholder;
const lines = doc.split('\n');
if (lines.length < this.rows) {
doc += '\n'.repeat(this.rows - lines.length);
}
const state = EditorState.create({
doc,
doc: this.modelValue ?? this.placeholder,
extensions,
});
Expand Down
11 changes: 9 additions & 2 deletions packages/editor-ui/src/components/CodeNodeEditor/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ const cssStyleDeclaration = getComputedStyle(document.documentElement);
interface ThemeSettings {
isReadOnly?: boolean;
customMaxHeight?: string;
customMinHeight?: number;
}

export const codeNodeEditorTheme = ({ isReadOnly, customMaxHeight }: ThemeSettings) => [
export const codeNodeEditorTheme = ({
isReadOnly,
customMaxHeight,
customMinHeight,
}: ThemeSettings) => [
EditorView.theme({
'&': {
'font-size': BASE_STYLING.fontSize,
Expand Down Expand Up @@ -82,7 +87,9 @@ export const codeNodeEditorTheme = ({ isReadOnly, customMaxHeight }: ThemeSettin
overflow: 'auto',

maxHeight: customMaxHeight ?? '100%',
...(isReadOnly ? {} : { minHeight: '1.3em' }),
...(isReadOnly
? {}
: { minHeight: customMinHeight ? `${Number(customMinHeight) * 1.3}em` : '10em' }),
},
'.cm-diagnosticAction': {
backgroundColor: BASE_STYLING.diagnosticButton.backgroundColor,
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/ParameterInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
:dialect="getArgument('sqlDialect')"
:isReadOnly="isReadOnly"
:rows="getArgument('rows')"
@valueChanged="valueChangedDebounced"
@update:modelValue="valueChangedDebounced"
/>

<code-node-editor
Expand Down
Loading

0 comments on commit 539f954

Please sign in to comment.