Skip to content

Commit

Permalink
Merge branch 'release' into chore/side-by-side-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hetunandu authored Jan 29, 2025
2 parents e7f7a00 + b62c875 commit ede2815
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe(
//Create and run query.

_.dataSources.EnterQuery(
"SELECT * FROM users ORDER BY username LIMIT 10;",
"SELECT * FROM users ORDER BY email LIMIT 10;",
1000,
);
_.dataSources.RunQuery();
Expand Down
3 changes: 3 additions & 0 deletions app/client/src/actions/pageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface FetchPublishedPageActionPayload {
export interface FetchPublishedPageResourcesPayload {
pageId: string;
basePageId: string;
branch: string;
}

export const fetchPublishedPageAction = (
Expand Down Expand Up @@ -298,12 +299,14 @@ export const clonePageSuccess = ({
// In future we can reuse this for fetching other page level resources in published mode
export const fetchPublishedPageResources = ({
basePageId,
branch,
pageId,
}: FetchPublishedPageResourcesPayload): ReduxAction<FetchPublishedPageResourcesPayload> => ({
type: ReduxActionTypes.FETCH_PUBLISHED_PAGE_RESOURCES_INIT,
payload: {
pageId,
basePageId,
branch,
},
});

Expand Down
26 changes: 13 additions & 13 deletions app/client/src/api/services/ConsolidatedPageLoadApi/api.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { api } from "api/core";
import type { InitConsolidatedApi } from "sagas/InitSagas";
import type { ConsolidatedApiParams } from "./types";
import { ConsolidatedApiUtils } from "./url";

const BASE_URL = "v1/consolidated-api";
const VIEW_URL = `${BASE_URL}/view`;
const EDIT_URL = `${BASE_URL}/edit`;
export const getConsolidatedPageLoadDataView = async (
params: ConsolidatedApiParams,
) => {
const viewUrl = ConsolidatedApiUtils.getViewUrl(params);

export const getConsolidatedPageLoadDataView = async (params: {
applicationId?: string;
defaultPageId?: string;
}) => {
return api.get<InitConsolidatedApi>(VIEW_URL, { params });
return api.get<InitConsolidatedApi>(viewUrl);
};

export const getConsolidatedPageLoadDataEdit = async (params: {
applicationId?: string;
defaultPageId?: string;
}) => {
return api.get<InitConsolidatedApi>(EDIT_URL, { params });
export const getConsolidatedPageLoadDataEdit = async (
params: ConsolidatedApiParams,
) => {
const editUrl = ConsolidatedApiUtils.getEditUrl(params);

return api.get<InitConsolidatedApi>(editUrl);
};
5 changes: 5 additions & 0 deletions app/client/src/api/services/ConsolidatedPageLoadApi/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface ConsolidatedApiParams {
applicationId?: string;
defaultPageId?: string;
branchName?: string;
}
25 changes: 25 additions & 0 deletions app/client/src/api/services/ConsolidatedPageLoadApi/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pickBy from "lodash/pickBy";
import identity from "lodash/identity";
import type { ConsolidatedApiParams } from "./types";

export class ConsolidatedApiUtils {
private static BASE_URL = "v1/consolidated-api";
private static VIEW_URL = `${this.BASE_URL}/view`;
private static EDIT_URL = `${this.BASE_URL}/edit`;

static getViewUrl = (requestParams: ConsolidatedApiParams) => {
// Remove undefined values from the requestParams object
const queryParamsObject = pickBy(requestParams, identity);
const queryParamsString = new URLSearchParams(queryParamsObject).toString();

return `${this.VIEW_URL}?${queryParamsString}`;
};

static getEditUrl = (requestParams: ConsolidatedApiParams) => {
// Remove undefined values from the requestParams object
const queryParamsObject = pickBy(requestParams, identity);
const queryParamsString = new URLSearchParams(queryParamsObject).toString();

return `${this.EDIT_URL}?${queryParamsString}`;
};
}
8 changes: 5 additions & 3 deletions app/client/src/ce/sagas/PageSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,13 @@ export function* fetchPublishedPageResourcesSaga(
action: ReduxAction<FetchPublishedPageResourcesPayload>,
) {
try {
const { basePageId, pageId } = action.payload;
const { basePageId, branch: branchName, pageId } = action.payload;

const params = { defaultPageId: basePageId };
const initConsolidatedApiResponse: ApiResponse<InitConsolidatedApi> =
yield ConsolidatedPageLoadApi.getConsolidatedPageLoadDataView(params);
yield ConsolidatedPageLoadApi.getConsolidatedPageLoadDataView({
defaultPageId: basePageId,
branchName,
});

const isValidResponse: boolean = yield validateResponse(
initConsolidatedApiResponse,
Expand Down
38 changes: 11 additions & 27 deletions app/client/src/ce/utils/serviceWorkerUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,9 @@ describe("serviceWorkerUtils", () => {

expect(request).toBeInstanceOf(Request);
expect(request?.url).toBe(
`https://app.appsmith.com/api/v1/consolidated-api/edit?defaultPageId=${basePageId}&applicationId=${baseApplicationId}`,
`https://app.appsmith.com/api/v1/consolidated-api/edit?defaultPageId=${basePageId}&applicationId=${baseApplicationId}&branchName=${params.branchName}`,
);
expect(request?.method).toBe("GET");
expect(request?.headers.get("Branchname")).toBe("main");
});

it("should create request for PUBLISHED mode with applicationId", () => {
Expand All @@ -369,10 +368,9 @@ describe("serviceWorkerUtils", () => {

expect(request).toBeInstanceOf(Request);
expect(request?.url).toBe(
`https://app.appsmith.com/api/v1/consolidated-api/view?defaultPageId=${basePageId}&applicationId=${baseApplicationId}`,
`https://app.appsmith.com/api/v1/consolidated-api/view?defaultPageId=${basePageId}&applicationId=${baseApplicationId}&branchName=${params.branchName}`,
);
expect(request?.method).toBe("GET");
expect(request?.headers.get("Branchname")).toBe("main");
});

it("should create request for EDIT mode without applicationId", () => {
Expand All @@ -387,10 +385,9 @@ describe("serviceWorkerUtils", () => {

expect(request).toBeInstanceOf(Request);
expect(request?.url).toBe(
`https://app.appsmith.com/api/v1/consolidated-api/edit?defaultPageId=page123`,
`https://app.appsmith.com/api/v1/consolidated-api/edit?defaultPageId=${params.basePageId}&branchName=${params.branchName}`,
);
expect(request?.method).toBe("GET");
expect(request?.headers.get("Branchname")).toBe("main");
});

it("should create request for PUBLISHED mode without applicationId", () => {
Expand All @@ -405,10 +402,9 @@ describe("serviceWorkerUtils", () => {

expect(request).toBeInstanceOf(Request);
expect(request?.url).toBe(
`https://app.appsmith.com/api/v1/consolidated-api/view?defaultPageId=page123`,
`https://app.appsmith.com/api/v1/consolidated-api/view?defaultPageId=${params.basePageId}&branchName=${params.branchName}`,
);
expect(request?.method).toBe("GET");
expect(request?.headers.get("Branchname")).toBe("main");
});

it("should return null for an unknown app mode", () => {
Expand Down Expand Up @@ -438,10 +434,9 @@ describe("serviceWorkerUtils", () => {

expect(consolidatedAPIRequest).toBeInstanceOf(Request);
expect(consolidatedAPIRequest?.url).toBe(
`https://app.appsmith.com/api/v1/consolidated-api/edit?defaultPageId=page123`,
`https://app.appsmith.com/api/v1/consolidated-api/edit?defaultPageId=${params.basePageId}&branchName=${params.branchName}`,
);
expect(consolidatedAPIRequest?.method).toBe("GET");
expect(consolidatedAPIRequest?.headers.get("Branchname")).toBe("main");
});
});

Expand Down Expand Up @@ -475,27 +470,16 @@ describe("serviceWorkerUtils", () => {

describe("getRequestKey", () => {
it("should return the correct request key", () => {
const request = new Request("https://app.appsmith.com", {
method: "GET",
});

request.headers.append("branchname", "main");
const key = prefetchApiService.getRequestKey(request);

expect(key).toBe("GET:https://app.appsmith.com/:branchname:main");
});

it("should only append branchname header in request key", () => {
const request = new Request("https://app.appsmith.com", {
method: "GET",
const url =
"https://app.appsmith.com/api/v1/consolidated-api/edit?defaultPageId=page123&applicationId=app123&branchName=main";
const method = "GET";
const request = new Request(url, {
method,
});

request.headers.append("branchname", "main");
request.headers.append("another-header-key", "another-header-value");
request.headers.append("Content-Type", "application/json");
const key = prefetchApiService.getRequestKey(request);

expect(key).toBe("GET:https://app.appsmith.com/:branchname:main");
expect(key).toBe(`${method}:${url}`);
});
});

Expand Down
49 changes: 20 additions & 29 deletions app/client/src/ce/utils/serviceWorkerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BUILDER_PATH_DEPRECATED,
VIEWER_PATH_DEPRECATED,
} from "../constants/routes/appRoutes";
import { ConsolidatedApiUtils } from "api/services/ConsolidatedPageLoadApi/url";

interface TMatchResult {
basePageId?: string;
Expand Down Expand Up @@ -104,36 +105,36 @@ export const getConsolidatedApiPrefetchRequest = (
const { appMode, baseApplicationId, basePageId, branchName, origin } =
applicationProps;

const headers = new Headers();
const searchParams = new URLSearchParams();

if (!basePageId) {
return null;
}

searchParams.append("defaultPageId", basePageId);

if (baseApplicationId) {
searchParams.append("applicationId", baseApplicationId);
}

// Add the branch name to the headers
if (branchName) {
headers.append("Branchname", branchName);
}

// If the URL matches the builder path
if (appMode === APP_MODE.EDIT) {
const requestUrl = `${origin}/api/${"v1/consolidated-api/edit"}?${searchParams.toString()}`;
const request = new Request(requestUrl, { method: "GET", headers });
const requestUrl = ConsolidatedApiUtils.getEditUrl({
defaultPageId: basePageId,
applicationId: baseApplicationId,
branchName,
});

const request = new Request(`${origin}/api/${requestUrl}`, {
method: "GET",
});

return request;
}

// If the URL matches the viewer path
if (appMode === APP_MODE.PUBLISHED) {
const requestUrl = `${origin}/api/v1/consolidated-api/view?${searchParams.toString()}`;
const request = new Request(requestUrl, { method: "GET", headers });
const requestUri = ConsolidatedApiUtils.getViewUrl({
defaultPageId: basePageId,
applicationId: baseApplicationId,
branchName,
});

const request = new Request(`${origin}/api/${requestUri}`, {
method: "GET",
});

return request;
}
Expand Down Expand Up @@ -166,22 +167,12 @@ export class PrefetchApiService {
cacheMaxAge = 2 * 60 * 1000; // 2 minutes in milliseconds
// Mutex to lock the fetch and cache operation
prefetchFetchMutexMap = new Map<string, Mutex>();
// Header keys used to create the unique request key
headerKeys = ["branchname"];

constructor() {}

// Function to get the request key
getRequestKey = (request: Request) => {
let requestKey = `${request.method}:${request.url}`;

this.headerKeys.forEach((headerKey) => {
const headerValue = request.headers.get(headerKey);

if (headerValue) {
requestKey += `:${headerKey}:${headerValue}`;
}
});
const requestKey = `${request.method}:${request.url}`;

return requestKey;
};
Expand Down
1 change: 1 addition & 0 deletions app/client/src/pages/AppViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function AppViewer(props: Props) {
fetchPublishedPageResources({
basePageId,
pageId,
branch,
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { isEmail } from "utils/formhelpers";
import ReduxFormTextField from "components/utils/ReduxFormTextField";
import { PRICING_PAGE_URL } from "constants/ThirdPartyConstants";
import { getAppsmithConfigs } from "ee/configs";
import { getInstanceId, isFreePlan } from "ee/selectors/tenantSelectors";
import { getInstanceId } from "ee/selectors/tenantSelectors";
import { pricingPageUrlSource } from "ee/utils/licenseHelpers";
import { RampFeature, RampSection } from "utils/ProductRamps/RampsControlList";
import {
Expand All @@ -29,6 +29,8 @@ import {
shouldLearnMoreButtonBeVisible,
} from "./Helpers";
import { PREMIUM_INTEGRATION_CONTACT_FORM } from "./Constants";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "ee/entities/FeatureFlag";

const FormWrapper = styled.form`
display: flex;
Expand All @@ -41,7 +43,8 @@ const PremiumDatasourceContactForm = (
) => {
const instanceId = useSelector(getInstanceId);
const appsmithConfigs = getAppsmithConfigs();
const isFreePlanInstance = useSelector(isFreePlan);
// We are using this feature flag to identify whether its the enterprise/business user - ref : https://www.notion.so/appsmith/Condition-for-showing-Premium-Soon-tag-datasources-184fe271b0e2802cb55bd63f468df60d
const isGACEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);

const redirectPricingURL = PRICING_PAGE_URL(
appsmithConfigs.pricingUrl,
Expand All @@ -68,24 +71,20 @@ const PremiumDatasourceContactForm = (
}, [redirectPricingURL, props.email, props.integrationName]);

const submitEvent = useCallback(() => {
handleSubmitEvent(
props.integrationName,
props.email || "",
!isFreePlanInstance,
);
}, [props.email, props.integrationName, isFreePlanInstance]);
handleSubmitEvent(props.integrationName, props.email || "", isGACEnabled);
}, [props.email, props.integrationName, isGACEnabled]);

return (
<>
<ModalHeader>
{getContactFormModalTitle(props.integrationName, !isFreePlanInstance)}
{getContactFormModalTitle(props.integrationName, isGACEnabled)}
</ModalHeader>
<FormWrapper onSubmit={props.handleSubmit(onSubmit)}>
<Text renderAs="p">
{getContactFormModalDescription(
props.email || "",
props.integrationName,
!isFreePlanInstance,
isGACEnabled,
)}
</Text>
<Field
Expand All @@ -99,7 +98,7 @@ const PremiumDatasourceContactForm = (
type="email"
/>
<ModalFooter>
{shouldLearnMoreButtonBeVisible(!isFreePlanInstance) && (
{shouldLearnMoreButtonBeVisible(isGACEnabled) && (
<Button
aria-label="Learn more"
kind="secondary"
Expand All @@ -110,10 +109,7 @@ const PremiumDatasourceContactForm = (
</Button>
)}
<Button isDisabled={props.invalid} size="md" type="submit">
{getContactFormSubmitButtonText(
props.email || "",
!isFreePlanInstance,
)}
{getContactFormSubmitButtonText(props.email || "", isGACEnabled)}
</Button>
</ModalFooter>
</FormWrapper>
Expand Down
Loading

0 comments on commit ede2815

Please sign in to comment.