Skip to content

feat: add 'Require Watching' option to YouTube video settings and enh… - #5218

Open
WillemBarendKruger wants to merge 4 commits into
shesha-io:mainfrom
WillemBarendKruger:bug/responsiveness
Open

feat: add 'Require Watching' option to YouTube video settings and enh…#5218
WillemBarendKruger wants to merge 4 commits into
shesha-io:mainfrom
WillemBarendKruger:bug/responsiveness

Conversation

@WillemBarendKruger

@WillemBarendKruger WillemBarendKruger commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

…ance tooltips

Summary by CodeRabbit

  • New Features
    • Added a “Require Watching” option for YouTube videos to block submission until playback has started.
  • Bug Fixes
    • Improved YouTube watch-gating by tracking started vs fully completed playback, updating validation and messaging.
    • Updated playback state handling to fire play/end more consistently (including pause handling where applicable).
  • Documentation
    • Updated YouTube settings dropdown labels for Title Level to include size descriptors (e.g., “2 (Large)”, “4 (Small)”).

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The YouTube component now tracks playback start and completion separately, exposes both states through its public API, always enables the YouTube JS API, and applies generalized watch gating. Settings add a start-watching requirement, clarify completion behavior, and update title-level labels.

Changes

YouTube watch-state API and gating

Layer / File(s) Summary
Watch-state contract and settings
shesha-reactjs/src/componentsApi/componentApi.ts, shesha-reactjs/src/designer-components/youtubeVideo/interfaces.ts, shesha-reactjs/src/designer-components/youtubeVideo/settingsForm.ts
Adds public started/completed watch-state fields, moves form requirements into model settings, and updates watch-related descriptions and title-level labels.
Player initialization and state tracking
shesha-reactjs/src/designer-components/youtubeVideo/index.tsx
Always enables the YouTube JS API, resets playback refs when the video or iframe visibility changes, and records playback start and completion events.
Watch gating and responsive rendering
shesha-reactjs/src/designer-components/youtubeVideo/index.tsx, shesha-reactjs/src/designer-components/youtubeVideo/styles.ts
Separates thumbnail dismissal from playback state, applies requirement-specific validation, renders the designer placeholder, revises responsive dimension handling, and removes obsolete completion-warning styling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Form
  participant YoutubeVideoComponent
  participant YouTubePlayer
  Form->>YoutubeVideoComponent: configure watch requirements
  YoutubeVideoComponent->>YouTubePlayer: initialize embed with JS API
  YouTubePlayer->>YoutubeVideoComponent: report PLAYING
  YoutubeVideoComponent->>Form: expose started watch state
  YouTubePlayer->>YoutubeVideoComponent: report ENDED
  YoutubeVideoComponent->>Form: expose completed watch state
Loading

Possibly related PRs

Suggested reviewers: ivanilyichev

Poem

A rabbit pressed play with a hop,
Tracking the start and the final stop.
The form now knows what viewers do,
While YouTube’s API follows through.
Completion earns a carrot on top!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a Require Watching option to YouTube video settings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx`:
- Around line 354-356: Update the satisfaction logic near satisfied so thumbnail
activation does not count as watching: introduce or reuse a state/value that is
set only when the player reports PLAYING, and use that playback-only state for
the non-completion branch instead of hasWatched. Preserve value === true and the
stricter watchCompletionRequired/isCompleted behavior.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: caafee2a-3809-4f77-9ea5-daa17d010b8e

📥 Commits

Reviewing files that changed from the base of the PR and between ea9aad8 and 8fe8684.

📒 Files selected for processing (2)
  • shesha-reactjs/src/designer-components/youtubeVideo/index.tsx
  • shesha-reactjs/src/designer-components/youtubeVideo/settingsForm.ts

Comment thread shesha-reactjs/src/designer-components/youtubeVideo/index.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
shesha-reactjs/src/designer-components/youtubeVideo/index.tsx (2)

78-81: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Handle YouTube API rejection before enabling required watch gates.

When loadYouTubeIframeApi() rejects with enablejsapi=1, the embed still plays but hasStarted/completion state are never updated, so isRequired or watchCompletionRequired can leave the submission gate permanently unsatisfied. Surface a tracking-unavailable error or disable the gate before allowing submit.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx` around lines
78 - 81, Update the YouTube API initialization flow around loadYouTubeIframeApi
and the needsJsApi/watch-gate logic so a rejected enablejsapi=1 request is
handled before enabling isRequired or watchCompletionRequired. Surface a
tracking-unavailable error or disable the affected gate, ensuring submission
cannot remain permanently blocked when player state cannot be tracked.

113-130: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not strip CSS units or convert pixels to percentages.

toPercentage() turns 560 into 560%, "500px" into "500%", and "10rem" into "10%", while "calc(...)" values become undefined and fall back to 100%. Keep the original CSS value as-is for responsive width, or convert pixel dimensions only on a real parent-width basis rather than dropping the unit.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx` around lines
113 - 130, Update toPercentage so responsive width preserves the original CSS
value and units instead of converting numeric prefixes to percentages; retain
valid values such as numbers, px, rem, %, and calc(...) without stripping units,
and avoid falling back to 100% for supported CSS expressions. If
pixel-to-percentage conversion is required, base it on the actual parent width
rather than the raw numeric value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx`:
- Around line 64-68: Reset hasStarted, isCompleted, and hasWatched whenever the
watched video identity (videoId or thumbnail) changes, and invalidate the bound
value so satisfied/value cannot remain true for the newly selected video. Update
the relevant effect or video-change handling around these state variables and
the value binding, while preserving normal state behavior when the video
identity is unchanged.

---

Outside diff comments:
In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx`:
- Around line 78-81: Update the YouTube API initialization flow around
loadYouTubeIframeApi and the needsJsApi/watch-gate logic so a rejected
enablejsapi=1 request is handled before enabling isRequired or
watchCompletionRequired. Surface a tracking-unavailable error or disable the
affected gate, ensuring submission cannot remain permanently blocked when player
state cannot be tracked.
- Around line 113-130: Update toPercentage so responsive width preserves the
original CSS value and units instead of converting numeric prefixes to
percentages; retain valid values such as numbers, px, rem, %, and calc(...)
without stripping units, and avoid falling back to 100% for supported CSS
expressions. If pixel-to-percentage conversion is required, base it on the
actual parent width rather than the raw numeric value.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fa4afd2c-abde-4776-89eb-103d128f11e3

📥 Commits

Reviewing files that changed from the base of the PR and between 8fe8684 and 34758e5.

📒 Files selected for processing (1)
  • shesha-reactjs/src/designer-components/youtubeVideo/index.tsx

Comment thread shesha-reactjs/src/designer-components/youtubeVideo/index.tsx Outdated

@IvanIlyichev IvanIlyichev left a comment

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.

Hi @WillemBarendKruger. Addressing the isRequired/watchCompletionRequired requirement through direct binding to a form field is architecturally incorrect.

There are 3 correct ways to cover this requirement:

  1. Expose isWatched/isWatchedEntirely on the component API. This allows it to be handled within the final form's configuration via form events (e.g., OnBeforeSubmit).
  2. Create custom events (OnWatch/OnWatchedEntirely). This allows it to be handled within the final form's configuration with explicit binding to a form field or context.
  3. Implement custom component validation without bindings (though this may require changes to the base form functionality).

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shesha-reactjs/src/designer-components/youtubeVideo/index.tsx (1)

127-164: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not relabel pixel dimensions as percentages.

500, 500px, and similar widths become 500%, causing severe overflow. Preserve the configured CSS width and use 100% only when it is absent.

Proposed fix
-    const toPercentage = (value: string | number | undefined): string | undefined => {
-      ...
-    };
-
     const finalDimensionStyles = responsive
       ? {
         ...dimensionStyles,
-        width: toPercentage(dimensionStyles.width) ?? '100%',
+        width: dimensionStyles.width ?? '100%',
         height: undefined,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx` around lines
127 - 164, Update the responsive branch of the dimension resolution around
finalDimensionStyles so configured widths retain their original CSS value,
including numeric values and pixel strings, instead of passing through
toPercentage. Use 100% only when dimensionStyles.width is absent, while
preserving the existing height reset and fixed-dimension behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx`:
- Line 287: Update the effect containing the formMode, videoId, and iframeShown
guard so it reruns when a previously hidden iframe becomes visible,
reinitializing the player and restoring playback tracking and configured events.
Include iframeShown in the effect’s dependency list and preserve the existing
designer-mode and empty-video behavior.
- Line 27: The YouTube video component currently ignores the configured “Require
Watching” start and completion settings at runtime. Update the component’s
runtime/rendering flow around its non-input configuration and the logic at the
referenced settings sections to evaluate these requirements, display the
appropriate warning, and gate submission when enabled, preserving normal
behavior when both options are disabled.

---

Outside diff comments:
In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx`:
- Around line 127-164: Update the responsive branch of the dimension resolution
around finalDimensionStyles so configured widths retain their original CSS
value, including numeric values and pixel strings, instead of passing through
toPercentage. Use 100% only when dimensionStyles.width is absent, while
preserving the existing height reset and fixed-dimension behavior.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 071a36a8-50af-43b7-acb9-cc315eacc537

📥 Commits

Reviewing files that changed from the base of the PR and between 34758e5 and cc0d39d.

📒 Files selected for processing (4)
  • shesha-reactjs/src/componentsApi/componentApi.ts
  • shesha-reactjs/src/designer-components/youtubeVideo/index.tsx
  • shesha-reactjs/src/designer-components/youtubeVideo/interfaces.ts
  • shesha-reactjs/src/designer-components/youtubeVideo/settingsForm.ts
💤 Files with no reviewable changes (2)
  • shesha-reactjs/src/designer-components/youtubeVideo/interfaces.ts
  • shesha-reactjs/src/designer-components/youtubeVideo/settingsForm.ts

Comment thread shesha-reactjs/src/designer-components/youtubeVideo/index.tsx
Comment thread shesha-reactjs/src/designer-components/youtubeVideo/index.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shesha-reactjs/src/designer-components/youtubeVideo/index.tsx (1)

127-145: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not reinterpret CSS dimensions as percentages.

toPercentage('500px') returns 500%, so fixed responsive widths can stretch beyond the container. Values like calc(100% - 20px) are discarded and fall back to 100%, ignoring configured responsive widths. Keep valid CSS sizes separate from percentage support, or derive explicit percentage input from the settings schema.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx` around lines
127 - 145, Update toPercentage so it does not reinterpret pixel or other CSS
dimensions as percentages: preserve only valid percentage values, and handle
configured CSS sizes such as 500px or calc(100% - 20px) through the existing
width logic rather than converting or discarding them. Use the responsive width
settings and schema to distinguish explicit percentage input from other valid
CSS values, retaining the intended fallback only for unsupported values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@shesha-reactjs/src/designer-components/youtubeVideo/index.tsx`:
- Around line 127-145: Update toPercentage so it does not reinterpret pixel or
other CSS dimensions as percentages: preserve only valid percentage values, and
handle configured CSS sizes such as 500px or calc(100% - 20px) through the
existing width logic rather than converting or discarding them. Use the
responsive width settings and schema to distinguish explicit percentage input
from other valid CSS values, retaining the intended fallback only for
unsupported values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f5189aa3-7d2a-4f92-919a-e6acfce743cc

📥 Commits

Reviewing files that changed from the base of the PR and between cc0d39d and 09dc2f8.

📒 Files selected for processing (2)
  • shesha-reactjs/src/designer-components/youtubeVideo/index.tsx
  • shesha-reactjs/src/designer-components/youtubeVideo/styles.ts
💤 Files with no reviewable changes (1)
  • shesha-reactjs/src/designer-components/youtubeVideo/styles.ts

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.

2 participants