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: add option to mark application as forkable #21874

Merged
merged 30 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
37e2de8
wip
akash-codemonk Mar 29, 2023
2e92e0e
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk Mar 29, 2023
6b35e1c
chore: fixes
akash-codemonk Mar 29, 2023
9c63cc9
chore: fixes
akash-codemonk Mar 29, 2023
44c82e5
chore: stick to single line
akash-codemonk Mar 29, 2023
265fb4d
fix: switch component bug
akash-codemonk Mar 29, 2023
e31647c
fix: fork button not shown when non-public
akash-codemonk Mar 29, 2023
9a88eea
chore: add cypress test
akash-codemonk Mar 30, 2023
67122ab
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk Mar 30, 2023
33cfb74
chore: fix warning
akash-codemonk Mar 30, 2023
43e7474
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk Mar 31, 2023
6cb5a98
chore: fix cypress import
akash-codemonk Mar 31, 2023
73fcf07
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk Apr 10, 2023
c62952f
chore: fix fork button shown for a moment
akash-codemonk Apr 10, 2023
d8ba3f8
chore: remove messages to constants
akash-codemonk Apr 10, 2023
0a308c1
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk Apr 10, 2023
d5d1b7b
chore: update test
akash-codemonk Apr 10, 2023
b299a1b
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk Apr 11, 2023
5229d37
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk Apr 16, 2023
d8cc14a
chore: update tooltip message and remove confirmation modal
akash-codemonk Apr 16, 2023
afc7e54
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk May 14, 2023
353d2b3
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk May 15, 2023
5480f3c
fix: add back confirmation modal
akash-codemonk May 15, 2023
9595522
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk May 17, 2023
686ae8e
chore: fix test
akash-codemonk May 17, 2023
4c133c9
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk May 22, 2023
8c3de83
Merge branch 'release' of github.com:appsmithorg/appsmith into feat/e…
akash-codemonk May 23, 2023
05eaf67
feat: update to ads 2.0
akash-codemonk May 23, 2023
863e644
chore: fix tests
akash-codemonk May 23, 2023
0e74a80
chore: fix tests
akash-codemonk May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("Fork application across workspaces", function () {
});
cy.wait(2000);
}

cy.get("#sidebar").should("be.visible");
cy.PublishtheApp();
_.agHelper.Sleep(2000);
cy.get("button:contains('Share')").first().click({ force: true });
Expand Down Expand Up @@ -99,8 +99,36 @@ describe("Fork application across workspaces", function () {
cy.wait(10000);
cy.get(applicationLocators.forkButton).first().click({ force: true });
cy.get(homePage.forkAppWorkspaceButton).should("be.visible");
_.agHelper.GetNClick(_.locators._dialogCloseButton);
cy.LogOut();
cy.LogintoApp(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
_.homePage.CreateNewApplication();
});
});
});
});

it("Mark application as forkable", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add index to it

_.appSettings.OpenAppSettings();
_.appSettings.GoToEmbedSettings();
_.embedSettings.ToggleMarkForkable();
Copy link
Contributor

@Aishwarya-U-R Aishwarya-U-R May 23, 2023

Choose a reason for hiding this comment

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

Can we also add test for _.embedSettings.ToggleMarkForkable(false); after true?


_.inviteModal.OpenShareModal();
_.homePage.InviteUserToWorkspaceFromApp(
Cypress.env("TESTUSERNAME1"),
"App Viewer",
false,
);
_.inviteModal.CloseModal();

_.deployMode.DeployApp();
cy.url().then((url) => {
forkableAppUrl = url;
cy.LogOut();
cy.LogintoApp(Cypress.env("TESTUSERNAME1"), Cypress.env("TESTPASSWORD1"));
cy.visit(forkableAppUrl);

_.agHelper.AssertElementVisible(applicationLocators.forkButton);
});
});
});
1 change: 1 addition & 0 deletions app/client/cypress/support/Objects/CommonLocators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class CommonLocators {
_commentString = ".cm-comment";
_modalWrapper = "[data-testid='modal-wrapper']";
_editorBackButton = ".t--close-editor";
_dialogCloseButton = ".ads-v2-modal__content-header-close-button";
_evaluateMsg = ".t--evaluatedPopup-error";
_canvas = "[data-testid=widgets-editor]";
_enterPreviewMode = "[data-testid='edit-mode']";
Expand Down
17 changes: 17 additions & 0 deletions app/client/cypress/support/Pages/AppSettings/EmbedSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class EmbedSettings {
_restrictedText: "Embedding restricted",
_disabledText: "Embedding disabled",
_showNavigationBar: "[data-testid='show-navigation-bar-toggle']",
_enableForking: "[data-testid='forking-enabled-toggle']",
_confirmForking: "[data-testid='allow-forking']",
};

public OpenEmbedSettings() {
Expand Down Expand Up @@ -45,4 +47,19 @@ export class EmbedSettings {
}
});
}

public ToggleMarkForkable(check: "true" | "false" = "true") {
const input = this.agHelper.GetElement(this.locators._enableForking);
input.invoke("attr", "checked").then((value) => {
if (value !== check) {
this.agHelper.GetNClick(this.locators._enableForking);

if (check) {
this.agHelper.GetNClick(this.locators._confirmForking);
}

this.agHelper.ValidateNetworkStatus("@updateApplication");
}
});
}
}
10 changes: 8 additions & 2 deletions app/client/cypress/support/Pages/HomePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,11 @@ export class HomePage {
cy.xpath(this._uploadFile).attachFile(fixtureJson);
this.agHelper.Sleep(3500);
}
public InviteUserToWorkspaceFromApp(email: string, role: string) {
public InviteUserToWorkspaceFromApp(
email: string,
role: string,
validate = true,
) {
const successMessage =
CURRENT_REPO === REPO.CE
? "The user has been invited successfully"
Expand All @@ -446,7 +450,9 @@ export class HomePage {
.its("request.headers")
.should("have.property", "origin", "Cypress");
// cy.contains(email, { matchCase: false });
cy.contains(successMessage);
if (validate) {
cy.contains(successMessage);
}
}

public InviteUserToApplicationFromApp(email: string, role: string) {
Expand Down
9 changes: 9 additions & 0 deletions app/client/src/ce/actions/applicationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ export const updateCurrentApplicationEmbedSetting = (
};
};

export const updateCurrentApplicationForkingEnabled = (
forkingEnabled: boolean,
) => {
return {
type: ReduxActionTypes.CURRENT_APPLICATION_FORKING_ENABLED_UPDATE,
payload: forkingEnabled,
};
};

export const updateApplicationNavigationSettingAction = (
navigationSetting: NavigationSetting,
) => {
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/ce/api/ApplicationApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export type UpdateApplicationPayload = {
navigationSetting?: NavigationSetting;
appPositioning?: AppPositioningTypeConfig;
};
forkingEnabled?: boolean;
};

export type UpdateApplicationRequest = UpdateApplicationPayload & {
Expand Down Expand Up @@ -206,6 +207,7 @@ export interface UpdateApplicationResponse {
evaluationVersion: number;
applicationVersion: number;
isManualUpdate: boolean;
forkingEnabled: boolean;
appLayout: AppLayoutConfig;
new: boolean;
modifiedAt: Date;
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/ce/constants/ReduxActionConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ const ActionTypes = {
CURRENT_APPLICATION_EMBED_SETTING_UPDATE:
"CURRENT_APPLICATION_EMBED_SETTING_UPDATE",
UPDATE_NAVIGATION_SETTING: "UPDATE_NAVIGATION_SETTING",
CURRENT_APPLICATION_FORKING_ENABLED_UPDATE:
"CURRENT_APPLICATION_FORKING_ENABLED_UPDATE",
FORK_APPLICATION_INIT: "FORK_APPLICATION_INIT",
FORK_APPLICATION_SUCCESS: "FORK_APPLICATION_SUCCESS",
IMPORT_APPLICATION_INIT: "IMPORT_APPLICATION_INIT",
Expand Down
10 changes: 10 additions & 0 deletions app/client/src/ce/constants/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,12 @@ export const IN_APP_EMBED_SETTING = {
allowEmbeddingLabel: () => "Embedding enabled",
allowEmbeddingTooltip: () =>
"This app can be embedded in all domains, including malicious ones",
forkApplicationConfirmation: {
title: () => "Allow developers to fork this app to their workspace?",
body: () => "Forking allows developers to copy your app to their workspace",
cancel: () => "CANCEL",
confirm: () => "ALLOW FORKING",
},
copy: () => "Copy",
copied: () => "Copied",
limitEmbeddingLabel: () => "Embedding restricted",
Expand All @@ -1574,6 +1580,10 @@ export const IN_APP_EMBED_SETTING = {
sectionContentHeader: () => "Share",
sectionHeaderDesc: () => "Make public, embed properties",
showNavigationBar: () => "Show navigation bar",
forkContentHeader: () => "Fork",
forkLabel: () => "Make application forkable",
forkLabelTooltip: () =>
"Forking allows developers to copy your app to their workspace",
upgradeHeading: () =>
"Please contact your workspace admin to make the app public before embedding",
upgradeHeadingForInviteModal: () =>
Expand Down
12 changes: 12 additions & 0 deletions app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,18 @@ export const handlers = {
},
};
},
[ReduxActionTypes.CURRENT_APPLICATION_FORKING_ENABLED_UPDATE]: (
state: ApplicationsReduxState,
action: ReduxAction<boolean>,
) => {
return {
...state,
currentApplication: {
...state.currentApplication,
forkingEnabled: action.payload,
},
};
},
[ReduxActionTypes.UPDATE_NAVIGATION_SETTING]: (
state: ApplicationsReduxState,
action: ReduxAction<NavigationSetting>,
Expand Down
8 changes: 8 additions & 0 deletions app/client/src/ce/sagas/ApplicationSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
updateApplicationNavigationSettingAction,
updateCurrentApplicationEmbedSetting,
updateCurrentApplicationIcon,
updateCurrentApplicationForkingEnabled,
} from "@appsmith/actions/applicationActions";
import AnalyticsUtil from "utils/AnalyticsUtil";
import {
Expand Down Expand Up @@ -414,6 +415,13 @@ export function* updateApplicationSaga(
updateCurrentApplicationEmbedSetting(response.data.embedSetting),
);
}
if ("forkingEnabled" in request) {
yield put(
updateCurrentApplicationForkingEnabled(
response.data.forkingEnabled,
),
);
}
if (
request.applicationDetail?.navigationSetting &&
response.data.applicationDetail?.navigationSetting
Expand Down
12 changes: 10 additions & 2 deletions app/client/src/pages/AppViewer/PrimaryCTA.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ describe("App viewer fork button", () => {
render(
<Provider store={getStore()}>
<ThemeProvider theme={lightTheme}>
<PrimaryCTA navColorStyle="solid" primaryColor="red" />
<PrimaryCTA
navColorStyle="solid"
primaryColor="red"
url={"/app/test-3/page1-63cccd44463c535b9fbc297c/edit"}
/>
</ThemeProvider>
</Provider>,
);
Expand All @@ -161,7 +165,11 @@ describe("App viewer fork button", () => {
render(
<Provider store={getStore("SET_CURRENT_USER_DETAILS")}>
<ThemeProvider theme={lightTheme}>
<PrimaryCTA navColorStyle="solid" primaryColor="red" />
<PrimaryCTA
navColorStyle="solid"
primaryColor="red"
url={"/app/test-3/page1-63cccd44463c535b9fbc297c/edit"}
/>
</ThemeProvider>
</Provider>,
);
Expand Down
9 changes: 5 additions & 4 deletions app/client/src/pages/AppViewer/PrimaryCTA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ function PrimaryCTA(props: Props) {
</Tooltip>
);
}

if (!currentUser) return;
// We wait for the url to be available here to avoid showing the fork
// button for a moment and then showing the edit button i.e show one of the buttons once
// the data is available
if (!currentUser || !url) return;
if (
currentApplication?.forkingEnabled &&
currentApplication?.isPublic &&
currentUser?.username === ANONYMOUS_USERNAME
) {
return (
Expand All @@ -157,7 +158,7 @@ function PrimaryCTA(props: Props) {
);
}

if (currentApplication?.forkingEnabled && currentApplication?.isPublic) {
if (currentApplication?.forkingEnabled) {
return (
<div className="header__application-fork-btn-wrapper t--fork-btn-wrapper">
<Button
Expand Down
Loading
Loading