Skip to content

Commit

Permalink
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
Browse files Browse the repository at this point in the history
…o action-redesign/googleai-v2
  • Loading branch information
ankitakinger committed Sep 4, 2024
2 parents 41d6218 + 7d7a601 commit dda8cee
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 27 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/sync-release-to-pg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ jobs:
uses: actions/checkout@v3
with:
ref: release # Checkout the release branch
fetch-depth: 0

- name: Fetch all branches
run: git fetch origin pg
- name: Set Git config values
run: |
git config pull.rebase false
git config user.email "automated@github.com"
git config user.name "Automated Github Action"
- name: Checkout pg branch
run: git checkout pg

- name: Merge release to pg
id: merge_commits
run: |
PG_HEAD=$(git rev-parse pg)
RELEASE_HEAD=$(git rev-parse release)
echo "PG_HEAD=$PG_HEAD"
echo "RELEASE_HEAD=$RELEASE_HEAD"
# Checkout the pg branch
git checkout pg
# Attempt to merge release into pg
if ! git merge release; then
echo "Merge conflict detected during merge"
Expand All @@ -42,7 +42,6 @@ jobs:
CONFLICTING_COMMIT=$(git log -1 --pretty=format:"%H")
echo "CONFLICTING_COMMIT=$CONFLICTING_COMMIT" >> $GITHUB_ENV
git merge --abort
echo "MERGE_CONFLICT=true" >> $GITHUB_ENV
else
echo "MERGE_CONFLICT=false" >> $GITHUB_ENV
Expand All @@ -68,6 +67,8 @@ jobs:
# This unwieldy horror of a sed command, converts standard Markdown links to Slack's unwieldy link syntax.
slack_message="$(echo "$message" | sed -E 's/\[([^]]+)\]\(([^)]+)\)/<\2|\1>/g')"
echo "$slack_message"
# This is the ChannelId of the proj postgres channel.
body="$(jq -nc \
--arg channel C06Q3A97USE \
Expand Down
7 changes: 7 additions & 0 deletions app/client/src/ce/utils/workflowHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export const useWorkflowOptions = () => {
return [];
};

// We don't want to show the create new JS object option if the user is in the workflow editor
// this is done since worflows runner doesn't support multiple JS objects
// TODO: Remove this once workflows can support multiple JS objects
export const checkIfJSObjectCreationAllowed = () => {
return false;
};
1 change: 1 addition & 0 deletions app/client/src/components/common/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const CardFooter = styled.div`
display: flex;
align-items: center;
margin: 4px 0 0 0;
justify-content: space-between;
width: ${(props) => props.theme.card.minWidth}px;
@media screen and (min-width: 1500px) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,58 @@ describe("getFilteredAndSortedFileOperations", () => {
}),
);
});

it("should not show new js object option if disableJSObjectCreation is true", () => {
const fileOptions = useFilteredAndSortedFileOperations({
query: "new js",
allDatasources: [],
recentlyUsedDSMap: {},
canCreateActions: true,
canCreateDatasource: true,
disableJSObjectCreation: true,
});

expect(fileOptions.length).toEqual(1);
expect(fileOptions[0]).toEqual(
expect.objectContaining({
title: "New datasource",
}),
);
});

it("should show new js object option if disableJSObjectCreation is false", () => {
const fileOptions = useFilteredAndSortedFileOperations({
query: "new js",
allDatasources: [],
recentlyUsedDSMap: {},
canCreateActions: true,
canCreateDatasource: true,
disableJSObjectCreation: false,
});

expect(fileOptions.length).toEqual(2);
expect(fileOptions[0]).toEqual(
expect.objectContaining({
title: "New JS Object",
}),
);
});

it("should show new js object option if disableJSObjectCreation is not set", () => {
const fileOptions = useFilteredAndSortedFileOperations({
query: "new js",
allDatasources: [],
recentlyUsedDSMap: {},
canCreateActions: true,
canCreateDatasource: true,
disableJSObjectCreation: false,
});

expect(fileOptions.length).toEqual(2);
expect(fileOptions[0]).toEqual(
expect.objectContaining({
title: "New JS Object",
}),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import type { Plugin } from "api/PluginApi";
import { useModuleOptions } from "ee/utils/moduleInstanceHelpers";
import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers";
import { createNewQueryBasedOnParentEntity } from "ee/actions/helpers";
import { useWorkflowOptions } from "ee/utils/workflowHelpers";
import {
checkIfJSObjectCreationAllowed,
useWorkflowOptions,
} from "ee/utils/workflowHelpers";

export interface FilterFileOperationsProps {
canCreateActions: boolean;
Expand All @@ -58,6 +61,11 @@ export const useFilteredFileOperations = ({
const moduleOptions = useModuleOptions();
const workflowOptions = useWorkflowOptions();

// We don't want to show the create new JS object option if the user is in the workflow editor
// this is done since worflows runner doesn't support multiple JS objects
// TODO: Remove this once workflows can support multiple JS objects
const disableJSObjectCreation = checkIfJSObjectCreationAllowed();

// helper map for sorting based on recent usage
const recentlyUsedDSMap = useRecentlyUsedDSMap();

Expand Down Expand Up @@ -90,13 +98,16 @@ export const useFilteredFileOperations = ({
plugins,
recentlyUsedDSMap,
query,
// TODO: Remove this once workflows can support multiple JS objects
disableJSObjectCreation,
});
};

export const useFilteredAndSortedFileOperations = ({
allDatasources = [],
canCreateActions = true,
canCreateDatasource = true,
disableJSObjectCreation = false,
moduleOptions = [],
plugins = [],
query,
Expand All @@ -111,6 +122,7 @@ export const useFilteredAndSortedFileOperations = ({
query: string;
recentlyUsedDSMap?: Record<string, number>;
workflowOptions?: ActionOperation[];
disableJSObjectCreation?: boolean;
}) => {
const fileOperations: ActionOperation[] = [];

Expand All @@ -127,8 +139,11 @@ export const useFilteredAndSortedFileOperations = ({
*/
const actionOps = updateActionOperations(plugins, actionOperations);

// Add JS Object operation
fileOperations.push(actionOps[2]);
// TODO: Remove this check once workflows can support multiple JS objects
if (!disableJSObjectCreation) {
// Add JS Object operation
fileOperations.push(actionOps[2]);
}

// Add Module operations
if (moduleOptions.length > 0) {
Expand Down
6 changes: 3 additions & 3 deletions app/client/src/pages/Editor/Explorer/Files/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Files() {

const onCreate = useCallback(() => {
openMenu(true);
}, [dispatch, openMenu]);
}, [openMenu]);

const activeActionBaseId = useActiveActionBaseId();

Expand Down Expand Up @@ -141,7 +141,7 @@ function Files() {
);
}
}),
[files, activeActionBaseId, parentEntityId],
[files, activeActionBaseId, parentEntityId, parentEntityType],
);

const handleClick = useCallback(
Expand All @@ -161,7 +161,7 @@ function Files() {
item.redirect(parentEntityId, DatasourceCreateEntryPoints.SUBMENU);
}
},
[parentEntityId, dispatch],
[dispatch, parentEntityId, parentEntityType],
);

return (
Expand Down
27 changes: 26 additions & 1 deletion app/client/src/pages/UserProfile/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import { render } from "@testing-library/react";
import { render, screen, fireEvent } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import { lightTheme } from "selectors/themeSelectors";
Expand Down Expand Up @@ -87,6 +87,15 @@ jest.mock("actions/gitSyncActions", () => ({
fetchGlobalGitConfigInit: jest.fn(),
}));

const mockHistoryPush = jest.fn();

jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
useHistory: () => ({
push: mockHistoryPush,
}),
}));

const mockStore = configureStore([]);
describe("Git config ", () => {
// TODO: Fix this the next time the file is edited
Expand Down Expand Up @@ -128,6 +137,22 @@ describe("Git config ", () => {
expect(getAllByText("Sign in to your account")).toBeInTheDocument;
});

it("should call history push when user goes back to applications", () => {
store = mockStore(defaultStoreState);
render(
<Provider store={store}>
<ThemeProvider theme={lightTheme}>
<Router>
<UserProfile />
</Router>
</ThemeProvider>
</Provider>,
);
const backButton = screen.getByText("Back");
fireEvent.click(backButton);
expect(mockHistoryPush).toHaveBeenCalledWith("/applications");
});

afterAll(() => {
jest.clearAllMocks();
store.clearActions();
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/pages/UserProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function UserProfile() {
return (
<PageWrapper displayName={"Profile"}>
<ProfileWrapper>
<BackButton />
<BackButton goTo="/applications" />
<Tabs defaultValue={selectedTab} onValueChange={setSelectedTab}>
<TabsList>
{tabs.map((tab) => {
Expand Down
30 changes: 30 additions & 0 deletions app/client/src/pages/workspace/__tests__/settings.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import React from "react";
import "@testing-library/jest-dom";
import Router from "react-router-dom";
import { BrowserRouter } from "react-router-dom";
import { render, screen } from "test/testUtils";
import {
render as testRender,
screen as testScreen,
} from "@testing-library/react";
import { fireEvent } from "@testing-library/react";
import Settings from "../settings";
import * as reactRedux from "react-redux";
import configureStore from "redux-mock-store";
import { Provider } from "react-redux";

// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -151,9 +159,16 @@ const mockWorkspaceData = {
new: false,
};

const mockHistoryPush = jest.fn();

const mockStore = configureStore([]);

jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
useParams: jest.fn(),
useHistory: () => ({
push: mockHistoryPush,
}),
}));

function renderComponent() {
Expand Down Expand Up @@ -190,4 +205,19 @@ describe("<Settings />", () => {
expect(tabList.length).toBeGreaterThanOrEqual(2);
expect(tabList.length).toBeLessThanOrEqual(3);
});

it("should redirect to workspace page if user wants to go back", () => {
testRender(
<BrowserRouter>
<Provider store={mockStore(mockWorkspaceData)}>
<Settings />
</Provider>
</BrowserRouter>,
);
const backBtn = testScreen.getByText("Back");
fireEvent.click(backBtn);
expect(mockHistoryPush).toHaveBeenCalledWith(
`/applications?workspaceId=${mockWorkspaceData.id}`,
);
});
});
2 changes: 1 addition & 1 deletion app/client/src/pages/workspace/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default function Settings() {
<>
<SettingsWrapper data-testid="t--settings-wrapper" isMobile={isMobile}>
<StyledStickyHeader isMobile={isMobile}>
<BackButton />
<BackButton goTo={`/applications?workspaceId=${workspaceId}`} />
<SettingsPageHeader
buttonText="Add users"
onButtonClick={onButtonClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.json.JSONObject;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StringUtils;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -279,12 +278,16 @@ protected Set<String> updateEntitiesInRepo(ApplicationGitReference applicationGi

fileOperations.scanAndDeleteDirectoryForDeletedResources(validPages, baseRepo.resolve(PAGE_DIRECTORY));

// Save JS Libs if there's at least one change
if (modifiedResources != null
&& (modifiedResources.isAllModified()
|| !CollectionUtils.isEmpty(
modifiedResources.getModifiedResourceMap().get(CUSTOM_JS_LIB_LIST)))) {
// Earlier this condition included that modified resource not be null, and
// it should either have allModified flag turned as true or CUSTOM_JS_LIB_LIST resource map is not empty
// Save JS Libs if there's at least one change.

// What are the possible caveats of making this change?
// Since each resource in the entry needs to be present in the Modified resource map to be written
// There won't be any differences in writing files.
// In terms of performance, we would need to access the customJSLib directory every time to
// compare with the valid js libs.
if (modifiedResources != null) {
Path jsLibDirectory = baseRepo.resolve(JS_LIB_DIRECTORY);
Set<Map.Entry<String, Object>> jsLibEntries =
applicationGitReference.getJsLibraries().entrySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Datasource extends GitSyncedDomain {
String templateName;

// This is only kept public for embedded datasource
@JsonView({Views.Public.class, FromRequest.class})
@JsonView({Views.Public.class, FromRequest.class, Git.class})
DatasourceConfiguration datasourceConfiguration;

@Transient
Expand Down
Loading

0 comments on commit dda8cee

Please sign in to comment.