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

feat: New tab ui changes #33228

Merged
merged 33 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bf1f488
feat: New tab ui changes
albinAppsmith May 7, 2024
d84c5d0
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 9, 2024
79f4185
fix: new query tab ui
albinAppsmith May 9, 2024
12534de
Removed duplicate type definition
albinAppsmith May 9, 2024
bee5670
fix: jest tests
albinAppsmith May 9, 2024
272561a
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 9, 2024
b2fa38b
fix: Add button and maximize button fixes
albinAppsmith May 10, 2024
ef30093
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 10, 2024
ab1e270
fix: cypress failures
albinAppsmith May 10, 2024
ae5654e
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 10, 2024
97feeb5
fix: add button logic change
albinAppsmith May 10, 2024
1012f63
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 10, 2024
e086e0f
fix: add click logic revert
albinAppsmith May 10, 2024
6d63f0d
fix: add and close button behaviour fix
albinAppsmith May 12, 2024
2da706b
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 12, 2024
cd2212b
fix: add and expand button shrink issue
albinAppsmith May 12, 2024
2e3629d
fix: new query tab scroll fix
albinAppsmith May 12, 2024
5ac67bc
fix: jest tests
albinAppsmith May 13, 2024
dd72f03
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 13, 2024
8d0a0ee
fix: cypress failures
albinAppsmith May 13, 2024
c0f210a
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 13, 2024
974b375
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 13, 2024
9540f0c
fix: cypress selector
albinAppsmith May 13, 2024
af6df38
fix: click create option function
albinAppsmith May 13, 2024
36faf74
fix: removed unnecessary function to get
albinAppsmith May 13, 2024
5c0b56d
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 13, 2024
bff3ef1
fix: code refactor
albinAppsmith May 14, 2024
54dda9b
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 14, 2024
6debce9
fix: dependency array for query add
albinAppsmith May 14, 2024
6dff7ef
fix: close issue
albinAppsmith May 14, 2024
6eb7205
fix: cypress refactor
albinAppsmith May 14, 2024
ea658d0
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith May 14, 2024
48223f4
fix: cypress failures
albinAppsmith May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("IDE add pane interactions", { tags: ["@tag.IDE"] }, () => {
// check add pane is open
PageLeftPane.assertInAddView();
// close add pane to show blank state
PageLeftPane.closeAddView();
PageLeftPane.closeAddView(PagePaneSegment.UI);
// click on add button and check add state
PageLeftPane.switchToAddNew();
// check add pane
Expand All @@ -28,7 +28,7 @@ describe("IDE add pane interactions", { tags: ["@tag.IDE"] }, () => {
// check add pane is open
PageLeftPane.assertInAddView();
// close add pane
PageLeftPane.closeAddView();
PageLeftPane.closeAddView(PagePaneSegment.UI);
// click on canvas and check add pane visible or not
agHelper.GetNClick(commonLocators._canvas).click();
// check add pane
Expand Down Expand Up @@ -67,7 +67,7 @@ describe("IDE add pane interactions", { tags: ["@tag.IDE"] }, () => {
// check add pane
PageLeftPane.assertInAddView();
// close add pane
PageLeftPane.closeAddView();
PageLeftPane.closeAddView(PagePaneSegment.Queries);
// open add pane to add item
PageLeftPane.switchToAddNew();
// add item
Expand Down
14 changes: 14 additions & 0 deletions app/client/cypress/support/Pages/AggregateHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,4 +1806,18 @@ export class AggregateHelper {
// }
// return items;
// }, { timeout: 5000 });

public GetChildrenNClick(
selector: string,
childSelector: string,
index = 0,
force = false,
waitTimeInterval = 500,
ctrlKey = false,
) {
return this.ScrollIntoView(selector, index)
.children(childSelector)
.click({ force: force, ctrlKey: ctrlKey })
.wait(waitTimeInterval);
}
}
6 changes: 4 additions & 2 deletions app/client/cypress/support/Pages/EntityExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import EditorNavigation, {
PageLeftPane,
PagePaneSegment,
} from "./EditorNavigation";
import AddView from "./IDE/AddView";
import PageList from "./PageList";

type templateActions =
Expand Down Expand Up @@ -49,6 +50,7 @@ export class EntityExplorer {
public locator = ObjectsRegistry.CommonLocators;
private modifierKey = Cypress.platform === "darwin" ? "meta" : "ctrl";
private assertHelper = ObjectsRegistry.AssertHelper;
private addView = new AddView();

public _contextMenu = (entityNameinLeftSidebar: string) =>
"//div[text()='" +
Expand Down Expand Up @@ -247,8 +249,8 @@ export class EntityExplorer {
this.agHelper.ClickOutside(); //to close the evaluated pop-up
PageLeftPane.switchSegment(PagePaneSegment.Queries);
PageLeftPane.switchToAddNew();
let overlayItem = this._visibleTextSpan(dsName);
this.agHelper.GetNClick(overlayItem);
let overlayItem = this.addView.getCreateOptions(dsName);
overlayItem.click({ force: true });
}

public CopyPasteWidget(widgetName: string) {
Expand Down
10 changes: 6 additions & 4 deletions app/client/cypress/support/Pages/IDE/AddView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { ObjectsRegistry } from "../../Objects/Registry";

class AddView {
public locators = {
addPane: "[data-testid='t--ide-add-pane']",
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The search results indicate that the data-testid='t--ide-add-pane' is used in multiple TypeScript files within the project. This suggests that the data-testid is not unique, which could potentially lead to issues in the test scripts where this identifier is expected to be unique for specific elements.

Files where data-testid='t--ide-add-pane' is found:

  • app/client/src/pages/Editor/IDE/EditorPane/UI/Add.tsx
  • app/client/src/pages/Editor/IDE/EditorPane/Query/Add.tsx
  • app/client/src/pages/Editor/IDE/EditorPane/JS/Add.tsx

Given this information, it is clear that the data-testid is not uniquely implemented across the project, which contradicts the requirement for uniqueness to avoid test failures.

Analysis chain

Added a new locator for the add pane. Ensure that the data-testid is unique and correctly implemented in the corresponding HTML element to avoid test failures.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the uniqueness and correct implementation of the `data-testid` for the add pane.

# Test: Search for the `data-testid` in the project. Expect: Only one occurrence in the expected HTML element.
rg --type html $'data-testid="t--ide-add-pane"'

Length of output: 48



Script:

#!/bin/bash
# Description: Search for the `data-testid` 't--ide-add-pane' in JavaScript and TypeScript files to verify its implementation and uniqueness.

# Search in JavaScript and TypeScript files
rg --type js --type ts 'data-testid="t--ide-add-pane"'

Length of output: 331

closePaneButton: "[data-testid='t--add-pane-close-icon']",
createOption: "[data-testid='t--create-option']",
createOption: (name: string) =>
".t--datasoucre-create-option-" + name.toLowerCase().replace(/ /g, "_"),
};

constructor() {
Expand All @@ -12,16 +14,16 @@ class AddView {

public assertInAddView() {
ObjectsRegistry.AggregateHelper.AssertElementVisibility(
this.locators.closePaneButton,
this.locators.addPane,
);
}

public closeAddView() {
ObjectsRegistry.AggregateHelper.GetNClick(this.locators.closePaneButton);
}

public getCreateOptions(): Cypress.Chainable {
return cy.get(this.locators.createOption);
public getCreateOptions(name: string): Cypress.Chainable {
return cy.get(this.locators.createOption(name));
}
}

Expand Down
14 changes: 13 additions & 1 deletion app/client/cypress/support/Pages/IDE/FileTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class FileTabs {
container: "[data-testid='t--editor-tabs']",
tabName: (name: string) => `[data-testid='t--ide-tab-${name}']`,
tabs: ".editor-tab",
addItem: "[data-testid='t--ide-split-screen-add-button']",
addItem: "[data-testid='t--ide-tabs-add-button']",
closeTab: "[data-testid='t--tab-close-btn']",
};

assertVisibility() {
Expand Down Expand Up @@ -32,6 +33,17 @@ class FileTabs {
}
});
}

closeTab(name: string) {
const tab = this.locators.tabName(name);
ObjectsRegistry.AggregateHelper.HoverElement(tab);
ObjectsRegistry.AggregateHelper.GetChildrenNClick(
tab,
this.locators.closeTab,
0,
true,
);
}
}

export default new FileTabs();
18 changes: 14 additions & 4 deletions app/client/cypress/support/Pages/IDE/LeftPane.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ObjectsRegistry } from "../../Objects/Registry";
import { PagePaneSegment } from "../EditorNavigation";
import AddView from "./AddView";
import FileTabs from "./FileTabs";
import ListView from "./ListView";

export class LeftPane {
Expand Down Expand Up @@ -112,12 +114,20 @@ export class LeftPane {
this.addView.assertInAddView();
}

public closeAddView() {
this.addView.closeAddView();
public closeAddView(segment: PagePaneSegment) {
Copy link
Member

Choose a reason for hiding this comment

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

This argument here is an anti-pattern. If we are seeing that the closing of the add view is different based on segments, it should be added as behaviours or exposed via sub classes

if (!this.segments) {
throw Error("No Segments configured");
}
cy.log(segment, "===Albin");
if (segment === PagePaneSegment.UI) {
this.addView.closeAddView();
} else {
FileTabs.closeTab("new");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Several files in the codebase still use the old function signature.

  • The closeAddView method in LeftPane.ts handles the UI segment explicitly but defaults to a generic action for other segments (Queries and JS). This might not be the intended behavior for these segments, and it could lead to unexpected results.
  • Consider reviewing the handling of all segments in the closeAddView method to ensure that each segment's specific requirements are met.
Analysis chain

Introduced a new method closeAddView that takes a segment parameter to determine the closing behavior. This is a significant change that adds flexibility but ensure that all segments are correctly handled and that there are no unhandled cases.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all segments are correctly handled in the `closeAddView` method.

# Test: Check the method implementation for handling different segments.
cat app/client/cypress/support/Pages/IDE/LeftPane.ts | grep -A 10 "closeAddView"

Length of output: 482



Script:

#!/bin/bash
# Description: Check the definition of the enum `PagePaneSegment` to verify all possible segments.

# Test: Retrieve the definition of `PagePaneSegment`.
ast-grep --lang typescript --pattern 'enum PagePaneSegment {$$$}'

Length of output: 438

}

public getCreateOptions() {
return this.addView.getCreateOptions();
public getCreateOptions(name: string) {
return this.addView.getCreateOptions(name);
}

public assertInListView() {
Expand Down
4 changes: 2 additions & 2 deletions app/client/src/ce/constants/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2326,9 +2326,9 @@ export const EDITOR_PANE_TEXTS = {
js_add_button: () => "New JS object",
js_blank_object_item: () => "Blank JS object",
widget_add_button: () => "New UI element",
query_create_tab_title: () => "Create new query / API",
query_create_tab_title: () => "Create new query from",
widgets_create_tab_title: () => "Drag & drop UI elements",
js_create_tab_title: () => "Create JS object",
js_create_tab_title: () => "Create JS object from",
queries_create_from_existing: () => "From existing datasource",
queries_create_new: () => "New API",
loading_building_blocks: () => "Loading building blocks",
Expand Down
48 changes: 21 additions & 27 deletions app/client/src/ce/pages/Editor/IDE/EditorPane/JS/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,28 @@ export const useJSAdd = () => {
(opt) => opt.focusEntityType === FocusEntity.JS_MODULE_INSTANCE,
);

return useCallback(() => {
if (jsModuleCreationOptions.length === 0) {
if (segmentMode === EditorEntityTabState.Add) {
const url = getJSUrl(currentEntityInfo, false);
history.push(url);
return useCallback(
Copy link
Member

Choose a reason for hiding this comment

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

Passing a boolean argument here adds more complication to an already complicated hook. I strongly believe we need to refactor this to be more explicit

(add: boolean) => {
if (jsModuleCreationOptions.length === 0) {
if (segmentMode === EditorEntityTabState.Add) {
const url = getJSUrl(currentEntityInfo, false);
history.push(url);
} else {
dispatch(createNewJSCollection(pageId, "ENTITY_EXPLORER"));
}
} else {
dispatch(createNewJSCollection(pageId, "ENTITY_EXPLORER"));
if (currentEntityInfo.entity === FocusEntity.JS_OBJECT_ADD && add) {
return;
}
const url = getJSUrl(
currentEntityInfo,
!(segmentMode === EditorEntityTabState.Add),
);
history.push(url);
}
} else {
const url = getJSUrl(
currentEntityInfo,
!(segmentMode === EditorEntityTabState.Add),
);
history.push(url);
}
}, [
dispatch,
pageId,
segmentMode,
currentEntityInfo,
jsModuleCreationOptions,
]);
},
[dispatch, pageId, segmentMode, currentEntityInfo, jsModuleCreationOptions],
);
};

export const useIsJSAddLoading = () => {
Expand Down Expand Up @@ -111,17 +111,11 @@ export const useJSSegmentRoutes = (path: string): UseRoutes => {
];
}
return [
{
exact: true,
key: "AddJS",
component: AddJS,
path: [`${path}${ADD_PATH}`, `${path}/:collectionId${ADD_PATH}`],
},
{
exact: false,
key: "ListJS",
component: ListJS,
path: [path],
path: [path, `${path}${ADD_PATH}`, `${path}/:collectionId${ADD_PATH}`],
},
];
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo } from "react";
import React, { useCallback, useMemo } from "react";
import history from "utils/history";
import { useLocation } from "react-router";
import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity";
Expand Down Expand Up @@ -27,35 +27,35 @@ import {
import { SAAS_EDITOR_API_ID_PATH } from "pages/Editor/SaaSEditor/constants";
import ApiEditor from "pages/Editor/APIEditor";
import type { UseRoutes } from "@appsmith/entities/IDE/constants";
import {
EditorEntityTabState,
EditorViewMode,
} from "@appsmith/entities/IDE/constants";
import { EditorViewMode } from "@appsmith/entities/IDE/constants";
import QueryEditor from "pages/Editor/QueryEditor";
import AddQuery from "pages/Editor/IDE/EditorPane/Query/Add";
import ListQuery from "pages/Editor/IDE/EditorPane/Query/List";
import type { AppState } from "@appsmith/reducers";
import keyBy from "lodash/keyBy";
import { getPluginEntityIcon } from "pages/Editor/Explorer/ExplorerIcons";
import type { ListItemProps } from "design-system";
import { Tag, type ListItemProps } from "design-system";
import { useCurrentEditorState } from "pages/Editor/IDE/hooks";
import CurlImportEditor from "pages/Editor/APIEditor/CurlImportEditor";
import { createAddClassName } from "pages/Editor/IDE/EditorPane/utils";

export const useQueryAdd = () => {
const location = useLocation();
const currentEntityInfo = identifyEntityFromPath(location.pathname);
const { segmentMode } = useCurrentEditorState();

const addButtonClickHandler = useCallback(() => {
let url = "";
if (segmentMode === EditorEntityTabState.Add) {
// Already in add mode, back to the previous active item
url = getQueryUrl(currentEntityInfo, false);
} else {
url = getQueryUrl(currentEntityInfo);
}
history.push(url);
}, [currentEntityInfo, segmentMode]);
const addButtonClickHandler = useCallback(
(add: boolean) => {
// if already in add mode, don call url function
// same for if not in add mode
if (currentEntityInfo.entity === FocusEntity.QUERY_ADD && add) {
return;
}
const url = getQueryUrl(currentEntityInfo, add);
history.push(url);
},
[currentEntityInfo, segmentMode],
);

return addButtonClickHandler;
};
Expand Down Expand Up @@ -166,17 +166,11 @@ export const useQuerySegmentRoutes = (path: string): UseRoutes => {
];
}
return [
{
key: "AddQuery",
exact: true,
component: AddQuery,
path: [`${path}${ADD_PATH}`, `${path}/:queryId${ADD_PATH}`],
},
{
key: "ListQuery",
exact: false,
component: ListQuery,
path: [path],
path: [path, `${path}${ADD_PATH}`, `${path}/:queryId${ADD_PATH}`],
},
];
};
Expand All @@ -202,17 +196,24 @@ export const useAddQueryListItems = () => {

const getListItems = (data: any[]) => {
return data.map((fileOperation) => {
const title =
fileOperation.entityExplorerTitle ||
fileOperation.dsName ||
fileOperation.title;
const className = createAddClassName(title);
const icon =
fileOperation.icon ||
(fileOperation.pluginId &&
getPluginEntityIcon(pluginGroups[fileOperation.pluginId]));
return {
startIcon: icon,
title:
fileOperation.entityExplorerTitle ||
fileOperation.dsName ||
fileOperation.title,
description: !!fileOperation.isBeta ? "Beta" : "",
wrapperClassName: className,
title,
description: !!fileOperation.isBeta ? (
<Tag isClosable={false}>Beta</Tag>
) : (
""
),
descriptionType: "inline",
onClick: onCreateItemClick.bind(null, fileOperation),
} as ListItemProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("JS Segment", () => {
expect(result.current).toBeDefined();

act(() => {
result.current();
result.current(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding assertions to verify the state before and after the dispatch to ensure the state is updated as expected.

});

expect(mockDispatchFn).toBeCalledWith({
Expand All @@ -66,7 +66,7 @@ describe("JS Segment", () => {

// Call the function now from a different page
act(() => {
result.current();
result.current(true);
});

// Now the creation action should have the new page id
Expand Down