From 4ec6c9a5ae9625bb52805d716af55d8a0ac227b2 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Thu, 13 Jan 2022 13:31:42 +0530 Subject: [PATCH 1/2] App crashes when a modal has a filepicker? (#10376) (cherry picked from commit f646eeafc1bbe442450d797e383080ca21ca6182) --- .../widgets/CameraWidget/component/index.tsx | 17 +++++++++++------ .../widgets/FilePickerWidgetV2/widget/index.tsx | 14 +++++++++++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/client/src/widgets/CameraWidget/component/index.tsx b/app/client/src/widgets/CameraWidget/component/index.tsx index 5fb9269050..7fb000bcc4 100644 --- a/app/client/src/widgets/CameraWidget/component/index.tsx +++ b/app/client/src/widgets/CameraWidget/component/index.tsx @@ -9,6 +9,7 @@ import { FullScreenHandle, useFullScreenHandle, } from "react-full-screen"; +import log from "loglevel"; import { ThemeProp } from "components/ads/common"; import { @@ -891,12 +892,16 @@ function CameraComponent(props: CameraComponentProps) { const fullScreenHandle = useFullScreenHandle(); useEffect(() => { - navigator.mediaDevices - .enumerateDevices() - .then(handleDeviceInputs) - .catch((err) => { - setError(err.message); - }); + try { + navigator.mediaDevices + .enumerateDevices() + .then(handleDeviceInputs) + .catch((err) => { + setError(err.message); + }); + } catch (e) { + log.debug("Error in calling enumerateDevices"); + } }, []); useEffect(() => { diff --git a/app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx b/app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx index f483d10cab..70bf297c86 100644 --- a/app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx +++ b/app/client/src/widgets/FilePickerWidgetV2/widget/index.tsx @@ -16,6 +16,7 @@ import _, { findIndex } from "lodash"; import FileDataTypes from "../constants"; import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory"; import { createBlobUrl, isBlobUrl } from "utils/AppsmithUtils"; +import log from "loglevel"; class FilePickerWidget extends BaseWidget< FilePickerWidgetProps, @@ -323,14 +324,17 @@ class FilePickerWidget extends BaseWidget< .use(Url, { companionUrl: "https://companion.uppy.io" }) .use(OneDrive, { companionUrl: "https://companion.uppy.io/", - }) - .use(Webcam, { + }); + + if (location.protocol === "https:") { + this.state.uppy.use(Webcam, { onBeforeSnapshot: () => Promise.resolve(), countdown: false, mirror: true, facingMode: "user", locale: {}, }); + } this.state.uppy.on("file-removed", (file: any) => { const updatedFiles = this.props.selectedFiles @@ -451,7 +455,11 @@ class FilePickerWidget extends BaseWidget< componentDidMount() { super.componentDidMount(); - this.initializeUppyEventListeners(); + try { + this.initializeUppyEventListeners(); + } catch (e) { + log.debug("Error in initializing uppy"); + } } componentWillUnmount() { From c1a32c9dfe0a258f2f64aa6fcdb3c439556fa4a9 Mon Sep 17 00:00:00 2001 From: Abhijeet <41686026+abhvsn@users.noreply.github.com> Date: Thu, 13 Jan 2022 19:00:04 +0530 Subject: [PATCH 2/2] Revert "chore: Don't take client subscription into account for fork application (#10220)" (#10375) This reverts commit 814a7d57f9dad02a89942e97db0d4646b489fd07. --- .../ce/ApplicationForkingServiceCEImpl.java | 13 +-- .../ApplicationForkingServiceTests.java | 102 ------------------ 2 files changed, 1 insertion(+), 114 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationForkingServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationForkingServiceCEImpl.java index 9a39efa9a1..c25f166a40 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationForkingServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationForkingServiceCEImpl.java @@ -44,7 +44,7 @@ public class ApplicationForkingServiceCEImpl implements ApplicationForkingServic Mono userMono = sessionUserService.getCurrentUser(); - Mono forkApplicationMono = Mono.zip(sourceApplicationMono, targetOrganizationMono, userMono) + return Mono.zip(sourceApplicationMono, targetOrganizationMono, userMono) .flatMap(tuple -> { final Application application = tuple.getT1(); final Organization targetOrganization = tuple.getT2(); @@ -75,17 +75,6 @@ public class ApplicationForkingServiceCEImpl implements ApplicationForkingServic .flatMap(application -> sendForkApplicationAnalyticsEvent(srcApplicationId, targetOrganizationId, application)); }); - - // Fork application is currently a slow API because it needs to create application, clone all the pages, and then - // copy all the actions and collections. This process may take time and the client may cancel the request. - // This leads to the flow getting stopped mid way producing corrupted DB objects. The following ensures that even - // though the client may have cancelled the flow, the forking of the application should proceed uninterrupted - // and whenever the user refreshes the page, the sane forked application is available. - // To achieve this, we use a synchronous sink which does not take subscription cancellations into account. This - // means that even if the subscriber has cancelled its subscription, the create method still generates its event. - return Mono.create(sink -> forkApplicationMono - .subscribe(sink::success, sink::error, null, sink.currentContext()) - ); } public Mono forkApplicationToOrganization(String srcApplicationId, diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ApplicationForkingServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ApplicationForkingServiceTests.java index 4cc3e10a37..51aa90da11 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ApplicationForkingServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ApplicationForkingServiceTests.java @@ -61,7 +61,6 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -383,107 +382,6 @@ public class ApplicationForkingServiceTests { .verify(); } - @Test - @WithUserDetails(value = "api_user") - public void test4_validForkApplication_cancelledMidWay_createValidApplication() { - - Organization targetOrganization = new Organization(); - targetOrganization.setName("Target Organization"); - targetOrganization = organizationService.create(targetOrganization).block(); - - // Trigger the fork application flow - applicationForkingService.forkApplicationToOrganization(sourceAppId, targetOrganization.getId()) - .timeout(Duration.ofMillis(10)) - .subscribe(); - - // Wait for fork to complete - Mono forkedAppFromDbMono = Mono.just(targetOrganization) - .flatMap(organization -> { - try { - // Before fetching the forked application, sleep for 5 seconds to ensure that the forking finishes - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return applicationService.findByOrganizationId(organization.getId(), READ_APPLICATIONS).next(); - }) - .cache(); - - StepVerifier - .create(forkedAppFromDbMono.zipWhen(application -> - Mono.zip( - newActionService.findAllByApplicationIdAndViewMode(application.getId(), false, READ_ACTIONS, null).collectList(), - actionCollectionService.findAllByApplicationIdAndViewMode(application.getId(), false, READ_ACTIONS, null).collectList(), - newPageService.findNewPagesByApplicationId(application.getId(), READ_PAGES).collectList())) - ) - .assertNext(tuple -> { - Application application = tuple.getT1(); - List actionList = tuple.getT2().getT1(); - List actionCollectionList = tuple.getT2().getT2(); - List pageList = tuple.getT2().getT3(); - - assertThat(application).isNotNull(); - assertThat(application.getName()).isEqualTo("1 - public app"); - assertThat(application.getPages().get(0).getDefaultPageId()) - .isEqualTo(application.getPages().get(0).getId()); - assertThat(application.getPublishedPages().get(0).getDefaultPageId()) - .isEqualTo(application.getPublishedPages().get(0).getId()); - - assertThat(pageList).isNotEmpty(); - pageList.forEach(newPage -> { - assertThat(newPage.getDefaultResources()).isNotNull(); - assertThat(newPage.getDefaultResources().getPageId()).isEqualTo(newPage.getId()); - assertThat(newPage.getDefaultResources().getApplicationId()).isEqualTo(application.getId()); - - newPage.getUnpublishedPage() - .getLayouts() - .forEach(layout -> - layout.getLayoutOnLoadActions().forEach(dslActionDTOS -> { - dslActionDTOS.forEach(actionDTO -> { - assertThat(actionDTO.getId()).isEqualTo(actionDTO.getDefaultActionId()); - }); - }) - ); - }); - - assertThat(actionList).hasSize(2); - actionList.forEach(newAction -> { - assertThat(newAction.getDefaultResources()).isNotNull(); - assertThat(newAction.getDefaultResources().getActionId()).isEqualTo(newAction.getId()); - assertThat(newAction.getDefaultResources().getApplicationId()).isEqualTo(application.getId()); - - ActionDTO action = newAction.getUnpublishedAction(); - assertThat(action.getDefaultResources()).isNotNull(); - assertThat(action.getDefaultResources().getPageId()).isEqualTo(application.getPages().get(0).getId()); - if (!StringUtils.isEmpty(action.getDefaultResources().getCollectionId())) { - assertThat(action.getDefaultResources().getCollectionId()).isEqualTo(action.getCollectionId()); - } - }); - - assertThat(actionCollectionList).hasSize(1); - actionCollectionList.forEach(actionCollection -> { - assertThat(actionCollection.getDefaultResources()).isNotNull(); - assertThat(actionCollection.getDefaultResources().getCollectionId()).isEqualTo(actionCollection.getId()); - assertThat(actionCollection.getDefaultResources().getApplicationId()).isEqualTo(application.getId()); - - ActionCollectionDTO unpublishedCollection = actionCollection.getUnpublishedCollection(); - - assertThat(unpublishedCollection.getDefaultToBranchedActionIdsMap()) - .hasSize(1); - unpublishedCollection.getDefaultToBranchedActionIdsMap().keySet() - .forEach(key -> - assertThat(key).isEqualTo(unpublishedCollection.getDefaultToBranchedActionIdsMap().get(key)) - ); - - assertThat(unpublishedCollection.getDefaultResources()).isNotNull(); - assertThat(unpublishedCollection.getDefaultResources().getPageId()) - .isEqualTo(application.getPages().get(0).getId()); - }); - }) - .verifyComplete(); - - } - private Flux getActionsInOrganization(Organization organization) { return applicationService .findByOrganizationId(organization.getId(), READ_APPLICATIONS)