Skip to content

Commit

Permalink
fix(editor): Error dropdown in resource locator disappears when searc…
Browse files Browse the repository at this point in the history
…h filter is required (n8n-io#9681)
  • Loading branch information
elsmr authored and adrian-martinez-onestic committed Jun 20, 2024
1 parent 79f8ff3 commit fdd81ea
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
24 changes: 21 additions & 3 deletions cypress/e2e/26-resource-locator.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WorkflowPage, NDV, CredentialsModal } from '../pages';
import { getVisiblePopper, getVisibleSelect } from '../utils';
import { getVisiblePopper } from '../utils';

const workflowPage = new WorkflowPage();
const ndv = new NDV();
Expand Down Expand Up @@ -40,18 +40,36 @@ describe('Resource Locator', () => {
it('should show appropriate error when credentials are not valid', () => {
workflowPage.actions.addInitialNodeToCanvas('Manual');
workflowPage.actions.addNodeToCanvas('Google Sheets', true, true, 'Update row in sheet');
workflowPage.getters.nodeCredentialsSelect().click();

// Add oAuth credentials
getVisibleSelect().find('li').last().click();
workflowPage.getters.nodeCredentialsSelect().click();
workflowPage.getters.nodeCredentialsCreateOption().click();
credentialsModal.getters.credentialsEditModal().should('be.visible');
credentialsModal.getters.credentialAuthTypeRadioButtons().should('have.length', 2);
credentialsModal.getters.credentialAuthTypeRadioButtons().first().click();
credentialsModal.actions.fillCredentialsForm();
cy.get('.el-message-box').find('button').contains('Close').click();

ndv.getters.resourceLocatorInput('documentId').click();
ndv.getters.resourceLocatorErrorMessage().should('contain', INVALID_CREDENTIALS_MESSAGE);
});

it('should show appropriate errors when search filter is required', () => {
workflowPage.actions.addNodeToCanvas('Github', true, true, 'On Pull Request');
ndv.getters.resourceLocator('owner').should('be.visible');
ndv.getters.resourceLocatorInput('owner').click();
ndv.getters.resourceLocatorErrorMessage().should('contain', NO_CREDENTIALS_MESSAGE);

workflowPage.getters.nodeCredentialsSelect().click();
workflowPage.getters.nodeCredentialsCreateOption().click();
credentialsModal.getters.credentialsEditModal().should('be.visible');
credentialsModal.actions.fillCredentialsForm();

ndv.getters.resourceLocatorInput('owner').click();
ndv.getters.resourceLocatorSearch('owner').type('owner');
ndv.getters.resourceLocatorErrorMessage().should('contain', INVALID_CREDENTIALS_MESSAGE);
});

it('should reset resource locator when dependent field is changed', () => {
workflowPage.actions.addInitialNodeToCanvas('Manual');
workflowPage.actions.addNodeToCanvas('Google Sheets', true, true, 'Update row in sheet');
Expand Down
2 changes: 2 additions & 0 deletions cypress/pages/ndv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export class NDV extends BasePage {
resourceLocatorErrorMessage: () => cy.getByTestId('rlc-error-container'),
resourceLocatorModeSelector: (paramName: string) =>
this.getters.resourceLocator(paramName).find('[data-test-id="rlc-mode-selector"]'),
resourceLocatorSearch: (paramName: string) =>
this.getters.resourceLocator(paramName).findChildByTestId('rlc-search'),
resourceMapperFieldsContainer: () => cy.getByTestId('mapping-fields-container'),
resourceMapperSelectColumn: () => cy.getByTestId('matching-column-select'),
resourceMapperRemoveFieldButton: (fieldName: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export default defineComponent({
return this.cachedResponses[this.currentRequestKey] || null;
},
currentQueryResults(): IResourceLocatorResultExpanded[] {
const results = this.currentResponse ? this.currentResponse.results : [];
const results = this.currentResponse?.results ?? [];
return results.map(
(result: INodeListSearchItems): IResourceLocatorResultExpanded => ({
Expand Down Expand Up @@ -648,6 +648,11 @@ export default defineComponent({
}
},
loadResourcesDebounced() {
if (this.currentResponse?.error) {
// Clear error response immediately when retrying to show loading state
delete this.cachedResponses[this.currentRequestKey];
}
void this.callDebounced(this.loadResources, {
debounceTime: 1000,
trailing: true,
Expand All @@ -664,6 +669,11 @@ export default defineComponent({
const paramsKey = this.currentRequestKey;
const cachedResponse = this.cachedResponses[paramsKey];
if (this.credentialsNotSet) {
this.setResponse(paramsKey, { error: true });
return;
}
if (this.requiresSearchFilter && !params.filter) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:width="width"
:popper-class="$style.popover"
:visible="show"
trigger="manual"
:teleported="false"
data-test-id="resource-locator-dropdown"
>
<div v-if="errorView" :class="$style.messageContainer">
Expand Down

0 comments on commit fdd81ea

Please sign in to comment.