PromucFlow_constructor/app/client/src/sagas/PageSagas.tsx

839 lines
24 KiB
TypeScript
Raw Normal View History

2019-11-25 05:07:27 +00:00
import CanvasWidgetsNormalizer from "normalizers/CanvasWidgetsNormalizer";
import { AppState } from "reducers";
import {
Page,
PageListPayload,
ReduxAction,
ReduxActionErrorTypes,
ReduxActionTypes,
2019-09-24 12:36:03 +00:00
UpdateCanvasPayload,
2019-11-25 05:07:27 +00:00
} from "constants/ReduxActionConstants";
import {
clonePageSuccess,
[API breaking change : Automated Tests Will Fail] Page And Action Refactor (#549) * Introduced new page which stores the published and unpublished pages as separate. * Mid level commit to save the state. * Parity of new page repository with old page repository (custom functions) * WIP : Delete a page. This requires changes across application structure as well. * Added publishedPages construct inside application to store the pages in the deployed view as well as isDefault so that the same changes (delete or isDefault) in unpublished view doesn't alter these fields for the published application * Parity reached with PageService. * Minor ActionService refactor to remove unnecessary code. ApplicationPageService, LayoutActionService, LayoutService use the new page service to fetch the pages Minor corrections in fetching the page from new page service in tests * New save function which sets the PageDTO for unpublished page and then saves the new page into repository. * Migration of page service functions to new page service functions across other services/tests/controller * Finished migrating all the page service functions to the new page service functions * Application Service Tests have been fixed. * All the existing test cases are working now. * Publish application implemented to store published pages as well. Added a basic test case to check that published pages is being set and that page's publishedPageDTO is being set accordingly. * Minor TODOs added to add test cases for published application. * A few tests to ascertain that published application page fields (deleted, isDefault) does not get changed when these statuses are changed for a page in edit mode. * Added a new controller end point to fetch application in view mode. * Added new endpoint for fetching an application in view mode on the client. * Bug fix where get application in view mode API was not getting called. * Fixed the get page names by application & archive pages which have been deleted in edit mode during publishing of application. * During delete page, if a page was never published and it was deleted during edit, delete the entire page instead of just deleting the unpublished PageDTO * Minor formatting. * Non working client side code to fetch page list using view mode. * revert unnecassary changes and streamlined view and edit actions * Fix missed import * Fixed a bug where if a page is not published, it should not be returned in view mode in list of page names api. * Fixed update for a page which was not working in integration test. * ActionDTO added. * Solidified the new action structure. * Migration added for NewAction index creation and NewAction per Action insertion in the database. * Basic file structure added the new repository, custom repository, service, etc. * Delete OldPage.java * Repo functions added - TODO : Haven;t handled the published/edited views * Helper functions added to convert Action to NewAction and vice-versa. Removed unused currentUserMono usage. * Create & update action functionality added. * Execute Action refactored. Removed dry run specific code. * Repository migrated to handle new data structure. Execute action refactored to no longer support dry runs of actions. * TODO added for special handling of change view of application to handle edge cases of pages/actions which either exist in published mode but don't exist in unpublished mode or vice versa. * Migrated finding on load actions from spring repository to custom repository. * In view mode, now actions are being fetched by application id directly instead of first fetching application and then using the page ids, fetching the actions. This reduces the db calls from 2 to 1 per fetch actions in view mode api call. * Delete action and get all actions (used in edit mode on the client side) implemented. * Updated CollectionService and ActionCollectionService to use the new action service instead of the old one. * LayoutActionService refactored to now use the new service functions. * ActionController now no longer used ActionService. The remaining service functions have been migrated to the new action service. * Refactor across ACL code for addition/removal of policies during addition/removal of users to organization, making app public, refactor for services like policy utils, item service, etc. * Removed the last of action repository and action service and replaced with new action repo and new action service. * Compile and run time issues fixed. The server is coming up without any spring dependency errors. * WIP in fixing fetching actions by page id. * Finally!!! Fixed the fetch actions (both published and unpublished actions) by page id repository function. * Fixed create action bug where null datasource in published actiondto (inside newly created action) leads to error. * Fixed the execute action issues : 1. Removed the dry runs from the tests 2. Fixed the null pointer error in variable substituted action and datasource configurations. * 1. Fixed the custom action repository field names. 2. Fixed the data structures used in ExamplesOrganizationClonerTests * Fixed countByDatasourceId repository function which was querying the actions incorrectly. * Fixed the clone example organization error where the id of the action was not getting updated in the page correctly. Yay! * Fixed post merge compilation failure. * Fixed more compilation time failures in ActionServiceTest * Fixed failing test case for fetching actions in view mode. * Minor changes to resolve merge changes and incorporate in the new refactored code. * 1. Fixed compile time errors on Client code. 2. Fixed fetching of actions in view mode by application id. The repository function did not need name parameter. Removed the same. * [Integration Testing Error Fix] : Added a new test case for refactor action name. * Instead of fetching actions in the page, mistakenly used the base service which was fetching all the actions in the repository, barring none which led to the name refactor being blocked even though no action in the current page exists with the new proposed name, * Added delete functionality to action service. * Minor code cleanup * Adding viewMode to action execution * Replacing action with actionId. * 1. Bug fix for deletion of unpublished action. In case of never published action, the entire action should be deleted. In case an action was published, only the unpublished action should be deleted. 2. In case of DB actions (external datasources), only the bare minimum fields should be stored inside the action (datasource id and datasource plugin id). The other fields should not be duplicated across code. * Fixed yarn build compilation issues. * Update app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com> * Changed the API path for GET applications in view mode. Some minor code formatting. * Incorporated review comments. * Some more unnecessary code removed. * Instead of returning Page, now the interface object between client and server for Pages is PageDTO * Migrated Page and Action to PageDTO and ActionDTO Fixed the compilation issues. TODO : Fix the test compilation issues. * Fixed compilation time issues with all the tests by migrating Page and Action to PageDTO and ActionDTO respectively * Action Controller and Page Controller no longer extend Base Controller. All the required functions have now been implemented and no base line API end points are being re-used from the base. * Test case fixes. * Bug Fix : Updating an action was not updating execute on load. Fixed the data flow leading to the error. * Deprecating Page and Action domain objects. This is to ensure no new code is written with these till we remove this old code. * Cloned example applications are now published before returning. This is to ensure that the applications are in ready to view mode when the new user signs up. * Added a function comment to expand on the usage of new param introduced. * When cloning a page, new actions were not being stored. Added that. Also updated the clonePage test to assert that the actions are also cloned when the pages are cloned. * Updated a Api call * removed extra slash Co-authored-by: Hetu Nandu <hetunandu@gmail.com> Co-authored-by: Satbir Singh <satbir121@gmail.com> Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com> Co-authored-by: nandan.anantharamu <nandan@thinkify.io>
2020-10-26 12:34:23 +00:00
deletePageSuccess,
FetchPageListPayload,
fetchPageSuccess,
fetchPublishedPageSuccess,
savePageSuccess,
setUrlData,
initCanvasLayout,
updateCurrentPage,
updateWidgetNameSuccess,
updateAndSaveLayout,
saveLayout,
2019-11-25 05:07:27 +00:00
} from "actions/pageActions";
import PageApi, {
[API breaking change : Automated Tests Will Fail] Page And Action Refactor (#549) * Introduced new page which stores the published and unpublished pages as separate. * Mid level commit to save the state. * Parity of new page repository with old page repository (custom functions) * WIP : Delete a page. This requires changes across application structure as well. * Added publishedPages construct inside application to store the pages in the deployed view as well as isDefault so that the same changes (delete or isDefault) in unpublished view doesn't alter these fields for the published application * Parity reached with PageService. * Minor ActionService refactor to remove unnecessary code. ApplicationPageService, LayoutActionService, LayoutService use the new page service to fetch the pages Minor corrections in fetching the page from new page service in tests * New save function which sets the PageDTO for unpublished page and then saves the new page into repository. * Migration of page service functions to new page service functions across other services/tests/controller * Finished migrating all the page service functions to the new page service functions * Application Service Tests have been fixed. * All the existing test cases are working now. * Publish application implemented to store published pages as well. Added a basic test case to check that published pages is being set and that page's publishedPageDTO is being set accordingly. * Minor TODOs added to add test cases for published application. * A few tests to ascertain that published application page fields (deleted, isDefault) does not get changed when these statuses are changed for a page in edit mode. * Added a new controller end point to fetch application in view mode. * Added new endpoint for fetching an application in view mode on the client. * Bug fix where get application in view mode API was not getting called. * Fixed the get page names by application & archive pages which have been deleted in edit mode during publishing of application. * During delete page, if a page was never published and it was deleted during edit, delete the entire page instead of just deleting the unpublished PageDTO * Minor formatting. * Non working client side code to fetch page list using view mode. * revert unnecassary changes and streamlined view and edit actions * Fix missed import * Fixed a bug where if a page is not published, it should not be returned in view mode in list of page names api. * Fixed update for a page which was not working in integration test. * ActionDTO added. * Solidified the new action structure. * Migration added for NewAction index creation and NewAction per Action insertion in the database. * Basic file structure added the new repository, custom repository, service, etc. * Delete OldPage.java * Repo functions added - TODO : Haven;t handled the published/edited views * Helper functions added to convert Action to NewAction and vice-versa. Removed unused currentUserMono usage. * Create & update action functionality added. * Execute Action refactored. Removed dry run specific code. * Repository migrated to handle new data structure. Execute action refactored to no longer support dry runs of actions. * TODO added for special handling of change view of application to handle edge cases of pages/actions which either exist in published mode but don't exist in unpublished mode or vice versa. * Migrated finding on load actions from spring repository to custom repository. * In view mode, now actions are being fetched by application id directly instead of first fetching application and then using the page ids, fetching the actions. This reduces the db calls from 2 to 1 per fetch actions in view mode api call. * Delete action and get all actions (used in edit mode on the client side) implemented. * Updated CollectionService and ActionCollectionService to use the new action service instead of the old one. * LayoutActionService refactored to now use the new service functions. * ActionController now no longer used ActionService. The remaining service functions have been migrated to the new action service. * Refactor across ACL code for addition/removal of policies during addition/removal of users to organization, making app public, refactor for services like policy utils, item service, etc. * Removed the last of action repository and action service and replaced with new action repo and new action service. * Compile and run time issues fixed. The server is coming up without any spring dependency errors. * WIP in fixing fetching actions by page id. * Finally!!! Fixed the fetch actions (both published and unpublished actions) by page id repository function. * Fixed create action bug where null datasource in published actiondto (inside newly created action) leads to error. * Fixed the execute action issues : 1. Removed the dry runs from the tests 2. Fixed the null pointer error in variable substituted action and datasource configurations. * 1. Fixed the custom action repository field names. 2. Fixed the data structures used in ExamplesOrganizationClonerTests * Fixed countByDatasourceId repository function which was querying the actions incorrectly. * Fixed the clone example organization error where the id of the action was not getting updated in the page correctly. Yay! * Fixed post merge compilation failure. * Fixed more compilation time failures in ActionServiceTest * Fixed failing test case for fetching actions in view mode. * Minor changes to resolve merge changes and incorporate in the new refactored code. * 1. Fixed compile time errors on Client code. 2. Fixed fetching of actions in view mode by application id. The repository function did not need name parameter. Removed the same. * [Integration Testing Error Fix] : Added a new test case for refactor action name. * Instead of fetching actions in the page, mistakenly used the base service which was fetching all the actions in the repository, barring none which led to the name refactor being blocked even though no action in the current page exists with the new proposed name, * Added delete functionality to action service. * Minor code cleanup * Adding viewMode to action execution * Replacing action with actionId. * 1. Bug fix for deletion of unpublished action. In case of never published action, the entire action should be deleted. In case an action was published, only the unpublished action should be deleted. 2. In case of DB actions (external datasources), only the bare minimum fields should be stored inside the action (datasource id and datasource plugin id). The other fields should not be duplicated across code. * Fixed yarn build compilation issues. * Update app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com> * Changed the API path for GET applications in view mode. Some minor code formatting. * Incorporated review comments. * Some more unnecessary code removed. * Instead of returning Page, now the interface object between client and server for Pages is PageDTO * Migrated Page and Action to PageDTO and ActionDTO Fixed the compilation issues. TODO : Fix the test compilation issues. * Fixed compilation time issues with all the tests by migrating Page and Action to PageDTO and ActionDTO respectively * Action Controller and Page Controller no longer extend Base Controller. All the required functions have now been implemented and no base line API end points are being re-used from the base. * Test case fixes. * Bug Fix : Updating an action was not updating execute on load. Fixed the data flow leading to the error. * Deprecating Page and Action domain objects. This is to ensure no new code is written with these till we remove this old code. * Cloned example applications are now published before returning. This is to ensure that the applications are in ready to view mode when the new user signs up. * Added a function comment to expand on the usage of new param introduced. * When cloning a page, new actions were not being stored. Added that. Also updated the clonePage test to assert that the actions are also cloned when the pages are cloned. * Updated a Api call * removed extra slash Co-authored-by: Hetu Nandu <hetunandu@gmail.com> Co-authored-by: Satbir Singh <satbir121@gmail.com> Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com> Co-authored-by: nandan.anantharamu <nandan@thinkify.io>
2020-10-26 12:34:23 +00:00
ClonePageRequest,
CreatePageRequest,
DeletePageRequest,
FetchPageListResponse,
FetchPageRequest,
FetchPageResponse,
FetchPublishedPageRequest,
FetchPublishedPageResponse,
PageLayout,
SavePageResponse,
2020-01-27 08:24:58 +00:00
UpdatePageRequest,
2020-02-21 12:16:49 +00:00
UpdateWidgetNameRequest,
UpdateWidgetNameResponse,
2019-11-25 05:07:27 +00:00
} from "api/PageApi";
import { FlattenedWidgetProps } from "reducers/entityReducers/canvasWidgetsReducer";
import {
all,
call,
debounce,
put,
select,
takeLatest,
takeLeading,
} from "redux-saga/effects";
import history from "utils/history";
import { BUILDER_PAGE_URL } from "constants/routes";
import { isNameValid } from "utils/helpers";
import {
checkIfMigrationIsNeeded,
extractCurrentDSL,
} from "utils/WidgetPropsUtils";
import {
getAllPageIds,
getEditorConfigs,
getExistingPageNames,
getWidgets,
} from "./selectors";
import { getDataTree } from "selectors/dataTreeSelectors";
import { IncorrectBindingError, validateResponse } from "./ErrorSagas";
import { executePageLoadActions } from "actions/widgetActions";
2020-01-27 08:24:58 +00:00
import { ApiResponse } from "api/ApiResponses";
2020-02-21 12:16:49 +00:00
import {
getCurrentApplicationId,
getCurrentLayoutId,
getCurrentPageId,
2020-02-21 12:16:49 +00:00
getCurrentPageName,
} from "selectors/editorSelectors";
import {
fetchActionsForPage,
setActionsToExecuteOnPageLoad,
} from "actions/actionActions";
[API breaking change : Automated Tests Will Fail] Page And Action Refactor (#549) * Introduced new page which stores the published and unpublished pages as separate. * Mid level commit to save the state. * Parity of new page repository with old page repository (custom functions) * WIP : Delete a page. This requires changes across application structure as well. * Added publishedPages construct inside application to store the pages in the deployed view as well as isDefault so that the same changes (delete or isDefault) in unpublished view doesn't alter these fields for the published application * Parity reached with PageService. * Minor ActionService refactor to remove unnecessary code. ApplicationPageService, LayoutActionService, LayoutService use the new page service to fetch the pages Minor corrections in fetching the page from new page service in tests * New save function which sets the PageDTO for unpublished page and then saves the new page into repository. * Migration of page service functions to new page service functions across other services/tests/controller * Finished migrating all the page service functions to the new page service functions * Application Service Tests have been fixed. * All the existing test cases are working now. * Publish application implemented to store published pages as well. Added a basic test case to check that published pages is being set and that page's publishedPageDTO is being set accordingly. * Minor TODOs added to add test cases for published application. * A few tests to ascertain that published application page fields (deleted, isDefault) does not get changed when these statuses are changed for a page in edit mode. * Added a new controller end point to fetch application in view mode. * Added new endpoint for fetching an application in view mode on the client. * Bug fix where get application in view mode API was not getting called. * Fixed the get page names by application & archive pages which have been deleted in edit mode during publishing of application. * During delete page, if a page was never published and it was deleted during edit, delete the entire page instead of just deleting the unpublished PageDTO * Minor formatting. * Non working client side code to fetch page list using view mode. * revert unnecassary changes and streamlined view and edit actions * Fix missed import * Fixed a bug where if a page is not published, it should not be returned in view mode in list of page names api. * Fixed update for a page which was not working in integration test. * ActionDTO added. * Solidified the new action structure. * Migration added for NewAction index creation and NewAction per Action insertion in the database. * Basic file structure added the new repository, custom repository, service, etc. * Delete OldPage.java * Repo functions added - TODO : Haven;t handled the published/edited views * Helper functions added to convert Action to NewAction and vice-versa. Removed unused currentUserMono usage. * Create & update action functionality added. * Execute Action refactored. Removed dry run specific code. * Repository migrated to handle new data structure. Execute action refactored to no longer support dry runs of actions. * TODO added for special handling of change view of application to handle edge cases of pages/actions which either exist in published mode but don't exist in unpublished mode or vice versa. * Migrated finding on load actions from spring repository to custom repository. * In view mode, now actions are being fetched by application id directly instead of first fetching application and then using the page ids, fetching the actions. This reduces the db calls from 2 to 1 per fetch actions in view mode api call. * Delete action and get all actions (used in edit mode on the client side) implemented. * Updated CollectionService and ActionCollectionService to use the new action service instead of the old one. * LayoutActionService refactored to now use the new service functions. * ActionController now no longer used ActionService. The remaining service functions have been migrated to the new action service. * Refactor across ACL code for addition/removal of policies during addition/removal of users to organization, making app public, refactor for services like policy utils, item service, etc. * Removed the last of action repository and action service and replaced with new action repo and new action service. * Compile and run time issues fixed. The server is coming up without any spring dependency errors. * WIP in fixing fetching actions by page id. * Finally!!! Fixed the fetch actions (both published and unpublished actions) by page id repository function. * Fixed create action bug where null datasource in published actiondto (inside newly created action) leads to error. * Fixed the execute action issues : 1. Removed the dry runs from the tests 2. Fixed the null pointer error in variable substituted action and datasource configurations. * 1. Fixed the custom action repository field names. 2. Fixed the data structures used in ExamplesOrganizationClonerTests * Fixed countByDatasourceId repository function which was querying the actions incorrectly. * Fixed the clone example organization error where the id of the action was not getting updated in the page correctly. Yay! * Fixed post merge compilation failure. * Fixed more compilation time failures in ActionServiceTest * Fixed failing test case for fetching actions in view mode. * Minor changes to resolve merge changes and incorporate in the new refactored code. * 1. Fixed compile time errors on Client code. 2. Fixed fetching of actions in view mode by application id. The repository function did not need name parameter. Removed the same. * [Integration Testing Error Fix] : Added a new test case for refactor action name. * Instead of fetching actions in the page, mistakenly used the base service which was fetching all the actions in the repository, barring none which led to the name refactor being blocked even though no action in the current page exists with the new proposed name, * Added delete functionality to action service. * Minor code cleanup * Adding viewMode to action execution * Replacing action with actionId. * 1. Bug fix for deletion of unpublished action. In case of never published action, the entire action should be deleted. In case an action was published, only the unpublished action should be deleted. 2. In case of DB actions (external datasources), only the bare minimum fields should be stored inside the action (datasource id and datasource plugin id). The other fields should not be duplicated across code. * Fixed yarn build compilation issues. * Update app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com> * Changed the API path for GET applications in view mode. Some minor code formatting. * Incorporated review comments. * Some more unnecessary code removed. * Instead of returning Page, now the interface object between client and server for Pages is PageDTO * Migrated Page and Action to PageDTO and ActionDTO Fixed the compilation issues. TODO : Fix the test compilation issues. * Fixed compilation time issues with all the tests by migrating Page and Action to PageDTO and ActionDTO respectively * Action Controller and Page Controller no longer extend Base Controller. All the required functions have now been implemented and no base line API end points are being re-used from the base. * Test case fixes. * Bug Fix : Updating an action was not updating execute on load. Fixed the data flow leading to the error. * Deprecating Page and Action domain objects. This is to ensure no new code is written with these till we remove this old code. * Cloned example applications are now published before returning. This is to ensure that the applications are in ready to view mode when the new user signs up. * Added a function comment to expand on the usage of new param introduced. * When cloning a page, new actions were not being stored. Added that. Also updated the clonePage test to assert that the actions are also cloned when the pages are cloned. * Updated a Api call * removed extra slash Co-authored-by: Hetu Nandu <hetunandu@gmail.com> Co-authored-by: Satbir Singh <satbir121@gmail.com> Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com> Co-authored-by: nandan.anantharamu <nandan@thinkify.io>
2020-10-26 12:34:23 +00:00
import { APP_MODE, UrlDataState } from "reducers/entityReducers/appReducer";
import { clearEvalCache } from "./EvaluationsSaga";
import { getQueryParams } from "utils/AppsmithUtils";
import PerformanceTracker, {
PerformanceTransactionName,
} from "utils/PerformanceTracker";
import log from "loglevel";
import { WidgetTypes } from "constants/WidgetConstants";
import { Toaster } from "components/ads/Toast";
import { Variant } from "components/ads/common";
import { migrateIncorrectDynamicBindingPathLists } from "utils/migrations/IncorrectDynamicBindingPathLists";
import * as Sentry from "@sentry/react";
import { ERROR_CODES } from "constants/ApiConstants";
import AnalyticsUtil from "utils/AnalyticsUtil";
import DEFAULT_TEMPLATE from "templates/default";
2020-02-21 12:16:49 +00:00
const getWidgetName = (state: AppState, widgetId: string) =>
state.entities.canvasWidgets[widgetId];
export function* fetchPageListSaga(
fetchPageListAction: ReduxAction<FetchPageListPayload>,
) {
PerformanceTracker.startAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_LIST_API,
);
try {
[API breaking change : Automated Tests Will Fail] Page And Action Refactor (#549) * Introduced new page which stores the published and unpublished pages as separate. * Mid level commit to save the state. * Parity of new page repository with old page repository (custom functions) * WIP : Delete a page. This requires changes across application structure as well. * Added publishedPages construct inside application to store the pages in the deployed view as well as isDefault so that the same changes (delete or isDefault) in unpublished view doesn't alter these fields for the published application * Parity reached with PageService. * Minor ActionService refactor to remove unnecessary code. ApplicationPageService, LayoutActionService, LayoutService use the new page service to fetch the pages Minor corrections in fetching the page from new page service in tests * New save function which sets the PageDTO for unpublished page and then saves the new page into repository. * Migration of page service functions to new page service functions across other services/tests/controller * Finished migrating all the page service functions to the new page service functions * Application Service Tests have been fixed. * All the existing test cases are working now. * Publish application implemented to store published pages as well. Added a basic test case to check that published pages is being set and that page's publishedPageDTO is being set accordingly. * Minor TODOs added to add test cases for published application. * A few tests to ascertain that published application page fields (deleted, isDefault) does not get changed when these statuses are changed for a page in edit mode. * Added a new controller end point to fetch application in view mode. * Added new endpoint for fetching an application in view mode on the client. * Bug fix where get application in view mode API was not getting called. * Fixed the get page names by application & archive pages which have been deleted in edit mode during publishing of application. * During delete page, if a page was never published and it was deleted during edit, delete the entire page instead of just deleting the unpublished PageDTO * Minor formatting. * Non working client side code to fetch page list using view mode. * revert unnecassary changes and streamlined view and edit actions * Fix missed import * Fixed a bug where if a page is not published, it should not be returned in view mode in list of page names api. * Fixed update for a page which was not working in integration test. * ActionDTO added. * Solidified the new action structure. * Migration added for NewAction index creation and NewAction per Action insertion in the database. * Basic file structure added the new repository, custom repository, service, etc. * Delete OldPage.java * Repo functions added - TODO : Haven;t handled the published/edited views * Helper functions added to convert Action to NewAction and vice-versa. Removed unused currentUserMono usage. * Create & update action functionality added. * Execute Action refactored. Removed dry run specific code. * Repository migrated to handle new data structure. Execute action refactored to no longer support dry runs of actions. * TODO added for special handling of change view of application to handle edge cases of pages/actions which either exist in published mode but don't exist in unpublished mode or vice versa. * Migrated finding on load actions from spring repository to custom repository. * In view mode, now actions are being fetched by application id directly instead of first fetching application and then using the page ids, fetching the actions. This reduces the db calls from 2 to 1 per fetch actions in view mode api call. * Delete action and get all actions (used in edit mode on the client side) implemented. * Updated CollectionService and ActionCollectionService to use the new action service instead of the old one. * LayoutActionService refactored to now use the new service functions. * ActionController now no longer used ActionService. The remaining service functions have been migrated to the new action service. * Refactor across ACL code for addition/removal of policies during addition/removal of users to organization, making app public, refactor for services like policy utils, item service, etc. * Removed the last of action repository and action service and replaced with new action repo and new action service. * Compile and run time issues fixed. The server is coming up without any spring dependency errors. * WIP in fixing fetching actions by page id. * Finally!!! Fixed the fetch actions (both published and unpublished actions) by page id repository function. * Fixed create action bug where null datasource in published actiondto (inside newly created action) leads to error. * Fixed the execute action issues : 1. Removed the dry runs from the tests 2. Fixed the null pointer error in variable substituted action and datasource configurations. * 1. Fixed the custom action repository field names. 2. Fixed the data structures used in ExamplesOrganizationClonerTests * Fixed countByDatasourceId repository function which was querying the actions incorrectly. * Fixed the clone example organization error where the id of the action was not getting updated in the page correctly. Yay! * Fixed post merge compilation failure. * Fixed more compilation time failures in ActionServiceTest * Fixed failing test case for fetching actions in view mode. * Minor changes to resolve merge changes and incorporate in the new refactored code. * 1. Fixed compile time errors on Client code. 2. Fixed fetching of actions in view mode by application id. The repository function did not need name parameter. Removed the same. * [Integration Testing Error Fix] : Added a new test case for refactor action name. * Instead of fetching actions in the page, mistakenly used the base service which was fetching all the actions in the repository, barring none which led to the name refactor being blocked even though no action in the current page exists with the new proposed name, * Added delete functionality to action service. * Minor code cleanup * Adding viewMode to action execution * Replacing action with actionId. * 1. Bug fix for deletion of unpublished action. In case of never published action, the entire action should be deleted. In case an action was published, only the unpublished action should be deleted. 2. In case of DB actions (external datasources), only the bare minimum fields should be stored inside the action (datasource id and datasource plugin id). The other fields should not be duplicated across code. * Fixed yarn build compilation issues. * Update app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com> * Changed the API path for GET applications in view mode. Some minor code formatting. * Incorporated review comments. * Some more unnecessary code removed. * Instead of returning Page, now the interface object between client and server for Pages is PageDTO * Migrated Page and Action to PageDTO and ActionDTO Fixed the compilation issues. TODO : Fix the test compilation issues. * Fixed compilation time issues with all the tests by migrating Page and Action to PageDTO and ActionDTO respectively * Action Controller and Page Controller no longer extend Base Controller. All the required functions have now been implemented and no base line API end points are being re-used from the base. * Test case fixes. * Bug Fix : Updating an action was not updating execute on load. Fixed the data flow leading to the error. * Deprecating Page and Action domain objects. This is to ensure no new code is written with these till we remove this old code. * Cloned example applications are now published before returning. This is to ensure that the applications are in ready to view mode when the new user signs up. * Added a function comment to expand on the usage of new param introduced. * When cloning a page, new actions were not being stored. Added that. Also updated the clonePage test to assert that the actions are also cloned when the pages are cloned. * Updated a Api call * removed extra slash Co-authored-by: Hetu Nandu <hetunandu@gmail.com> Co-authored-by: Satbir Singh <satbir121@gmail.com> Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com> Co-authored-by: nandan.anantharamu <nandan@thinkify.io>
2020-10-26 12:34:23 +00:00
const { applicationId, mode } = fetchPageListAction.payload;
const apiCall =
mode === APP_MODE.EDIT
? PageApi.fetchPageList
: PageApi.fetchPageListViewMode;
const response: FetchPageListResponse = yield call(apiCall, applicationId);
const isValidResponse = yield validateResponse(response);
if (isValidResponse) {
const orgId = response.data.organizationId;
2020-12-24 04:32:25 +00:00
const pages: PageListPayload = response.data.pages.map((page) => ({
pageName: page.name,
pageId: page.id,
2020-01-27 08:24:58 +00:00
isDefault: page.isDefault,
2021-02-24 13:47:37 +00:00
isHidden: !!page.isHidden,
}));
yield put({
type: ReduxActionTypes.SET_CURRENT_ORG_ID,
payload: {
orgId,
},
});
yield put({
type: ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS,
payload: {
pages,
applicationId,
},
});
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_LIST_API,
);
} else {
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_LIST_API,
);
yield put({
type: ReduxActionErrorTypes.FETCH_PAGE_LIST_ERROR,
payload: {
error: response.responseMeta.error,
},
});
}
} catch (error) {
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_LIST_API,
{ failed: true },
);
yield put({
type: ReduxActionErrorTypes.FETCH_PAGE_LIST_ERROR,
payload: {
error,
},
});
}
}
2019-11-08 11:02:00 +00:00
export const getCanvasWidgetsPayload = (
pageResponse: FetchPageResponse,
): UpdateCanvasPayload => {
const normalizedResponse = CanvasWidgetsNormalizer.normalize(
extractCurrentDSL(pageResponse),
);
return {
pageWidgetId: normalizedResponse.result,
currentPageName: pageResponse.data.name,
currentPageId: pageResponse.data.id,
widgets: normalizedResponse.entities.canvasWidgets,
currentLayoutId: pageResponse.data.layouts[0].id, // TODO(abhinav): Handle for multiple layouts
currentApplicationId: pageResponse.data.applicationId,
pageActions: pageResponse.data.layouts[0].layoutOnLoadActions || [],
};
};
export function* fetchPageSaga(
pageRequestAction: ReduxAction<FetchPageRequest>,
) {
2019-08-26 12:41:21 +00:00
try {
const { id } = pageRequestAction.payload;
PerformanceTracker.startAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_API,
{ pageId: id },
);
2020-02-13 09:32:24 +00:00
const fetchPageResponse: FetchPageResponse = yield call(PageApi.fetchPage, {
id,
2020-02-13 09:32:24 +00:00
});
2019-09-27 16:05:33 +00:00
const isValidResponse = yield validateResponse(fetchPageResponse);
const willPageBeMigrated = checkIfMigrationIsNeeded(fetchPageResponse);
[Feature] Grid Widget (#2389) * Updated test * updated assertions * Resizing image to take full width of table cell * updated assertion * Stop updating dynamicBindingPathList directly from widget * Fix selectedRow and selectedRows computations * Fix primaryColumns computations * Updated test for derived column * Added tests for computed value * Added check clear data * Reordering of test * updated common method * Made image size as 100% of table cell size * add templating logic * Updated flow and dsl * Clear old primary columns * Updated testname * updated assertion * use evaluated values for children * Fix primary columns update on component mount and component update * add isArray check * remove property pane enhancement reducer * add property pane enhancement reducer * disable items other than template + fix running property enchancment on drop of list widget * disbled drag, resize, settingsControl, drag for items other than template * add grid options * uncomment the widget operation for add child for grid children * handle delete scenario for child widget in list widget * WIP: Use the new delete and update property features * add listdsl.json for testcases * add test cases for correct no. of items being rendered * add test cases currentItem binding in list widget * change dragEnabled to dragDisabled * change resizeEnabled to resizeDisabled * change settingsControlEnabled to settingsControlDisabled * change dropEnabled to dropDisabled * update settingsControlDisabled default value * Use deleteProperties in propertyControls * Fix unsetting of array indices when deleting widget properties * remove old TableWidget.tsx file * Fix derived column property update on primary column property update * Handle undefined primary columns * Fix filepicker immutable prop issue * Fix object.freeze issue when adding ids to the property pane configuration * fix widget issue in grid * Fix column actions dynamicBindingPathList inclusion issue * remove consoles + fix typo around batch update * Remove redundant tests * js binding test for date picker * hydate enhancement map on copy list widget * check for dynamicleaf * fixes * improve check * fix getNextWidgetName * update template in list widget when copying * updating template copy logic when copying widget * update dynamicBindingPathList in copied widget * Add path parameter to hidden functions in property pane configs * fix copy bug when copying list widget * add computed list property control * Remove time column type Fix editor prompt for currentRow Fix undefined derivedColumns scenario Remove validations for primaryColums and derivedColumns Fix section toggle for video, image and button column types * Fix table widget actions and custom column migrations * Add logs for cyclical dependency map :recycle: * Process array differences * add property control for list widget * Fix onClick migrations * Property pane config parity * binding and trigger paths from the property pane config (#2920) * try react virtualized library * Fix unit test * Fix unit test :white_check_mark: * Fix minor issues in table widget * Add default meta props to binding paths to ensure eval and validation * Dummy commit :tada: * Remove unnecessary datepicker test Fix chart data as string issue * Achieve table column sorting and resizing parity with release * handle scenario where last column isn't available to access * Fix for panel config path not existing in the widget * Fix bindings in currentRow (default) Add dummy property pane config for canvas widget * Update canvas widgets with dynamicPathLists on delete of property paths * Add all diffs to change paths and trim later * Add back default properties 🚶🏻‍♂️ * Use object based paths instead of arrays for primaryColumns and derivedColumns * Fix issue in reordered columns * Fix inccorect update order * add virtualized list * Fix failing property pane tests * minor change * minor list widget change * Remove .vscode from git * Rename ads to alloy Fix isVisible in list widget * move grid component to widget folder * fix import in widget registry * add sticky row in virtualized list * add sticky container * Fix Height of grid widget items container * fix dragging of items in children other than template children * update list widget * update list widget * Fix padding in list widget * hide scrollbar in list widget list * fix copy bug in list widget * regenrate enhancement map on undo delete widget * Use enhancementmap for autocomplete in list widget Basic styles for list widget scrollbar * add custom control in widget config * minor commit * update scrollbar styles * remove unused variable * fix typo in custom control * comment out test cases * remove unused imports * remove unused imports * add JSON stringify in interweave * add noPad styling in dragLayer for noPad prop * implement grid gap * add list item background color prop * add white color in color picker control * fix gap in last list item * remove onBeforeParse in textcomponent * remove virtualization in grid widget * allow overflow-y * add onListItemClick action * add beta label * add pagination * fix actions in pagination in list widget * add list widget icon * add list background color default value * remove extra div * fix pagination issue * fix list widget crashing on perpage change * extract child operation function to widgetblueprint saga * refactor enhancements * add enhancement hook * refactor propertyUpdate hook enhancment * remove enhacement map * revert renaming ads to alloy * add autopagination * Cleanup unused vars Re-write loop using map Fix binding with external input widget * update default background color * remove unnessary scrol + fix pagination per page * remove console.log * use grid gap in pixel instead of snap * fix list widget tests for binding * add tests for on click action and pagination * remove unnecessary imports * remove overflow hidden in list component * Add feature to enable template actions * update property pane help text for list widget * disable pagination in editor view * update property pane options * add test case for action * uncomment tests * fix grid gap validation * update test cases * fix property pane opening issue for list tempalte * Disable form widgets in list widget * fix template issue for actions * add validation tests for list data * update starting template * add selectedRow + enable pagination in edit mode * remove extra padding in list widget + popper fix on settingDisabled * add stop propagation for button click * fix click event in edit mode * disallow filepicker widget for list widget * add test for list widget entity definition for selectItem * remove unused imports * fix test * remove evaluated value for list child widgets * add comment * remove log * fix copying bug in list widget * add check for not allowing template to copy * fix test * add test for property pane actions * remove unused import * add draglayercomponent test * add test for draggable component * add test for evaluatedvalue popup * add test for messages.ts * add test for widgeticons * add test for property pane selector * add test for widget config response * start testing widget configresponse * add test for enhancements in widget config * add test for codeeditor * add test for base widget + list widget * add test for executeWidgetBlueprintChildOperations * remove unused import * add test for widget operation utils * remove unused import * add test for handleSpecificCasesWhilePasting * remove unused function * remove unused import * add empty list styling * resolve all review comments * fix message test * add test for widget operation utils * fix merge conflicts * move validations in property config Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: nandan.anantharamu <nandan.anantharamu@thoughtspot.com> Co-authored-by: vicky-primathon.in <vicky.bansal@primathon.in> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Piyush <piyush@codeitout.com> Co-authored-by: hetunandu <hetu@appsmith.com> Co-authored-by: Hetu Nandu <hetunandu@gmail.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain>
2021-04-23 05:43:13 +00:00
2019-09-27 16:05:33 +00:00
if (isValidResponse) {
2020-04-17 16:15:09 +00:00
// Clear any existing caches
yield call(clearEvalCache);
// Set url params
yield call(setDataUrl);
// Get Canvas payload
const canvasWidgetsPayload = getCanvasWidgetsPayload(fetchPageResponse);
// Update the canvas
yield put(initCanvasLayout(canvasWidgetsPayload));
// set current page
yield put(updateCurrentPage(id));
// dispatch fetch page success
yield put(fetchPageSuccess());
const extractedDSL = extractCurrentDSL(fetchPageResponse);
yield put({
type: ReduxActionTypes.UPDATE_CANVAS_STRUCTURE,
payload: extractedDSL,
});
if (willPageBeMigrated) {
yield put(saveLayout());
}
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_API,
);
}
} catch (error) {
log.error(error);
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_API,
{
failed: true,
},
);
2019-09-27 16:05:33 +00:00
yield put({
type: ReduxActionErrorTypes.FETCH_PAGE_ERROR,
payload: {
error,
},
});
}
}
export function* fetchPublishedPageSaga(
2020-05-05 12:16:51 +00:00
pageRequestAction: ReduxAction<{ pageId: string; bustCache: boolean }>,
) {
try {
const { bustCache, pageId } = pageRequestAction.payload;
PerformanceTracker.startAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_API,
[Feature] Grid Widget (#2389) * Updated test * updated assertions * Resizing image to take full width of table cell * updated assertion * Stop updating dynamicBindingPathList directly from widget * Fix selectedRow and selectedRows computations * Fix primaryColumns computations * Updated test for derived column * Added tests for computed value * Added check clear data * Reordering of test * updated common method * Made image size as 100% of table cell size * add templating logic * Updated flow and dsl * Clear old primary columns * Updated testname * updated assertion * use evaluated values for children * Fix primary columns update on component mount and component update * add isArray check * remove property pane enhancement reducer * add property pane enhancement reducer * disable items other than template + fix running property enchancment on drop of list widget * disbled drag, resize, settingsControl, drag for items other than template * add grid options * uncomment the widget operation for add child for grid children * handle delete scenario for child widget in list widget * WIP: Use the new delete and update property features * add listdsl.json for testcases * add test cases for correct no. of items being rendered * add test cases currentItem binding in list widget * change dragEnabled to dragDisabled * change resizeEnabled to resizeDisabled * change settingsControlEnabled to settingsControlDisabled * change dropEnabled to dropDisabled * update settingsControlDisabled default value * Use deleteProperties in propertyControls * Fix unsetting of array indices when deleting widget properties * remove old TableWidget.tsx file * Fix derived column property update on primary column property update * Handle undefined primary columns * Fix filepicker immutable prop issue * Fix object.freeze issue when adding ids to the property pane configuration * fix widget issue in grid * Fix column actions dynamicBindingPathList inclusion issue * remove consoles + fix typo around batch update * Remove redundant tests * js binding test for date picker * hydate enhancement map on copy list widget * check for dynamicleaf * fixes * improve check * fix getNextWidgetName * update template in list widget when copying * updating template copy logic when copying widget * update dynamicBindingPathList in copied widget * Add path parameter to hidden functions in property pane configs * fix copy bug when copying list widget * add computed list property control * Remove time column type Fix editor prompt for currentRow Fix undefined derivedColumns scenario Remove validations for primaryColums and derivedColumns Fix section toggle for video, image and button column types * Fix table widget actions and custom column migrations * Add logs for cyclical dependency map :recycle: * Process array differences * add property control for list widget * Fix onClick migrations * Property pane config parity * binding and trigger paths from the property pane config (#2920) * try react virtualized library * Fix unit test * Fix unit test :white_check_mark: * Fix minor issues in table widget * Add default meta props to binding paths to ensure eval and validation * Dummy commit :tada: * Remove unnecessary datepicker test Fix chart data as string issue * Achieve table column sorting and resizing parity with release * handle scenario where last column isn't available to access * Fix for panel config path not existing in the widget * Fix bindings in currentRow (default) Add dummy property pane config for canvas widget * Update canvas widgets with dynamicPathLists on delete of property paths * Add all diffs to change paths and trim later * Add back default properties 🚶🏻‍♂️ * Use object based paths instead of arrays for primaryColumns and derivedColumns * Fix issue in reordered columns * Fix inccorect update order * add virtualized list * Fix failing property pane tests * minor change * minor list widget change * Remove .vscode from git * Rename ads to alloy Fix isVisible in list widget * move grid component to widget folder * fix import in widget registry * add sticky row in virtualized list * add sticky container * Fix Height of grid widget items container * fix dragging of items in children other than template children * update list widget * update list widget * Fix padding in list widget * hide scrollbar in list widget list * fix copy bug in list widget * regenrate enhancement map on undo delete widget * Use enhancementmap for autocomplete in list widget Basic styles for list widget scrollbar * add custom control in widget config * minor commit * update scrollbar styles * remove unused variable * fix typo in custom control * comment out test cases * remove unused imports * remove unused imports * add JSON stringify in interweave * add noPad styling in dragLayer for noPad prop * implement grid gap * add list item background color prop * add white color in color picker control * fix gap in last list item * remove onBeforeParse in textcomponent * remove virtualization in grid widget * allow overflow-y * add onListItemClick action * add beta label * add pagination * fix actions in pagination in list widget * add list widget icon * add list background color default value * remove extra div * fix pagination issue * fix list widget crashing on perpage change * extract child operation function to widgetblueprint saga * refactor enhancements * add enhancement hook * refactor propertyUpdate hook enhancment * remove enhacement map * revert renaming ads to alloy * add autopagination * Cleanup unused vars Re-write loop using map Fix binding with external input widget * update default background color * remove unnessary scrol + fix pagination per page * remove console.log * use grid gap in pixel instead of snap * fix list widget tests for binding * add tests for on click action and pagination * remove unnecessary imports * remove overflow hidden in list component * Add feature to enable template actions * update property pane help text for list widget * disable pagination in editor view * update property pane options * add test case for action * uncomment tests * fix grid gap validation * update test cases * fix property pane opening issue for list tempalte * Disable form widgets in list widget * fix template issue for actions * add validation tests for list data * update starting template * add selectedRow + enable pagination in edit mode * remove extra padding in list widget + popper fix on settingDisabled * add stop propagation for button click * fix click event in edit mode * disallow filepicker widget for list widget * add test for list widget entity definition for selectItem * remove unused imports * fix test * remove evaluated value for list child widgets * add comment * remove log * fix copying bug in list widget * add check for not allowing template to copy * fix test * add test for property pane actions * remove unused import * add draglayercomponent test * add test for draggable component * add test for evaluatedvalue popup * add test for messages.ts * add test for widgeticons * add test for property pane selector * add test for widget config response * start testing widget configresponse * add test for enhancements in widget config * add test for codeeditor * add test for base widget + list widget * add test for executeWidgetBlueprintChildOperations * remove unused import * add test for widget operation utils * remove unused import * add test for handleSpecificCasesWhilePasting * remove unused function * remove unused import * add empty list styling * resolve all review comments * fix message test * add test for widget operation utils * fix merge conflicts * move validations in property config Co-authored-by: Abhinav Jha <abhinav@appsmith.com> Co-authored-by: nandan.anantharamu <nandan.anantharamu@thoughtspot.com> Co-authored-by: vicky-primathon.in <vicky.bansal@primathon.in> Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro.local> Co-authored-by: Piyush <piyush@codeitout.com> Co-authored-by: hetunandu <hetu@appsmith.com> Co-authored-by: Hetu Nandu <hetunandu@gmail.com> Co-authored-by: root <root@DESKTOP-9GENCK0.localdomain>
2021-04-23 05:43:13 +00:00
{
pageId: pageId,
published: true,
},
);
const request: FetchPublishedPageRequest = {
pageId,
2020-05-05 12:16:51 +00:00
bustCache,
};
2019-10-24 09:23:50 +00:00
const response: FetchPublishedPageResponse = yield call(
PageApi.fetchPublishedPage,
2019-10-24 09:23:50 +00:00
request,
);
2019-10-24 09:23:50 +00:00
const isValidResponse = yield validateResponse(response);
if (isValidResponse) {
2020-04-17 16:15:09 +00:00
// Clear any existing caches
yield call(clearEvalCache);
// Set url params
yield call(setDataUrl);
// Get Canvas payload
const canvasWidgetsPayload = getCanvasWidgetsPayload(response);
// Update the canvas
yield put(initCanvasLayout(canvasWidgetsPayload));
// set current page
yield put(updateCurrentPage(pageId));
// dispatch fetch page success
yield put(
fetchPublishedPageSuccess(
// Execute page load actions post published page eval
[executePageLoadActions()],
),
);
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_API,
);
}
} catch (error) {
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.FETCH_PAGE_API,
{
failed: true,
},
);
yield put({
type: ReduxActionErrorTypes.FETCH_PUBLISHED_PAGE_ERROR,
payload: {
error,
},
});
}
}
2020-05-05 12:16:51 +00:00
export function* fetchAllPublishedPagesSaga() {
try {
const pageIds = yield select(getAllPageIds);
yield all(
pageIds.map((pageId: string) => {
return call(PageApi.fetchPublishedPage, { pageId });
}),
);
} catch (error) {
log.error({ error });
2020-05-05 12:16:51 +00:00
}
}
function* savePageSaga(action: ReduxAction<{ isRetry?: boolean }>) {
2020-04-13 14:00:50 +00:00
const widgets = yield select(getWidgets);
const editorConfigs = yield select(getEditorConfigs) as any;
const savePageRequest = getLayoutSavePayload(widgets, editorConfigs);
PerformanceTracker.startAsyncTracking(
PerformanceTransactionName.SAVE_PAGE_API,
{
pageId: savePageRequest.pageId,
},
);
try {
// Store the updated DSL in the pageDSLs reducer
yield put({
type: ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS,
payload: {
pageId: savePageRequest.pageId,
dsl: savePageRequest.dsl,
},
});
yield put({
type: ReduxActionTypes.UPDATE_CANVAS_STRUCTURE,
payload: savePageRequest.dsl,
});
const savePageResponse: SavePageResponse = yield call(
PageApi.savePage,
savePageRequest,
);
const isValidResponse = yield validateResponse(savePageResponse);
2019-09-27 16:05:33 +00:00
if (isValidResponse) {
const { actionUpdates, messages } = savePageResponse.data;
// Show toast messages from the server
if (messages && messages.length) {
savePageResponse.data.messages.forEach((message) => {
Toaster.show({
text: message,
type: Variant.info,
});
});
}
// Update actions
if (actionUpdates && actionUpdates.length > 0) {
yield put(setActionsToExecuteOnPageLoad(actionUpdates));
}
2019-09-27 16:05:33 +00:00
yield put(savePageSuccess(savePageResponse));
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.SAVE_PAGE_API,
);
2019-09-27 16:05:33 +00:00
}
} catch (error) {
PerformanceTracker.stopAsyncTracking(
PerformanceTransactionName.SAVE_PAGE_API,
{
failed: true,
},
);
2019-09-27 16:05:33 +00:00
yield put({
type: ReduxActionErrorTypes.SAVE_PAGE_ERROR,
payload: {
error,
show: false,
2019-09-27 16:05:33 +00:00
},
});
if (error instanceof IncorrectBindingError) {
const { isRetry } = action.payload;
const incorrectBindingError = JSON.parse(error.message);
const { message } = incorrectBindingError;
if (isRetry) {
Sentry.captureException(new Error("Failed to correct binding paths"));
yield put({
type: ReduxActionErrorTypes.FAILED_CORRECTING_BINDING_PATHS,
payload: {
error: {
message,
code: ERROR_CODES.FAILED_TO_CORRECT_BINDING,
crash: true,
},
},
});
} else {
// Create a denormalized structure because the migration needs the children in the dsl form
const denormalizedWidgets = CanvasWidgetsNormalizer.denormalize("0", {
canvasWidgets: widgets,
});
const correctedWidgets = migrateIncorrectDynamicBindingPathLists(
denormalizedWidgets,
);
// Normalize the widgets because the save page needs it in the flat structure
const normalizedWidgets = CanvasWidgetsNormalizer.normalize(
correctedWidgets,
);
AnalyticsUtil.logEvent("CORRECT_BAD_BINDING", {
2021-03-16 05:31:48 +00:00
error: error.message,
correctWidget: JSON.stringify(normalizedWidgets),
});
yield put(
updateAndSaveLayout(normalizedWidgets.entities.canvasWidgets, true),
);
}
}
}
}
function getLayoutSavePayload(
widgets: {
[widgetId: string]: FlattenedWidgetProps;
},
editorConfigs: any,
) {
const denormalizedDSL = CanvasWidgetsNormalizer.denormalize(
Object.keys(widgets)[0],
{ canvasWidgets: widgets },
);
return {
...editorConfigs,
dsl: denormalizedDSL,
};
}
export function* saveLayoutSaga(action: ReduxAction<{ isRetry?: boolean }>) {
try {
yield put({
type: ReduxActionTypes.SAVE_PAGE_INIT,
payload: action.payload,
});
} catch (error) {
yield put({
type: ReduxActionErrorTypes.SAVE_PAGE_ERROR,
payload: {
error,
},
});
}
}
export function* createPageSaga(
createPageAction: ReduxAction<CreatePageRequest>,
) {
try {
const request: CreatePageRequest = createPageAction.payload;
const response: FetchPageResponse = yield call(PageApi.createPage, request);
const isValidResponse = yield validateResponse(response);
if (isValidResponse) {
yield put({
type: ReduxActionTypes.CREATE_PAGE_SUCCESS,
payload: {
pageId: response.data.id,
pageName: response.data.name,
layoutId: response.data.layouts[0].id,
},
});
// Add this to the page DSLs for entity explorer
yield put({
type: ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS,
payload: {
pageId: response.data.id,
dsl: extractCurrentDSL(response),
},
});
history.push(
BUILDER_PAGE_URL(
createPageAction.payload.applicationId,
response.data.id,
),
);
}
} catch (error) {
yield put({
type: ReduxActionErrorTypes.CREATE_PAGE_ERROR,
payload: {
error,
},
});
}
}
2020-01-27 08:24:58 +00:00
export function* updatePageSaga(action: ReduxAction<UpdatePageRequest>) {
try {
const request: UpdatePageRequest = action.payload;
const response: ApiResponse = yield call(PageApi.updatePage, request);
const isValidResponse = yield validateResponse(response);
if (isValidResponse) {
yield put({
type: ReduxActionTypes.UPDATE_PAGE_SUCCESS,
payload: action.payload,
2020-01-27 08:24:58 +00:00
});
}
} catch (error) {
yield put({
type: ReduxActionErrorTypes.UPDATE_PAGE_ERROR,
payload: {
error,
},
});
}
}
export function* deletePageSaga(action: ReduxAction<DeletePageRequest>) {
try {
const request: DeletePageRequest = action.payload;
const defaultPageId = yield select(
(state: AppState) => state.entities.pageList.defaultPageId,
);
const applicationId = yield select(
(state: AppState) => state.entities.pageList.applicationId,
);
if (defaultPageId === request.id) {
throw Error("Cannot delete the home page.");
} else {
const response: ApiResponse = yield call(PageApi.deletePage, request);
const isValidResponse = yield validateResponse(response);
if (isValidResponse) {
yield put(deletePageSuccess());
}
// Remove this page from page DSLs
yield put({
type: ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS,
payload: {
pageId: request.id,
dsl: undefined,
},
});
const currentPageId = yield select(
(state: AppState) => state.entities.pageList.currentPageId,
);
if (currentPageId === action.payload.id)
history.push(BUILDER_PAGE_URL(applicationId, defaultPageId));
2020-01-27 08:24:58 +00:00
}
} catch (error) {
yield put({
type: ReduxActionErrorTypes.DELETE_PAGE_ERROR,
payload: {
error: { message: error.message, show: true },
show: true,
2020-01-27 08:24:58 +00:00
},
});
}
}
export function* clonePageSaga(clonePageAction: ReduxAction<ClonePageRequest>) {
try {
const request: ClonePageRequest = clonePageAction.payload;
const response: FetchPageResponse = yield call(PageApi.clonePage, request);
const applicationId = yield select(
(state: AppState) => state.entities.pageList.applicationId,
);
const isValidResponse = yield validateResponse(response);
if (isValidResponse) {
yield put(
clonePageSuccess(
response.data.id,
response.data.name,
response.data.layouts[0].id,
),
);
// Add this to the page DSLs for entity explorer
yield put({
type: ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS,
payload: {
pageId: response.data.id,
dsl: extractCurrentDSL(response),
},
});
yield put(fetchActionsForPage(response.data.id));
history.push(BUILDER_PAGE_URL(applicationId, response.data.id));
}
} catch (error) {
yield put({
type: ReduxActionErrorTypes.CLONE_PAGE_ERROR,
payload: {
error,
},
});
}
}
/**
* this saga do two things
*
* 1. Checks if the name of page is conflicting with any used name
* 2. dispatches a action which triggers a request to update the name
*
* @param action
*/
2020-02-21 12:16:49 +00:00
export function* updateWidgetNameSaga(
action: ReduxAction<{ id: string; newName: string }>,
2020-02-21 12:16:49 +00:00
) {
try {
const { widgetName } = yield select(getWidgetName, action.payload.id);
2020-02-21 12:16:49 +00:00
const layoutId = yield select(getCurrentLayoutId);
const evalTree = yield select(getDataTree);
2020-02-21 12:16:49 +00:00
const pageId = yield select(getCurrentPageId);
2020-04-29 10:20:12 +00:00
const existingPageNames = yield select(getExistingPageNames);
// TODO(abhinav): Why do we need to jump through these hoops just to
// change the tab name? Figure out a better design to make this moot.
const tabsObj: Record<
string,
{
id: string;
widgetId: string;
label: string;
}
> = yield select((state: AppState) => {
// Check if this widget exists in the canvas widgets
if (state.entities.canvasWidgets.hasOwnProperty(action.payload.id)) {
// If it does assign it to a variable
const widget = state.entities.canvasWidgets[action.payload.id];
// Check if this widget has a parent in the canvas widgets
if (
widget.parentId &&
state.entities.canvasWidgets.hasOwnProperty(widget.parentId)
) {
// If the parent exists assign it to a variable
const parent = state.entities.canvasWidgets[widget.parentId];
// Check if this parent is a TABS_WIDGET
if (parent.type === WidgetTypes.TABS_WIDGET) {
// If it is return the tabs property
return parent.tabsObj;
}
}
}
// This isn't a tab in a tabs widget so return undefined
return;
});
// If we're trying to update the name of a tab in the TABS_WIDGET
if (tabsObj !== undefined) {
const tabs: any = Object.values(tabsObj);
// Get all canvas widgets
const stateWidgets = yield select(getWidgets);
// Shallow copy canvas widgets as they're immutable
const widgets = { ...stateWidgets };
// Get the parent Id of the tab (canvas widget) whose name we're updating
const parentId = widgets[action.payload.id].parentId;
// Update the tabName property of the tab (canvas widget)
widgets[action.payload.id] = {
...widgets[action.payload.id],
tabName: action.payload.newName,
2020-02-21 12:16:49 +00:00
};
// Shallow copy the parent widget so that we can update the properties
const parent = { ...widgets[parentId] };
// Update the tabs property of the parent tabs widget
const tabToChange = tabs.find(
(each: any) => each.widgetId === action.payload.id,
2020-02-21 12:16:49 +00:00
);
const updatedTab = {
...tabToChange,
label: action.payload.newName,
};
parent.tabsObj = {
...parent.tabsObj,
[updatedTab.id]: {
...updatedTab,
},
};
// replace the parent widget in the canvas widgets
widgets[parentId] = parent;
// Update and save the new widgets
yield put(updateAndSaveLayout(widgets));
// Send a update saying that we've successfully updated the name
yield put(updateWidgetNameSuccess());
} else {
// check if name is not conflicting with any
// existing entity/api/queries/reserved words
if (
isNameValid(action.payload.newName, {
...evalTree,
...existingPageNames,
})
) {
const request: UpdateWidgetNameRequest = {
newName: action.payload.newName,
oldName: widgetName,
pageId,
layoutId,
};
const response: UpdateWidgetNameResponse = yield call(
PageApi.updateWidgetName,
request,
);
const isValidResponse = yield validateResponse(response);
if (isValidResponse) {
yield updateCanvasWithDSL(response.data, pageId, layoutId);
2020-02-21 12:16:49 +00:00
yield put(updateWidgetNameSuccess());
// Add this to the page DSLs for entity explorer
yield put({
type: ReduxActionTypes.FETCH_PAGE_DSL_SUCCESS,
payload: {
pageId: pageId,
dsl: response.data.dsl,
},
});
}
} else {
yield put({
type: ReduxActionErrorTypes.UPDATE_WIDGET_NAME_ERROR,
payload: {
error: {
message: `Entity name: ${action.payload.newName} is already being used.`,
},
},
});
2020-02-21 12:16:49 +00:00
}
}
} catch (error) {
yield put({
type: ReduxActionErrorTypes.UPDATE_WIDGET_NAME_ERROR,
payload: {
error,
},
});
}
}
2020-06-16 10:23:19 +00:00
export function* updateCanvasWithDSL(
data: PageLayout,
pageId: string,
layoutId: string,
) {
const normalizedWidgets = CanvasWidgetsNormalizer.normalize(data.dsl);
const currentPageName = yield select(getCurrentPageName);
const applicationId = yield select(getCurrentApplicationId);
const canvasWidgetsPayload: UpdateCanvasPayload = {
pageWidgetId: normalizedWidgets.result,
currentPageName,
currentPageId: pageId,
currentLayoutId: layoutId,
currentApplicationId: applicationId,
pageActions: data.layoutOnLoadActions,
widgets: normalizedWidgets.entities.canvasWidgets,
};
yield put(initCanvasLayout(canvasWidgetsPayload));
2020-06-16 10:23:19 +00:00
yield put(fetchActionsForPage(pageId));
}
export function* setDataUrl() {
const urlData: UrlDataState = {
fullPath: window.location.href,
host: window.location.host,
hostname: window.location.hostname,
queryParams: getQueryParams(),
protocol: window.location.protocol,
pathname: window.location.pathname,
port: window.location.port,
hash: window.location.hash,
};
yield put(setUrlData(urlData));
}
function* fetchPageDSLSaga(pageId: string) {
try {
const fetchPageResponse: FetchPageResponse = yield call(PageApi.fetchPage, {
id: pageId,
});
const isValidResponse = yield validateResponse(fetchPageResponse);
if (isValidResponse) {
return {
pageId: pageId,
dsl: extractCurrentDSL(fetchPageResponse),
};
}
} catch (error) {
yield put({
type: ReduxActionErrorTypes.FETCH_PAGE_DSL_ERROR,
payload: {
pageId: pageId,
error,
show: true,
},
});
return {
pageId: pageId,
dsl: DEFAULT_TEMPLATE,
};
}
}
export function* populatePageDSLsSaga() {
try {
yield put({
type: ReduxActionTypes.POPULATE_PAGEDSLS_INIT,
});
const pageIds: string[] = yield select((state: AppState) =>
state.entities.pageList.pages.map((page: Page) => page.pageId),
);
const pageDSLs = yield all(
pageIds.map((pageId: string) => {
return call(fetchPageDSLSaga, pageId);
}),
);
yield put({
type: ReduxActionTypes.FETCH_PAGE_DSLS_SUCCESS,
payload: pageDSLs,
});
} catch (error) {
yield put({
type: ReduxActionErrorTypes.POPULATE_PAGEDSLS_ERROR,
payload: {
error,
},
});
}
}
export default function* pageSagas() {
yield all([
takeLatest(ReduxActionTypes.FETCH_PAGE_INIT, fetchPageSaga),
takeLatest(
ReduxActionTypes.FETCH_PUBLISHED_PAGE_INIT,
fetchPublishedPageSaga,
),
2020-04-13 14:00:50 +00:00
takeLatest(ReduxActionTypes.UPDATE_LAYOUT, saveLayoutSaga),
takeLeading(ReduxActionTypes.CREATE_PAGE_INIT, createPageSaga),
takeLeading(ReduxActionTypes.CLONE_PAGE_INIT, clonePageSaga),
2019-11-08 11:02:00 +00:00
takeLatest(ReduxActionTypes.FETCH_PAGE_LIST_INIT, fetchPageListSaga),
2020-01-27 08:24:58 +00:00
takeLatest(ReduxActionTypes.UPDATE_PAGE_INIT, updatePageSaga),
takeLatest(ReduxActionTypes.DELETE_PAGE_INIT, deletePageSaga),
2020-01-31 10:46:43 +00:00
debounce(500, ReduxActionTypes.SAVE_PAGE_INIT, savePageSaga),
2020-02-21 12:16:49 +00:00
takeLatest(ReduxActionTypes.UPDATE_WIDGET_NAME_INIT, updateWidgetNameSaga),
2020-05-05 12:16:51 +00:00
takeLatest(
ReduxActionTypes.FETCH_ALL_PUBLISHED_PAGES,
fetchAllPublishedPagesSaga,
),
]);
}