🎥 Make videos programmatically with React
Fix same-sequence effect inspector selection (#8560)
Jonny Burger2b937526454b
diff --git a/packages/studio/src/components/InspectorPanel.tsx b/packages/studio/src/components/InspectorPanel.tsxindex b8bfd35f12..f17e52a989 100644--- a/packages/studio/src/components/InspectorPanel.tsx+++ b/packages/studio/src/components/InspectorPanel.tsx@@ -2,7 +2,7 @@ import React, {useMemo} from 'react';import type {_InternalTypes} from 'remotion';import {InspectorMessage} from './InspectorPanel/common';import {DefaultInspector} from './InspectorPanel/DefaultInspector';-import {getSameSequencePropInspectorSelection} from './InspectorPanel/inspector-selection';+import {getSameSequenceInspectorSelection} from './InspectorPanel/inspector-selection';import {SelectedInspector} from './InspectorPanel/SelectedInspector';import {container} from './InspectorPanel/styles';import type {UpdaterFunction} from './RenderModal/SchemaEditor/ZodSwitch';@@ -14,8 +14,8 @@ export const InspectorPanel: React.FC<{readonly setDefaultProps: UpdaterFunction<Record<string, unknown>>;}> = ({composition, currentDefaultProps, setDefaultProps}) => {const {selectedItems} = useTimelineSelection();- const sameSequencePropInspectorSelection = useMemo(- () => getSameSequencePropInspectorSelection(selectedItems),+ const sameSequenceInspectorSelection = useMemo(+ () => getSameSequenceInspectorSelection(selectedItems),[selectedItems],);@@ -30,10 +30,10 @@ export const InspectorPanel: React.FC<{}if (selectedItems.length > 1) {- if (sameSequencePropInspectorSelection) {+ if (sameSequenceInspectorSelection) {return (<div style={container}>- <SelectedInspector selection={sameSequencePropInspectorSelection} />+ <SelectedInspector selection={sameSequenceInspectorSelection} /></div>);}diff --git a/packages/studio/src/components/InspectorPanel/inspector-selection.ts b/packages/studio/src/components/InspectorPanel/inspector-selection.tsindex 865053c5f9..41180cf5cc 100644--- a/packages/studio/src/components/InspectorPanel/inspector-selection.ts+++ b/packages/studio/src/components/InspectorPanel/inspector-selection.ts@@ -27,25 +27,26 @@ export const isSequenceSectionSelection = ();};-type SequencePropSelection = Extract<+type SameSequenceInspectorSelection = Extract<TimelineSelection,- {type: 'sequence-prop' | 'sequence-effect-prop'}+ {type: 'sequence-prop' | 'sequence-effect' | 'sequence-effect-prop'}>;-const isSequencePropSelection = (+const isSameSequenceInspectorSelection = (selection: TimelineSelection,-): selection is SequencePropSelection => {+): selection is SameSequenceInspectorSelection => {return (selection.type === 'sequence-prop' ||+ selection.type === 'sequence-effect' ||selection.type === 'sequence-effect-prop');};-export const getSameSequencePropInspectorSelection = (+export const getSameSequenceInspectorSelection = (selections: readonly TimelineSelection[],-): SequencePropSelection | null => {+): SameSequenceInspectorSelection | null => {const firstSelection = selections[0];- if (!firstSelection || !isSequencePropSelection(firstSelection)) {+ if (!firstSelection || !isSameSequenceInspectorSelection(firstSelection)) {return null;}@@ -53,7 +54,7 @@ export const getSameSequencePropInspectorSelection = (firstSelection.nodePathInfo,);for (const selection of selections) {- if (!isSequencePropSelection(selection)) {+ if (!isSameSequenceInspectorSelection(selection)) {return null;}diff --git a/packages/studio/src/test/inspector-selection.test.ts b/packages/studio/src/test/inspector-selection.test.tsnew file mode 100644index 0000000000..58aed70548--- /dev/null+++ b/packages/studio/src/test/inspector-selection.test.ts@@ -0,0 +1,57 @@+import {expect, test} from 'bun:test';+import type {SequenceNodePath, SequencePropsSubscriptionKey} from 'remotion';+import {getSameSequenceInspectorSelection} from '../components/InspectorPanel/inspector-selection';+import type {TimelineSelection} from '../components/Timeline/TimelineSelection';+import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';++const makeKey = (nodePath: SequenceNodePath): SequencePropsSubscriptionKey => ({+ absolutePath: '/project/src/Comp.tsx',+ effectKeys: [],+ nodePath,+ sequenceKeys: ['from', 'durationInFrames'],+});++const makeNodePathInfo = (+ nodePath: SequenceNodePath,+ auxiliaryKeys: string[],+): SequenceNodePathInfo => ({+ auxiliaryKeys,+ index: 0,+ numberOfSequencesWithThisNodePath: 1,+ sequenceSubscriptionKey: makeKey(nodePath),+ supportsEffects: true,+});++test('keeps the sequence inspector for multiple effects from the same sequence', () => {+ const firstEffect: TimelineSelection = {+ i: 0,+ nodePathInfo: makeNodePathInfo(['Root', 'Child'], ['effects', '0']),+ type: 'sequence-effect',+ };+ const secondEffect: TimelineSelection = {+ i: 1,+ nodePathInfo: makeNodePathInfo(['Root', 'Child'], ['effects', '1']),+ type: 'sequence-effect',+ };++ expect(getSameSequenceInspectorSelection([firstEffect, secondEffect])).toBe(+ firstEffect,+ );+});++test('does not keep the sequence inspector for effects from different sequences', () => {+ const firstEffect: TimelineSelection = {+ i: 0,+ nodePathInfo: makeNodePathInfo(['Root', 'First'], ['effects', '0']),+ type: 'sequence-effect',+ };+ const secondEffect: TimelineSelection = {+ i: 0,+ nodePathInfo: makeNodePathInfo(['Root', 'Second'], ['effects', '0']),+ type: 'sequence-effect',+ };++ expect(getSameSequenceInspectorSelection([firstEffect, secondEffect])).toBe(+ null,+ );+});