Skip to content

Commit

Permalink
Merge branch 'refs/heads/release' into chore/combine-plugin-editor-ui…
Browse files Browse the repository at this point in the history
…-state
  • Loading branch information
hetunandu committed Oct 3, 2024
2 parents 58a9158 + a01edff commit 151246e
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import EditorNavigation, {
} from "../../../../../support/Pages/EditorNavigation";

const ppt =
"https://ssz.sgp1.digitaloceanspaces.com/3ZEO2582C29EA0KKK2/ppt-on-population-pptxafa26c44-208f-46a3-89cc-8a5c020b6863.pptx";
"http://host.docker.internal:4200/ppt-on-population-pptxafa26c44-208f-46a3-89cc-8a5c020b6863.pptx";
const pngImage =
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRb8umIiCU_K6ac-xS-ni4y6SP7XAd8C7Ms3Q&usqp=CAU";
const jpgImage =
"https://community.appsmith.com/sites/default/files/styles/small_thumbnail/public/2024-03/aws-logo.jpg?itok=yG4bpfFs";
const pdf =
"https://www.learningcontainer.com/wp-content/uploads/2019/09/sample-pdf-file.pdf";
const pdf = "http://host.docker.internal:4200/sample-pdf-file.pdf";

describe(
"DocumentViewer Widget Functionality",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
agHelper,
apiPage,
dataManager,
entityExplorer,
jsEditor,
propPane,
Expand Down Expand Up @@ -76,18 +78,25 @@ describe("Tests fetch calls", { tags: ["@tag.JS"] }, () => {
});

it("3. Tests if fetch works with store value", function () {
apiPage.CreateAndFillApi(
dataManager.dsValues[dataManager.defaultEnviorment].mockGenderAge +
`{{this.params.person}}`,
"Gender_Age",
);
apiPage.RunAPI();
entityExplorer.DragDropWidgetNVerify("buttonwidget", 500, 200);
EditorNavigation.SelectEntityByName("Button1", EntityType.Widget);
propPane.TypeTextIntoField("Label", "getUserID");
propPane.TypeTextIntoField("Label", "getUserName");
propPane.EnterJSContext(
"onClick",
`{{fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(res => res.json())
.then(json => storeValue('userId', json.userId))
.then(() => showAlert("UserId: " + appsmith.store.userId))}}`,
`{{(async function(){
const gender = await Gender_Age.run({ person: "sagar" });
storeValue("Gender", gender);
showAlert("Your name is " + appsmith.store.Gender.name);
})()}}`,
);
agHelper.Sleep(2000);
agHelper.ClickButton("getUserID");
agHelper.AssertContains("UserId: 1", "exist");

agHelper.ClickButton("getUserName");
agHelper.AssertContains("Your name is sagar", "exist");
});
});
15 changes: 9 additions & 6 deletions app/client/src/actions/pageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,25 @@ export const fetchPageAction = (
export interface FetchPublishedPageActionPayload {
pageId: string;
bustCache?: boolean;
firstLoad?: boolean;
pageWithMigratedDsl?: FetchPageResponse;
}

export interface FetchPublishedPageResourcesPayload {
pageId: string;
basePageId: string;
}

export const fetchPublishedPageAction = (
pageId: string,
bustCache = false,
firstLoad = false,
pageWithMigratedDsl?: FetchPageResponse,
): ReduxAction<FetchPublishedPageActionPayload> => ({
type: ReduxActionTypes.FETCH_PUBLISHED_PAGE_INIT,
payload: {
pageId,
bustCache,
firstLoad,
pageWithMigratedDsl,
},
});
Expand Down Expand Up @@ -297,14 +299,12 @@ export const clonePageSuccess = ({

// Fetches resources required for published page, currently only used for fetching actions
// In future we can reuse this for fetching other page level resources in published mode
export const fetchPublishedPageResources = ({
basePageId,
pageId,
}: FetchPublishedPageResourcesPayload): ReduxAction<FetchPublishedPageResourcesPayload> => ({
export const fetchPublishedPageResourcesAction = (
pageId: string,
): ReduxAction<FetchPublishedPageResourcesPayload> => ({
type: ReduxActionTypes.FETCH_PUBLISHED_PAGE_RESOURCES_INIT,
payload: {
pageId,
basePageId,
},
});

Expand Down Expand Up @@ -675,18 +675,21 @@ export const setupPageAction = (
export interface SetupPublishedPageActionPayload {
pageId: string;
bustCache: boolean;
firstLoad: boolean;
pageWithMigratedDsl?: FetchPageResponse;
}

export const setupPublishedPage = (
pageId: string,
bustCache = false,
firstLoad = false,
pageWithMigratedDsl?: FetchPageResponse,
): ReduxAction<SetupPublishedPageActionPayload> => ({
type: ReduxActionTypes.SETUP_PUBLISHED_PAGE_INIT,
payload: {
pageId,
bustCache,
firstLoad,
pageWithMigratedDsl,
},
});
2 changes: 0 additions & 2 deletions app/client/src/ce/constants/ReduxActionConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,6 @@ const AppViewActionTypes = {
SET_APP_VIEWER_HEADER_HEIGHT: "SET_APP_VIEWER_HEADER_HEIGHT",
SET_APP_SIDEBAR_PINNED: "SET_APP_SIDEBAR_PINNED",
FETCH_PUBLISHED_PAGE_RESOURCES_INIT: "FETCH_PUBLISHED_PAGE_RESOURCES_INIT",
FETCH_PUBLISHED_PAGE_RESOURCES_SUCCESS:
"FETCH_PUBLISHED_PAGE_RESOURCES_SUCCESS",
};

const AppViewActionErrorTypes = {
Expand Down
101 changes: 49 additions & 52 deletions app/client/src/ce/sagas/PageSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,47 +325,12 @@ export function* fetchPageSaga(action: ReduxAction<FetchPageActionPayload>) {
}
}

export function* updateCanvasLayout(response: FetchPageResponse) {
// Wait for widget config to load before we can get the canvas payload
yield call(waitForWidgetConfigBuild);
// Get Canvas payload
const canvasWidgetsPayload = getCanvasWidgetsPayload(response);

// resize main canvas
resizePublishedMainCanvasToLowestWidget(canvasWidgetsPayload.widgets);
// Update the canvas
yield put(initCanvasLayout(canvasWidgetsPayload));

// Since new page has new layout, we need to generate a data structure
// to compute dynamic height based on the new layout.
yield put(generateAutoHeightLayoutTreeAction(true, true));
}

export function* postFetchedPublishedPage(
response: FetchPageResponse,
pageId: string,
) {
// set current page
yield put(
updateCurrentPage(
pageId,
response.data.slug,
response.data.userPermissions,
),
);
// Clear any existing caches
yield call(clearEvalCache);
// Set url params
yield call(setDataUrl);

yield call(updateCanvasLayout, response);
}

export function* fetchPublishedPageSaga(
action: ReduxAction<FetchPublishedPageActionPayload>,
) {
try {
const { bustCache, pageId, pageWithMigratedDsl } = action.payload;
const { bustCache, firstLoad, pageId, pageWithMigratedDsl } =
action.payload;

const params = { pageId, bustCache };
const response: FetchPageResponse = yield call(
Expand All @@ -377,9 +342,41 @@ export function* fetchPublishedPageSaga(
const isValidResponse: boolean = yield validateResponse(response);

if (isValidResponse) {
yield call(postFetchedPublishedPage, response, pageId);
// Clear any existing caches
yield call(clearEvalCache);
// Set url params
yield call(setDataUrl);
// Wait for widget config to load before we can get the canvas payload
yield call(waitForWidgetConfigBuild);
// Get Canvas payload
const canvasWidgetsPayload = getCanvasWidgetsPayload(response);

// resize main canvas
resizePublishedMainCanvasToLowestWidget(canvasWidgetsPayload.widgets);
// Update the canvas
yield put(initCanvasLayout(canvasWidgetsPayload));
// set current page
yield put(
updateCurrentPage(
pageId,
response.data.slug,
response.data.userPermissions,
),
);

// dispatch fetch page success
yield put(fetchPublishedPageSuccess());

// Since new page has new layout, we need to generate a data structure
// to compute dynamic height based on the new layout.
yield put(generateAutoHeightLayoutTreeAction(true, true));

/* Currently, All Actions are fetched in initSagas and on pageSwitch we only fetch page
*/
// Hence, if is not isFirstLoad then trigger evaluation with execute pageLoad action
if (!firstLoad) {
yield put(fetchAllPageEntityCompletion([executePageLoadActions()]));
}
}
} catch (error) {
yield put({
Expand All @@ -395,9 +392,9 @@ export function* fetchPublishedPageResourcesSaga(
action: ReduxAction<FetchPublishedPageResourcesPayload>,
) {
try {
const { basePageId, pageId } = action.payload;
const { pageId } = action.payload;

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

Expand All @@ -413,18 +410,10 @@ export function* fetchPublishedPageResourcesSaga(
// In future, we can reuse this saga to fetch other resources of the page like actionCollections etc
const { publishedActions } = response;

yield call(
postFetchedPublishedPage,
response.pageWithMigratedDsl,
pageId,
);

// NOTE: fetchActionsForView is used here to update publishedActions in redux store and not to fetch actions again
// Sending applicationId as empty as we have publishedActions present,
// it won't call the actions view api with applicationId
yield put(fetchActionsForView({ applicationId: "", publishedActions }));
yield put(fetchAllPageEntityCompletion([executePageLoadActions()]));
yield put({
type: ReduxActionTypes.FETCH_PUBLISHED_PAGE_RESOURCES_SUCCESS,
});
}
} catch (error) {
yield put({
Expand Down Expand Up @@ -1436,13 +1425,21 @@ export function* setupPublishedPageSaga(
action: ReduxAction<SetupPublishedPageActionPayload>,
) {
try {
const { bustCache, pageId, pageWithMigratedDsl } = action.payload;
const { bustCache, firstLoad, pageId, pageWithMigratedDsl } =
action.payload;

/*
Added the first line for isPageSwitching redux state to be true when page is being fetched to fix scroll position issue.
Added the second line for sync call instead of async (due to first line) as it was leading to issue with on page load actions trigger.
*/
yield put(fetchPublishedPageAction(pageId, bustCache, pageWithMigratedDsl));
yield put(
fetchPublishedPageAction(
pageId,
bustCache,
firstLoad,
pageWithMigratedDsl,
),
);
yield take(ReduxActionTypes.FETCH_PUBLISHED_PAGE_SUCCESS);

yield put({
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/ce/sagas/__tests__/PageSaga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe("ce/PageSaga", () => {
pageWithMigratedDsl: mockResponse.data
.pageWithMigratedDsl as FetchPageResponse,
bustCache: false,
firstLoad: true,
},
};

Expand All @@ -56,6 +57,7 @@ describe("ce/PageSaga", () => {
fetchPublishedPageAction(
action.payload.pageId,
action.payload.bustCache,
action.payload.firstLoad,
action.payload.pageWithMigratedDsl,
),
)
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/entities/Engine/AppViewerEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class AppViewerEngine extends AppEngine {
}),
fetchSelectedAppThemeAction(applicationId, currentTheme),
fetchAppThemesAction(applicationId, themes),
setupPublishedPage(toLoadPageId, true, pageWithMigratedDsl),
setupPublishedPage(toLoadPageId, true, true, pageWithMigratedDsl),
];

const successActionEffects = [
Expand Down
15 changes: 8 additions & 7 deletions app/client/src/pages/AppViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import { useSelector } from "react-redux";
import BrandingBadge from "./BrandingBadge";
import { setAppViewHeaderHeight } from "actions/appViewActions";
import { CANVAS_SELECTOR } from "constants/WidgetConstants";
import { fetchPublishedPageResources } from "actions/pageActions";
import {
setupPublishedPage,
fetchPublishedPageResourcesAction,
} from "actions/pageActions";
import usePrevious from "utils/hooks/usePrevious";
import { getIsBranchUpdated } from "../utils";
import { APP_MODE } from "entities/App";
Expand Down Expand Up @@ -162,12 +165,10 @@ function AppViewer(props: Props) {
)?.pageId;

if (pageId) {
dispatch(
fetchPublishedPageResources({
basePageId,
pageId,
}),
);
dispatch(setupPublishedPage(pageId, true));

// Used for fetching page resources
dispatch(fetchPublishedPageResourcesAction(basePageId));
}
}
}
Expand Down
13 changes: 0 additions & 13 deletions app/client/src/reducers/uiReducers/appViewReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ const appViewReducer = createReducer(initialState, {
[ReduxActionTypes.FETCH_PUBLISHED_PAGE_INIT]: (state: AppViewReduxState) => {
return { ...state, isFetchingPage: true };
},
[ReduxActionTypes.FETCH_PUBLISHED_PAGE_RESOURCES_INIT]: (
state: AppViewReduxState,
) => {
return { ...state, isFetchingPage: true };
},
[ReduxActionErrorTypes.FETCH_PUBLISHED_PAGE_ERROR]: (
state: AppViewReduxState,
) => {
Expand All @@ -49,14 +44,6 @@ const appViewReducer = createReducer(initialState, {
isFetchingPage: false,
};
},
[ReduxActionTypes.FETCH_PUBLISHED_PAGE_RESOURCES_SUCCESS]: (
state: AppViewReduxState,
) => {
return {
...state,
isFetchingPage: false,
};
},
[ReduxActionTypes.SET_APP_VIEWER_HEADER_HEIGHT]: (
state: AppViewReduxState,
action: ReduxAction<number>,
Expand Down
Loading

0 comments on commit 151246e

Please sign in to comment.