Skip to content

fix: close Video Library drawer after Select (NES-1568)#9043

Open
jianwei1 wants to merge 3 commits intomainfrom
jianweichong/nes-1568-fix-video-library-drawer-pops-up-after-changing-video
Open

fix: close Video Library drawer after Select (NES-1568)#9043
jianwei1 wants to merge 3 commits intomainfrom
jianweichong/nes-1568-fix-video-library-drawer-pops-up-after-changing-video

Conversation

@jianwei1
Copy link
Copy Markdown
Contributor

@jianwei1 jianwei1 commented Apr 20, 2026

Summary

When a user edits an existing video block in Journey Builder and clicks Select to confirm a language (or video) change, the parent Video Library drawer stays open underneath — exposing the library browse tabs and making it look like the UI is asking them to pick a different video. This PR closes both drawers on a confirmed Select while preserving the background MUX upload completion contract (uploads finishing in the background must not yank a drawer the user has moved on from).

Reported by Lucinda (JFP) while preparing 34 World Cup journey translations. Confirmed by Siyang in #nextsteps-bugs on 2026-04-17 NZ time. Related UX overhaul tracked in QA-221.

Changes

  • apps/journeys-admin/src/components/Editor/Slider/Settings/Drawer/VideoLibrary/VideoLibrary.tsx — after closing the inner VideoDetails drawer in onSelect, also call onClose?.() on the parent, gated on the existing shouldCloseDrawer parameter. Mirrors the pattern already in handleVideoDetailsClose (if (closeParent === true) onClose?.()).
  • apps/journeys-admin/src/components/Editor/Slider/Settings/Drawer/VideoLibrary/VideoLibrary.spec.tsx — new and extended tests:
    • existing-internal-video Select closes both drawers;
    • new-video Select (library tab) closes both drawers;
    • background MUX upload completion (shouldCloseDrawer=false) does NOT close the outer drawer;
    • Change Video on internal / YouTube / MUX sources does NOT close the outer drawer;
    • assertions tightened from toHaveBeenCalled() to toHaveBeenCalledTimes(1) to guard against double-fire regressions.
  • docs/plans/2026-04-20-001-fix-video-library-stays-open-after-language-select-plan.md — plan doc.

Why the gate matters

AddByFile.onChange(videoId, false)VideoFromMux.handleChangeVideoLibrary.onSelect(block, false) is the background-upload completion path. It deliberately passes shouldCloseDrawer=false so a completion firing after the user has navigated to a different block cannot close the drawer they are now using. Gating the new onClose?.() on that existing parameter restores the contract and happens to realign the parameter name with real behaviour.

Test plan

  • npx jest --config apps/journeys-admin/jest.config.ts --no-coverage 'apps/journeys-admin/src/components/Editor/Slider/Settings/Drawer/VideoLibrary/' — 15 suites, 102 pass (1 pre-existing skip)
  • npx jest on the three direct consumers (Source, VideoOptions, BackgroundMediaVideo) — 3 suites, 15 pass
  • QA on Vercel preview (see Linear ticket for scenarios): edit language on existing video → Select → editor returns; pick a new video from Library tab → Select → editor returns; change the video via Change Video → library browse tabs remain; background MUX upload completion while viewing a different block → drawer stays put

Links

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the Video Library drawer staying open after selecting or updating a video in the editor.
    • Drawer now closes when a video selection is confirmed, but remains open for background upload completions that should not dismiss it.
    • “Change Video” flows no longer unexpectedly close the library drawer.

When a user edits an existing video block and changes the audio
language, clicking Select correctly saved the language but left the
parent Video Library drawer open underneath — exposing the browse
tabs and suggesting they still had to pick a different video.

The onSelect handler was only closing the inner VideoDetails drawer
via setOpenVideoDetails(false); it never invoked the outer onClose
supplied by the parent (Source.tsx, BackgroundMediaVideo.tsx). A
confirmed Select is a terminal action — both drawers should close.

Regression-guarded: the Change Video button still keeps the outer
drawer open so users can pick a different video.
The previous commit unconditionally called the parent drawer's
onClose after a video block update. That broke the background MUX
upload completion contract: AddByFile explicitly passes
shouldCloseDrawer=false through VideoFromMux → VideoLibrary.onSelect
so an upload finishing in the background cannot close a drawer the
user is now using on a different block.

Gate the new onClose?.() call on shouldCloseDrawer, mirroring the
pattern already in handleVideoDetailsClose. This restores the
background-completion contract and aligns the parameter name with
real behaviour.

Tests:
- Tighten onClose assertions from toHaveBeenCalled to toHaveBeenCalledTimes(1).
- Add regression guards (expect(onClose).not.toHaveBeenCalled()) to
  the YouTube and MUX Change-Video tests so every source type is
  protected against a future unconditional-close regression.
- Add a new test that stubs VideoFromMux to fire onSelect(block,
  false) and asserts onClose is not called — covering the background
  upload completion path end-to-end.

Plan updated (Requirements Trace R3, Key Technical Decisions, and
per-unit Approach) to reflect the corrected call chain and gate.
@linear
Copy link
Copy Markdown

linear Bot commented Apr 20, 2026

@jianwei1 jianwei1 self-assigned this Apr 20, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4707fbbf-0216-4f92-bcad-004c965dcd02

📥 Commits

Reviewing files that changed from the base of the PR and between dcb577d and ef1384f.

📒 Files selected for processing (1)
  • docs/plans/2026-04-20-001-fix-video-library-stays-open-after-language-select-plan.md
✅ Files skipped from review due to trivial changes (1)
  • docs/plans/2026-04-20-001-fix-video-library-stays-open-after-language-select-plan.md

Walkthrough

The changes fix a UX bug where the outer Video Library drawer remained open after confirming a video-block update by adding conditional drawer-closing logic controlled by a shouldCloseDrawer parameter and adding tests to verify closure behavior while preserving background MUX upload flows.

Changes

Cohort / File(s) Summary
VideoLibrary Implementation
apps/journeys-admin/src/components/Editor/Slider/Settings/Drawer/VideoLibrary/VideoLibrary.tsx
Invoke onClose after selection when shouldCloseDrawer is truthy; retains existing inner setOpenVideoDetails(false) behavior.
VideoLibrary Test Coverage
apps/journeys-admin/src/components/Editor/Slider/Settings/Drawer/VideoLibrary/VideoLibrary.spec.tsx
Added Jest mock for VideoFromMux, new/updated tests asserting onClose is called for Select flows and not called for "Change Video" or when shouldCloseDrawer=false.
Documentation / Plan
docs/plans/2026-04-20-001-fix-video-library-stays-open-after-language-select-plan.md
New plan describing the bug, the onClose?.() change gated by shouldCloseDrawer, and required regression tests covering selection and non-closing scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: closing the Video Library drawer after Select, with the ticket reference for context.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jianweichong/nes-1568-fix-video-library-drawer-pops-up-after-changing-video

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 20, 2026

View your CI Pipeline Execution ↗ for commit ef1384f

Command Status Duration Result
nx run journeys-admin-e2e:e2e ✅ Succeeded 26s View ↗
nx run-many --target=vercel-alias --projects=jo... ✅ Succeeded 2s View ↗
nx run-many --target=upload-sourcemaps --projec... ✅ Succeeded 9s View ↗
nx run-many --target=deploy --projects=journeys... ✅ Succeeded 2m 37s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-20 03:16:14 UTC

@github-actions github-actions Bot requested a deployment to Preview - journeys-admin April 20, 2026 03:04 Pending
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@docs/plans/2026-04-20-001-fix-video-library-stays-open-after-language-select-plan.md`:
- Line 158: The plan text incorrectly states that background MUX upload
completion does not trigger VideoLibrary.onSelect and instead goes through
VideoOptions.handleChange; update the risk row to reflect the actual
implementation and tests: background upload completions do flow through
VideoLibrary.onSelect with shouldCloseDrawer=false (which is why the gate
exists) and the regression test at the spec (lines 1090–1129) verifies this
behavior; ensure the row references VideoLibrary.onSelect,
VideoOptions.handleChange only as the alternate path, and mention
shouldCloseDrawer=false and the gate as the rationale so the plan and
implementation are consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4f5d9e49-15f1-4f29-99a9-54d74cbc229a

📥 Commits

Reviewing files that changed from the base of the PR and between e5c6ca8 and dcb577d.

📒 Files selected for processing (3)
  • apps/journeys-admin/src/components/Editor/Slider/Settings/Drawer/VideoLibrary/VideoLibrary.spec.tsx
  • apps/journeys-admin/src/components/Editor/Slider/Settings/Drawer/VideoLibrary/VideoLibrary.tsx
  • docs/plans/2026-04-20-001-fix-video-library-stays-open-after-language-select-plan.md

|------|------------|
| A rare caller might rely on the outer drawer staying open after Select (e.g. a preview-multiple-videos flow). | None found in the codebase after reviewing `VideoLibrary` consumers (`Source`, `BackgroundMediaVideo`, `VideoOptions`). Test coverage will catch any hidden coupling. |
| Snapshot or storybook tests asserting the pre-bug DOM state could break. | Run `VideoLibrary.stories.tsx` and `VideoLibrary.spec.tsx` after the change and update any snapshots that reflect the new (correct) behaviour, with a note in the PR. |
| Background MUX upload completion inadvertently triggers `VideoLibrary.onSelect`. | Confirmed in Phase 1 research it does not — it goes through `VideoOptions.handleChange` directly. A test asserts upload-completion paths don't invoke `onClose`. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Minor inconsistency between the plan and the implemented fix.

Line 158's risk row states background MUX upload completion "does not" trigger VideoLibrary.onSelect and "goes through VideoOptions.handleChange directly" — but the rest of the plan (R3 on line 31, the resolved Q on line 96, and the Key Decision on line 86) correctly documents that completions do flow through VideoLibrary.onSelect with shouldCloseDrawer=false, which is exactly why the gate exists. Worth tightening this row so the rationale stays consistent with the actual implementation and the new regression test at lines 1090–1129 of the spec.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@docs/plans/2026-04-20-001-fix-video-library-stays-open-after-language-select-plan.md`
at line 158, The plan text incorrectly states that background MUX upload
completion does not trigger VideoLibrary.onSelect and instead goes through
VideoOptions.handleChange; update the risk row to reflect the actual
implementation and tests: background upload completions do flow through
VideoLibrary.onSelect with shouldCloseDrawer=false (which is why the gate
exists) and the regression test at the spec (lines 1090–1129) verifies this
behavior; ensure the row references VideoLibrary.onSelect,
VideoOptions.handleChange only as the alternate path, and mention
shouldCloseDrawer=false and the gate as the rationale so the plan and
implementation are consistent.

@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 20, 2026 03:09 Inactive
@github-actions
Copy link
Copy Markdown
Contributor

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys-admin ✅ Ready journeys-admin preview Mon Apr 20 15:13:10 NZST 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant