fix: paste widgets on a new page (#14295)

* paste widget on generate Page

* adding cypress tests
This commit is contained in:
rahulramesha 2022-06-09 17:17:47 +05:30 committed by GitHub
parent 6fafbf58df
commit c1da8a6866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 6 deletions

View File

@ -2,6 +2,7 @@ const widgetsPage = require("../../../../locators/Widgets.json");
const commonLocators = require("../../../../locators/commonlocators.json"); const commonLocators = require("../../../../locators/commonlocators.json");
const explorer = require("../../../../locators/explorerlocators.json"); const explorer = require("../../../../locators/explorerlocators.json");
const dsl = require("../../../../fixtures/WidgetCopyPaste.json"); const dsl = require("../../../../fixtures/WidgetCopyPaste.json");
const generatePage = require("../../../../locators/GeneratePage.json");
describe("Widget Copy paste", function() { describe("Widget Copy paste", function() {
const modifierKey = Cypress.platform === "darwin" ? "meta" : "ctrl"; const modifierKey = Cypress.platform === "darwin" ? "meta" : "ctrl";
@ -152,4 +153,17 @@ describe("Widget Copy paste", function() {
.find(widgetsPage.listWidget) .find(widgetsPage.listWidget)
.should("have.length", 0); .should("have.length", 0);
}); });
it("should be able to paste widget on the initial generate Page", function() {
cy.Createpage("NewPage", false);
//verify that it is in generate page
cy.get(generatePage.buildFromScratchActionCard).should("have.length", 1);
//paste
cy.get("body").type(`{${modifierKey}}{v}`);
//verify a pasted list widget
cy.get(widgetsPage.listWidget).should("have.length", 1);
});
}); });

View File

@ -716,7 +716,7 @@ Cypress.Commands.add("DeleteModal", () => {
.click({ force: true }); .click({ force: true });
}); });
Cypress.Commands.add("Createpage", (pageName) => { Cypress.Commands.add("Createpage", (pageName, navigateToCanvasPage = true) => {
let pageId; let pageId;
cy.get(pages.AddPage) cy.get(pages.AddPage)
.first() .first()
@ -734,7 +734,9 @@ Cypress.Commands.add("Createpage", (pageName) => {
pageidcopy = pageName; pageidcopy = pageName;
cy.wrap(pageId).as("currentPageId"); cy.wrap(pageId).as("currentPageId");
} }
cy.get(generatePage.buildFromScratchActionCard).click(); if (navigateToCanvasPage) {
cy.get(generatePage.buildFromScratchActionCard).click();
}
cy.get("#loading").should("not.exist"); cy.get("#loading").should("not.exist");
}); });
}); });

View File

@ -74,6 +74,9 @@ export const matchViewerForkPath = (pathName: string) =>
match(`${VIEWER_PATH_DEPRECATED}${VIEWER_FORK_PATH}`)(pathName); match(`${VIEWER_PATH_DEPRECATED}${VIEWER_FORK_PATH}`)(pathName);
export const matchTemplatesPath = match(TEMPLATES_PATH); export const matchTemplatesPath = match(TEMPLATES_PATH);
export const matchTemplatesIdPath = match(TEMPLATES_ID_PATH); export const matchTemplatesIdPath = match(TEMPLATES_ID_PATH);
export const matchGeneratePagePath = (pathName: string) =>
match(`${BUILDER_PATH}${GENERATE_TEMPLATE_PATH}`)(pathName) ||
match(`${BUILDER_PATH_DEPRECATED}${GENERATE_TEMPLATE_PATH}`)(pathName);
export const addBranchParam = (branch: string) => { export const addBranchParam = (branch: string) => {
const url = new URL(window.location.href); const url = new URL(window.location.href);

View File

@ -50,7 +50,7 @@ import { getExplorerPinned } from "selectors/explorerSelector";
import { setExplorerPinnedAction } from "actions/explorerActions"; import { setExplorerPinnedAction } from "actions/explorerActions";
import { setIsGitSyncModalOpen } from "actions/gitSyncActions"; import { setIsGitSyncModalOpen } from "actions/gitSyncActions";
import { GitSyncModalTab } from "entities/GitSync"; import { GitSyncModalTab } from "entities/GitSync";
import { matchBuilderPath } from "constants/routes"; import { matchBuilderPath, matchGeneratePagePath } from "constants/routes";
import { commentModeSelector } from "selectors/commentsSelectors"; import { commentModeSelector } from "selectors/commentsSelectors";
type Props = { type Props = {
@ -216,9 +216,14 @@ class GlobalHotKeys extends React.Component<Props> {
group="Canvas" group="Canvas"
label="Paste Widget" label="Paste Widget"
onKeyDown={() => { onKeyDown={() => {
this.props.pasteCopiedWidget( if (
this.props.getMousePosition() || { x: 0, y: 0 }, matchBuilderPath(window.location.pathname) ||
); matchGeneratePagePath(window.location.pathname)
) {
this.props.pasteCopiedWidget(
this.props.getMousePosition() || { x: 0, y: 0 },
);
}
}} }}
/> />
<Hotkey <Hotkey

View File

@ -139,6 +139,9 @@ import { reflow } from "reflow";
import { getBottomMostRow } from "reflow/reflowUtils"; import { getBottomMostRow } from "reflow/reflowUtils";
import { flashElementsById } from "utils/helpers"; import { flashElementsById } from "utils/helpers";
import { getSlidingCanvasName } from "constants/componentClassNameConstants"; import { getSlidingCanvasName } from "constants/componentClassNameConstants";
import { matchGeneratePagePath } from "constants/routes";
import { builderURL } from "RouteBuilder";
import history from "utils/history";
export function* resizeSaga(resizeAction: ReduxAction<WidgetResize>) { export function* resizeSaga(resizeAction: ReduxAction<WidgetResize>) {
try { try {
@ -1538,6 +1541,14 @@ function* pasteWidgetSaga(
yield put(updateAndSaveLayout(reflowedWidgets)); yield put(updateAndSaveLayout(reflowedWidgets));
if (
copiedWidgetGroups &&
copiedWidgetGroups.length > 0 &&
matchGeneratePagePath(window.location.pathname)
) {
history.push(builderURL());
}
yield put({ yield put({
type: ReduxActionTypes.RECORD_RECENTLY_ADDED_WIDGET, type: ReduxActionTypes.RECORD_RECENTLY_ADDED_WIDGET,
payload: newlyCreatedWidgetIds, payload: newlyCreatedWidgetIds,