From 57dba485cec20b85cb892f2dd06c9ed68fe4a16f Mon Sep 17 00:00:00 2001 From: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com> Date: Fri, 8 Jul 2022 13:57:59 +0100 Subject: [PATCH] fix: fixes google sheets datasource global search error (#15020) * fixes google sheets datasource global search error * Adds cypress test * Fix cypress test * Fixes navigating to google sheets queries from global search issue --- .../OtherUIFeatures/GlobalSearch_spec.js | 22 +++++++++++++++++++ .../cypress/locators/DatasourcesEditor.json | 1 + .../cypress/support/dataSourceCommands.js | 6 +++++ .../editorComponents/GlobalSearch/index.tsx | 9 ++++++++ .../pages/Editor/DataSourceEditor/index.tsx | 1 - 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/OtherUIFeatures/GlobalSearch_spec.js b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/OtherUIFeatures/GlobalSearch_spec.js index 56a395e009..0c646c2445 100644 --- a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/OtherUIFeatures/GlobalSearch_spec.js +++ b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/OtherUIFeatures/GlobalSearch_spec.js @@ -4,6 +4,7 @@ const dsl = require("../../../../fixtures/MultipleWidgetDsl.json"); const globalSearchLocators = require("../../../../locators/GlobalSearch.json"); const datasourceHomeLocators = require("../../../../locators/apiWidgetslocator.json"); const datasourceLocators = require("../../../../locators/DatasourcesEditor.json"); +const appPage = require("../../../../locators/PgAdminlocators.json"); describe("GlobalSearch", function() { before(() => { @@ -166,6 +167,27 @@ describe("GlobalSearch", function() { cy.get(datasourceHomeLocators.apiTxt) .invoke("val") .then((title) => expect(title).includes("Api")); + }); + + it("8. navigatesToGoogleSheetsQuery does not break again: Bug 15012", () => { + cy.createGoogleSheetsDatasource(); + cy.renameDatasource("XYZ"); + cy.wait(4000); + cy.get(appPage.dropdownChevronLeft).click(); + + cy.get(commonlocators.globalSearchTrigger).click({ force: true }); + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(1000); // modal open transition should be deterministic + cy.get(commonlocators.globalSearchInput).type("XYZ"); + cy.get("body").type("{enter}"); + + cy.get(".t--save-datasource") + .contains("Save and Authorize") + .should("be.visible"); + + cy.deleteDatasource("XYZ"); + + // this should be called at the end of the last test case in this spec file. cy.NavigateToHome(); }); }); diff --git a/app/client/cypress/locators/DatasourcesEditor.json b/app/client/cypress/locators/DatasourcesEditor.json index 77047f0b6f..34276bc814 100644 --- a/app/client/cypress/locators/DatasourcesEditor.json +++ b/app/client/cypress/locators/DatasourcesEditor.json @@ -13,6 +13,7 @@ "PostgreSQL": ".t--plugin-name:contains('PostgreSQL')", "SMTP":".t--plugin-name:contains('SMTP')", "MySQL": ".t--plugin-name:contains('MySQL')", + "GoogleSheets": ".t--plugin-name:contains('Google Sheets')", "sectionAuthentication": "[data-cy=section-Authentication]", "PostgresEntity": ".t--entity-name:contains(PostgreSQL)", "MySQLEntity": ".t--entity-name:contains(Mysql)", diff --git a/app/client/cypress/support/dataSourceCommands.js b/app/client/cypress/support/dataSourceCommands.js index b7dc975044..9535691b17 100644 --- a/app/client/cypress/support/dataSourceCommands.js +++ b/app/client/cypress/support/dataSourceCommands.js @@ -356,6 +356,12 @@ Cypress.Commands.add("createPostgresDatasource", () => { cy.testSaveDatasource(); }); +// this can be modified further when google sheets automation is done. +Cypress.Commands.add("createGoogleSheetsDatasource", () => { + cy.NavigateToDatasourceEditor(); + cy.get(datasourceEditor.GoogleSheets).click(); +}); + Cypress.Commands.add("deleteDatasource", (datasourceName) => { cy.NavigateToQueryEditor(); cy.get(pages.integrationActiveTab) diff --git a/app/client/src/components/editorComponents/GlobalSearch/index.tsx b/app/client/src/components/editorComponents/GlobalSearch/index.tsx index ad2603385a..68efa1ae54 100644 --- a/app/client/src/components/editorComponents/GlobalSearch/index.tsx +++ b/app/client/src/components/editorComponents/GlobalSearch/index.tsx @@ -84,6 +84,8 @@ import { builderURL, jsCollectionIdURL, } from "RouteBuilder"; +import { getPlugins } from "selectors/entitiesSelector"; +import { PluginType } from "entities/Action"; const StyledContainer = styled.div<{ category: SearchCategory; query: string }>` width: ${({ category, query }) => @@ -194,6 +196,7 @@ function GlobalSearch() { const category = useSelector( (state: AppState) => state.ui.globalSearch.filterContext.category, ); + const plugins = useSelector(getPlugins); const setCategory = useCallback( (category: SearchCategory) => { if (isSnippet(category)) { @@ -412,12 +415,18 @@ function GlobalSearch() { const { config } = item; const { id, pageId, pluginType } = config; const actionConfig = getActionConfig(pluginType); + let plugin; + // passing plugins for SAAS actions since they require it for computing urls. + if (pluginType === PluginType.SAAS) { + plugin = plugins.find((plugin) => plugin?.id === config?.pluginId); + } const url = actionConfig?.getURL( applicationSlug, pageIdToSlugMap[pageId] as string, pageId, id, pluginType, + plugin, ); toggleShow(); url && history.push(url); diff --git a/app/client/src/pages/Editor/DataSourceEditor/index.tsx b/app/client/src/pages/Editor/DataSourceEditor/index.tsx index 7ae8d61c04..dbc622fa17 100644 --- a/app/client/src/pages/Editor/DataSourceEditor/index.tsx +++ b/app/client/src/pages/Editor/DataSourceEditor/index.tsx @@ -241,7 +241,6 @@ class DatasourceEditorRouter extends React.Component { datasourceId, }), ); - return; } // Default to old flow