Skip to content

🎥 Make videos programmatically with React

Elements: Keep Studio library open when canceling installation (#11794)

Igor Samokhovetsdba3c31e8eda
diff --git a/packages/example/e2e/studio-protocol.test.mts b/packages/example/e2e/studio-protocol.test.mts
index dc9bb1744d..de0a43fc31 100644
--- a/packages/example/e2e/studio-protocol.test.mts
+++ b/packages/example/e2e/studio-protocol.test.mts
@@ -1,4 +1,3 @@
-import {expect, test} from '@playwright/test';
import type {ChildProcess} from 'node:child_process';
import {spawn} from 'node:child_process';
import fs from 'node:fs';
@@ -6,6 +5,7 @@ import {createServer} from 'node:http';
import os from 'node:os';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
+import {expect, test} from '@playwright/test';
import {remotionBin} from './constants.mts';
const waitForUrl = async (url: string, process: ChildProcess) => {
@@ -403,11 +403,10 @@ const CloseupPlaceholder = () => {
});
await expect(dialog).toBeVisible();
await dialog.getByRole('button', {name: 'Cancel'}).click();
- expect(fs.existsSync(installedAsset)).toBe(false);
- await browseElements.click();
- await expect(externalLibraryItem).toBeVisible();
- await externalLibraryItem.click();
+ await expect(dialog).toHaveCount(0);
await expect(elementsIframe).toBeVisible();
+ expect(externalLibraryRequests).toHaveLength(1);
+ expect(fs.existsSync(installedAsset)).toBe(false);
await installInStudio.click();
await expect(dialog).toBeVisible();
const currentDestination = dialog.getByRole('button', {
@@ -453,9 +452,10 @@ const CloseupPlaceholder = () => {
await expect(
decoyStudioPage.getByText('Install Protocol Element', {exact: true}),
).toHaveCount(0);
- await expect(elementsIframe).toHaveCount(0);
+ await expect(elementsIframe).toBeVisible();
expect(studioProtocolRequests).toEqual([]);
await dialog.getByRole('button', {name: /Install/}).click();
+ await expect(elementsIframe).toHaveCount(0);
await expect(
studioPage
.getByRole('group', {name: 'Inspector source location'})
diff --git a/packages/studio/src/components/ElementInstallConfirmation.tsx b/packages/studio/src/components/ElementInstallConfirmation.tsx
index c13b82978f..220b27838c 100644
--- a/packages/studio/src/components/ElementInstallConfirmation.tsx
+++ b/packages/studio/src/components/ElementInstallConfirmation.tsx
@@ -311,6 +311,7 @@ export const ElementInstallConfirmation: React.FC<{
currentPlan,
missingPackages,
newPlan,
+ onCancel,
onClose,
request,
sourceIsUnverified,
@@ -834,9 +835,9 @@ export const ElementInstallConfirmation: React.FC<{
const cancel = useCallback(() => {
if (!submitting) {
- onClose();
+ onCancel();
}
- }, [onClose, submitting]);
+ }, [onCancel, submitting]);
const destinationOptions = useMemo(
() => [
diff --git a/packages/studio/src/components/ElementInstallRequestHandler.tsx b/packages/studio/src/components/ElementInstallRequestHandler.tsx
index 64056e36bb..2bd0c0b23d 100644
--- a/packages/studio/src/components/ElementInstallRequestHandler.tsx
+++ b/packages/studio/src/components/ElementInstallRequestHandler.tsx
@@ -293,7 +293,16 @@ export const ElementInstallRequestHandler: FC = () => {
}, [activeRequest, pendingRequests]);
const closeElementInstallDialog = useCallback(() => {
- setSelectedModal(null);
+ setSelectedModal((modal) =>
+ modal?.type === 'element-install' ? null : modal,
+ );
+ setActiveRequest(null);
+ }, [setSelectedModal]);
+
+ const cancelElementInstallDialog = useCallback(() => {
+ setSelectedModal((modal) =>
+ modal?.type === 'element-install' ? modal.library : modal,
+ );
setActiveRequest(null);
}, [setSelectedModal]);
@@ -373,16 +382,22 @@ export const ElementInstallRequestHandler: FC = () => {
(source.type === 'browser-studio-link' && source.origin === null);
const currentPlan =
currentPreflight?.success === true ? currentPreflight.plan : null;
- setSelectedModal({
+ setSelectedModal((modal) => ({
type: 'element-install',
currentPlan,
+ library:
+ activeRequest.source.type === 'studio-protocol' &&
+ modal?.type === 'element-library'
+ ? modal
+ : null,
missingPackages,
newPlan: newPreflight.plan,
+ onCancel: cancelElementInstallDialog,
onClose: closeElementInstallDialog,
request: activeRequest,
sourceIsUnverified,
sourceLabel,
- });
+ }));
} catch (error) {
if (canceled) {
return;
@@ -402,7 +417,12 @@ export const ElementInstallRequestHandler: FC = () => {
return () => {
canceled = true;
};
- }, [activeRequest, closeElementInstallDialog, setSelectedModal]);
+ }, [
+ activeRequest,
+ cancelElementInstallDialog,
+ closeElementInstallDialog,
+ setSelectedModal,
+ ]);
return null;
};
diff --git a/packages/studio/src/components/ElementLibraryModal.tsx b/packages/studio/src/components/ElementLibraryModal.tsx
index 4072f1557c..80c972cf52 100644
--- a/packages/studio/src/components/ElementLibraryModal.tsx
+++ b/packages/studio/src/components/ElementLibraryModal.tsx
@@ -1,7 +1,11 @@
import React, {useCallback, useContext, useLayoutEffect, useRef} from 'react';
import {GearIcon} from '../icons/gear';
-import {SetSelectedModalContext} from '../state/modals';
+import {
+ type ElementInstallModalState,
+ SetSelectedModalContext,
+} from '../state/modals';
import {ActionTooltip} from './ActionTooltip';
+import {ElementInstallConfirmation} from './ElementInstallConfirmation';
import type {RenderInlineAction} from './InlineAction';
import {InlineAction} from './InlineAction';
import {getMaxModalHeight, getMaxModalWidth} from './ModalContainer';
@@ -27,7 +31,8 @@ const iframeStyle: React.CSSProperties = {
export const ElementLibraryModal: React.FC<{
readonly name: string;
readonly url: string;
-}> = ({name, url}) => {
+ readonly installState: ElementInstallModalState | null;
+}> = ({name, url, installState}) => {
const iframeRef = useRef<HTMLIFrameElement>(null);
const {setSelectedModal} = useContext(SetSelectedModalContext);
const openElementSettings = useCallback(() => {
@@ -85,6 +90,9 @@ export const ElementLibraryModal: React.FC<{
style={iframeStyle}
aria-label={`${name} library`}
/>
+ {installState === null ? null : (
+ <ElementInstallConfirmation state={installState} />
+ )}
</DismissableModal>
);
};
diff --git a/packages/studio/src/components/Modals.tsx b/packages/studio/src/components/Modals.tsx
index f8560207c1..67fe583529 100644
--- a/packages/studio/src/components/Modals.tsx
+++ b/packages/studio/src/components/Modals.tsx
@@ -241,6 +241,13 @@ export const Modals: React.FC<{
requestElementLibraryAddition,
]);
+ const library =
+ modalContextType?.type === 'element-library'
+ ? modalContextType
+ : modalContextType?.type === 'element-install'
+ ? modalContextType.library
+ : null;
+
return (
<>
{modalContextType && modalContextType.type === 'new-comp' && (
@@ -422,15 +429,20 @@ export const Modals: React.FC<{
state={modalContextType}
/>
) : null}
- {modalContextType && modalContextType.type === 'element-library' && (
+ {library === null ? null : (
<ElementLibraryModal
- name={modalContextType.name}
- url={modalContextType.url}
+ name={library.name}
+ url={library.url}
+ installState={
+ modalContextType?.type === 'element-install'
+ ? modalContextType
+ : null
+ }
/>
)}
- {modalContextType && modalContextType.type === 'element-install' && (
+ {modalContextType?.type === 'element-install' && library === null ? (
<ElementInstallConfirmation state={modalContextType} />
- )}
+ ) : null}
{modalContextType && modalContextType.type === 'add-effect' && (
<EffectPickerModal state={modalContextType} />
)}
diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.ts
index af318a91bb..5fb7c8eddb 100644
--- a/packages/studio/src/state/modals.ts
+++ b/packages/studio/src/state/modals.ts
@@ -196,11 +196,19 @@ export type ElementInstallPlan = {
readonly filePath: string;
};
+export type ElementLibraryModalState = {
+ readonly type: 'element-library';
+ readonly name: string;
+ readonly url: string;
+};
+
export type ElementInstallModalState = {
readonly type: 'element-install';
readonly currentPlan: ElementInstallPlan | null;
readonly missingPackages: string[];
readonly newPlan: ElementInstallPlan;
+ readonly library: ElementLibraryModalState | null;
+ readonly onCancel: () => void;
readonly onClose: () => void;
readonly request: ElementInstallRequest;
readonly sourceIsUnverified: boolean;
@@ -337,11 +345,7 @@ export type ModalState =
onSelected: (composition: _InternalTypes['AnyComposition']) => void;
} | null;
}
- | {
- type: 'element-library';
- name: string;
- url: string;
- }
+ | ElementLibraryModalState
| ElementInstallModalState
| AddEffectModalState
| AssetSelectionModalState