Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ You can also override per-load via URL query params: `?contentId=do_123&lang=hi&
| **Review workflow** | Send for review, reviewer request-changes (with reasons checklist), publish. |
| **Locking** | Creates a content lock on upload / edit-open; retires it on close and on send-for-review. |
| **Session guard** | 30-minute inactivity prompt (Continue / Close). |
| **Enrichments** | Ticking "Generate transcripts" when uploading a video saves `enrichmentTypes` on the content; the platform generates transcripts after publish. A published video's transcripts show in a read-only drawer and as preview captions, read via `POST /object/enrichment/v4/list` (served under `config.portalSlug`, default `/portal`). |
| **Telemetry** | Emits Sunbird 3.0 telemetry (impression / interact / error / end) via `onTelemetryEvent`. |
| **Preview** | Renders through the ekstep content renderer for every supported mimeType. |

Expand Down
4 changes: 2 additions & 2 deletions src/ContentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MetadataDrawer from './components/MetadataDrawer';
import CollaboratorDrawer from './components/CollaboratorDrawer';
import ReviewDrawer from './components/ReviewDrawer';
import ReviewCommentsDrawer from './components/ReviewCommentsDrawer';
import TranscriptsDrawer from './components/TranscriptsDrawer';
import EnrichmentsDrawer from './components/enrichment/EnrichmentsDrawer';
import AssetPickerModal from './components/AssetPickerModal';
import Toast from './components/Toast';
import { t } from './i18n/i18n';
Expand Down Expand Up @@ -69,7 +69,7 @@ const ContentEditor: React.FC<ContentEditorProps> = (props) => {
<CollaboratorDrawer ed={ed} />
<ReviewDrawer ed={ed} />
<ReviewCommentsDrawer ed={ed} />
<TranscriptsDrawer ed={ed} />
<EnrichmentsDrawer ed={ed} />
<AssetPickerModal ed={ed} />

<Toast toast={ed.toast} />
Expand Down
79 changes: 48 additions & 31 deletions src/components/EditorPreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import EditorPreview, { rendererData } from './EditorPreview';
import { makeEd, mockContext, mockContent } from '../test/mockEd';
import type { EnrichmentObject } from '../types';

describe('<EditorPreview />', () => {
it('renders nothing when there is no content (negative)', () => {
Expand Down Expand Up @@ -32,66 +33,82 @@ describe('<EditorPreview />', () => {
expect(container.querySelector('iframe')).toHaveAttribute('src', '/preview.html?foo=1&webview=true');
});

it('renders the iframe immediately for non-video content regardless of transcriptsChecked', () => {
const ed = makeEd({ content: mockContent, transcriptsChecked: false }); // mockContent is application/pdf
it('renders the iframe immediately for non-video content regardless of enrichmentsChecked', () => {
const ed = makeEd({ content: mockContent, enrichmentsChecked: false }); // mockContent is application/pdf
const { container } = render(<EditorPreview ed={ed} context={mockContext} />);
expect(container.querySelector('iframe')).toBeInTheDocument();
});

it('shows a loading state instead of the iframe for video content until transcripts have been checked at least once (negative)', () => {
it('shows a loading state instead of the iframe for video content until enrichments have been checked at least once (negative)', () => {
const videoContent = { ...mockContent, mimeType: 'video/mp4' };
const ed = makeEd({ content: videoContent, transcriptsChecked: false, transcripts: [] });
const ed = makeEd({ content: videoContent, enrichmentsChecked: false, enrichmentObjects: [] });
const { container } = render(<EditorPreview ed={ed} context={mockContext} />);
expect(container.querySelector('iframe')).not.toBeInTheDocument();
expect(container.querySelector('.ce-spinner')).toBeInTheDocument();
});

it('renders the iframe for video content once transcriptsChecked is true, even with zero transcripts', () => {
it('renders the iframe for video content once enrichmentsChecked is true, even with zero objects', () => {
const videoContent = { ...mockContent, mimeType: 'video/mp4' };
const ed = makeEd({ content: videoContent, transcriptsChecked: true, transcripts: [] });
const ed = makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: [] });
const { container } = render(<EditorPreview ed={ed} context={mockContext} />);
expect(container.querySelector('iframe')).toBeInTheDocument();
});

it('does not treat a transcript with no status as Live (negative)', () => {
const videoContent = { ...mockContent, mimeType: 'video/mp4' };
const ed1 = makeEd({
content: videoContent,
transcriptsChecked: true,
transcripts: [{ code: 'c_en', language: 'English', languageCode: 'en', captionsUrl: 'https://x/en.vtt' }], // no status
});
const noStatus = { identifier: 't_en', enrichmentObjectType: 'Transcript', parentId: 'do_1', language: 'English', languageCode: 'en', captionsUrl: 'https://x/en.vtt' } as unknown as EnrichmentObject;
const ed1 = makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: [noStatus] });
const { container, rerender } = render(<EditorPreview ed={ed1} context={mockContext} />);
const withoutStatusIframe = container.querySelector('iframe');

const ed2 = makeEd({
content: videoContent,
transcriptsChecked: true,
transcripts: [],
});
const ed2 = makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: [] });
rerender(<EditorPreview ed={ed2} context={mockContext} />);
const emptyIframe = container.querySelector('iframe');
// Same remount key either way, since a status-less entry must be excluded just like an empty list.
expect(emptyIframe).toBe(withoutStatusIframe);
// Same remount key either way, since a status-less object must be excluded just like an empty list.
expect(container.querySelector('iframe')).toBe(withoutStatusIframe);
});

it('remounts the iframe (new DOM node) when the live-caption set changes at equal length', () => {
it('remounts the iframe (new DOM node) when the Live set changes at equal length', () => {
const videoContent = { ...mockContent, mimeType: 'video/mp4' };
const ed1 = makeEd({
content: videoContent,
transcriptsChecked: true,
transcripts: [{ code: 'c_en', language: 'English', languageCode: 'en', captionsUrl: 'https://x/en.vtt', status: 'Live' }],
const live = (identifier: string, languageCode: string): EnrichmentObject => ({
identifier, enrichmentObjectType: 'Transcript', parentId: 'do_1', status: 'Live',
language: languageCode, languageCode, captionsUrl: `https://x/${languageCode}.vtt`,
});
const ed1 = makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: [live('c_en', 'en')] });
const { container, rerender } = render(<EditorPreview ed={ed1} context={mockContext} />);
const firstIframe = container.querySelector('iframe');

const ed2 = makeEd({
content: videoContent,
transcriptsChecked: true,
transcripts: [{ code: 'c_fr', language: 'French', languageCode: 'fr', captionsUrl: 'https://x/fr.vtt', status: 'Live' }],
});
const ed2 = makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: [live('c_fr', 'fr')] });
rerender(<EditorPreview ed={ed2} context={mockContext} />);
const secondIframe = container.querySelector('iframe');
expect(secondIframe).not.toBe(firstIframe);
expect(container.querySelector('iframe')).not.toBe(firstIframe);
});

it('does not remount the iframe when a non-Live object changes (negative)', () => {
const videoContent = { ...mockContent, mimeType: 'video/mp4' };
const obj = (status: EnrichmentObject['status']): EnrichmentObject => ({
identifier: 'c_hi', enrichmentObjectType: 'Transcript', parentId: 'do_1', status,
});
const ed1 = makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: [obj('Processing')] });
const { container, rerender } = render(<EditorPreview ed={ed1} context={mockContext} />);
const firstIframe = container.querySelector('iframe');
rerender(<EditorPreview ed={makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: [obj('Failed')] })} context={mockContext} />);
expect(container.querySelector('iframe')).toBe(firstIframe);
});

it('hands only the Live transcripts to the renderer as metadata.transcripts (VTT as artifactUrl)', () => {
const videoContent = { ...mockContent, mimeType: 'video/mp4' };
const objects: EnrichmentObject[] = [
{ identifier: 't_en', enrichmentObjectType: 'Transcript', parentId: 'do_1', status: 'Live', language: 'English', languageCode: 'en', sourceLanguage: true, captionsUrl: 'https://x/en.vtt', artifactUrl: 'https://x/en.json' },
{ identifier: 't_hi', enrichmentObjectType: 'Transcript', parentId: 'do_1', status: 'Processing', language: 'Hindi', languageCode: 'hi' },
];
const { container } = render(<EditorPreview ed={makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: objects })} context={mockContext} />);
const iframe = container.querySelector('iframe')!;
const initializePreview = vi.fn();
(iframe.contentWindow as unknown as { initializePreview: typeof initializePreview }).initializePreview = initializePreview;
fireEvent.load(iframe);
expect(initializePreview).toHaveBeenCalledTimes(1);
expect(initializePreview.mock.calls[0][0].metadata.transcripts).toEqual([
{ language: 'English', identifier: 't_en', languageCode: 'en', artifactUrl: 'https://x/en.vtt', wordByWordUrl: 'https://x/en.vtt', sourceLanguage: true },
]);
});

it('hands the ECML body to the renderer as data, so a generated Dynamic Assess lesson can play (positive)', () => {
Expand Down
50 changes: 11 additions & 39 deletions src/components/EditorPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
import React, { useRef } from 'react';
import type { EditorController } from '../useEditor';
import type { ContentData, EditorContext, RawTranscript } from '../types';
import type { ContentData, EditorContext } from '../types';
import { getMimeTypeLabel, t } from '../i18n/i18n';
import { FileIcon } from '../icons';
import { isVideoMimeType } from '../constants';

interface PlayerTranscript {
language: string;
identifier: string;
languageCode: string;
artifactUrl: string;
wordByWordUrl?: string;
sourceLanguage?: boolean;
}

/** Maps raw enrichment.transcripts into the shape sunbird-video-player expects, mirroring
* the portal's ContentService mapping (artifactUrl here is the VTT, not transcript.json).
* Requires an explicit 'Live' status - a missing status is treated the same safe way
* TranscriptsDrawer.statusTone does (not-yet-approved), never served as a live caption. */
function mapRawTranscripts(raw: RawTranscript[]): PlayerTranscript[] {
return raw
.filter((e): e is RawTranscript & { captionsUrl: string } =>
!!e.captionsUrl && e.status === 'Live')
.map((e) => ({
language: e.language || (e.languageCode || 'Unknown').toUpperCase(),
identifier: e.code ?? e.identifier ?? '',
languageCode: e.languageCode || '',
artifactUrl: e.captionsUrl,
wordByWordUrl: e.captionsUrl,
sourceLanguage: !!e.sourceLanguage,
}));
}
import { applyEnrichments, enrichmentTypesForMime } from '../services/enrichment/registry';

/** The ECML renderer reads the lesson from `data` (as the portal's EcmlPlayerService passes metadata.body); the API returns the body JSON-stringified. */
export function rendererData(body: unknown): unknown {
Expand Down Expand Up @@ -87,16 +60,15 @@ const RendererPreview: React.FC<{
};

const EditorPreview: React.FC<{ ed: EditorController; context: EditorContext }> = ({ ed, context }) => {
const { content, lang, previewUrl, previewConfig, transcripts: rawTranscripts, transcriptsChecked } = ed;
const { content, lang, previewUrl, previewConfig, enrichmentObjects, enrichmentsChecked } = ed;

if (!content) return null;

const isVideo = isVideoMimeType(content.mimeType);
const transcripts = mapRawTranscripts(rawTranscripts);
// The iframe key changes only when the actual live-caption set changes (not just its
// count), so a same-count swap (one language leaves Live as another joins) still remounts.
const transcriptsKey = transcripts.map((tr) => tr.identifier).sort().join(',');
const previewMetadata = transcripts.length ? { ...content, transcripts } : content;
const hasEnrichments = enrichmentTypesForMime(content.mimeType).length > 0;
const previewMetadata = applyEnrichments(content, enrichmentObjects);
// The iframe key changes only when the actual Live set changes (not just its count), so a
// same-count swap (one object leaves Live as another joins) still remounts.
const enrichmentsKey = enrichmentObjects.filter((o) => o.status === 'Live').map((o) => `${o.identifier}:${String(o.captionsUrl ?? '')}`).sort().join(',');
Comment thread
chethann007 marked this conversation as resolved.
Resolved

return (
<div className="ce-preview-card">
Expand All @@ -107,8 +79,8 @@ const EditorPreview: React.FC<{ ed: EditorController; context: EditorContext }>
<span className="ce-preview-chip">{t(lang, 'PREVIEW_MODE')}</span>
</div>
<div className="ce-preview-frame">
{isVideo && !transcriptsChecked ? (
// Wait for the first transcripts check before ever mounting the renderer, so a
{hasEnrichments && !enrichmentsChecked ? (
// Wait for the first enrichments check before ever mounting the renderer, so a
// slow initial read can't yank the iframe out (and restart playback) right after
// the user presses play - by the time it first mounts, this is already settled.
<div className="ce-center" style={{ height: '100%' }}>
Expand All @@ -117,7 +89,7 @@ const EditorPreview: React.FC<{ ed: EditorController; context: EditorContext }>
) : (
<RendererPreview
// A regenerated ECML body has no new artifactUrl, so lastUpdatedOn (set by the job) is what remounts the player onto it.
key={`${content.identifier}-${content.artifactUrl ?? ''}-${transcriptsKey}${ed.isDynamicAssess ? `-${String(content.lastUpdatedOn ?? '')}` : ''}`}
key={`${content.identifier}-${content.artifactUrl ?? ''}-${enrichmentsKey}${ed.isDynamicAssess ? `-${String(content.lastUpdatedOn ?? '')}` : ''}`}
content={previewMetadata}
isDynamicAssess={ed.isDynamicAssess}
context={context}
Expand Down
22 changes: 14 additions & 8 deletions src/components/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,37 @@ describe('<Header />', () => {
expect(publish).toHaveBeenCalled();
});

it('shows "View transcript" for video content once transcripts exist, and opens the drawer', () => {
const setDrawer = vi.fn();
it('shows "View transcript" once the content has Transcript objects, and opens the drawer for that type', () => {
const openEnrichmentDrawer = vi.fn();
const ed = makeEd({
view: 'player', mode: 'edit', setDrawer, hasTranscripts: true,
view: 'player', mode: 'edit', openEnrichmentDrawer, presentEnrichmentTypes: ['Transcript'],
content: { ...mockContent, mimeType: 'video/mp4' },
});
render(<Header ed={ed} />);
fireEvent.click(screen.getByRole('button', { name: 'View transcript' }));
expect(setDrawer).toHaveBeenCalledWith('transcripts');
expect(openEnrichmentDrawer).toHaveBeenCalledWith('Transcript');
});

it('hides "View transcript" for video content with no transcripts yet (negative)', () => {
it('hides "View transcript" when no enrichment type is present (negative)', () => {
const ed = makeEd({
view: 'player', mode: 'edit', hasTranscripts: false,
view: 'player', mode: 'edit', presentEnrichmentTypes: [],
content: { ...mockContent, mimeType: 'video/mp4' },
});
render(<Header ed={ed} />);
expect(screen.queryByRole('button', { name: 'View transcript' })).not.toBeInTheDocument();
});

it('hides "View transcript" for non-video content (negative)', () => {
const ed = makeEd({ view: 'player', mode: 'edit', content: { ...mockContent, mimeType: 'application/pdf' } });
it('skips a present type that has no registry entry (negative)', () => {
const ed = makeEd({ view: 'player', mode: 'edit', presentEnrichmentTypes: ['Unknown'] });
render(<Header ed={ed} />);
expect(screen.queryByRole('button', { name: 'View transcript' })).not.toBeInTheDocument();
});

it('disables the enrichment button while busy (negative)', () => {
const ed = makeEd({ view: 'player', mode: 'edit', busy: true, presentEnrichmentTypes: ['Transcript'] });
render(<Header ed={ed} />);
expect(screen.getByRole('button', { name: 'View transcript' })).toBeDisabled();
});
});

describe('<Header /> — Regenerate (Dynamic Assess)', () => {
Expand Down
36 changes: 22 additions & 14 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import type { EditorController } from '../useEditor';
import { t } from '../i18n/i18n';
import {
ImageIcon, PencilIcon, SaveIcon, CloseIcon, SendIcon, UserPlusIcon, CheckIcon, CommentIcon, CaptionsIcon, RefreshIcon,
ImageIcon, PencilIcon, SaveIcon, CloseIcon, SendIcon, UserPlusIcon, CheckIcon, CommentIcon, RefreshIcon,
} from '../icons';
import { STATUS } from '../constants';
import { enrichmentDefinition } from '../services/enrichment/registry';
import { ENRICHMENT_UI } from './enrichment/enrichmentUi';

/** Hover hint for a disabled button: a disabled button is faded and gets no hover tooltip itself, so the hint sits on a wrapper. */
const DisabledHint: React.FC<{ hint?: string; children: React.ReactNode }> = ({ hint, children }) => (
Expand All @@ -14,12 +16,12 @@
const Header: React.FC<{ ed: EditorController }> = ({ ed }) => {
const {
content, lang, mode, setDrawer, saveDraft, close, busy, busyAction, setReviewErrors, setReviewSubmitMode,
headerLogo, hasReviewComments, hasTranscripts, isDynamicAssess, hasGeneratedBody, dynamicAssessStale,
headerLogo, hasReviewComments, presentEnrichmentTypes, openEnrichmentDrawer, isDynamicAssess, hasGeneratedBody, dynamicAssessStale,
dynamicAssessRefreshing, refreshBody,
} = ed;
const savingDraft = busyAction === 'save-draft';
const hasContent = !!content?.identifier && ed.view === 'player';
const isDraft = (content?.status ?? STATUS.DRAFT) === STATUS.DRAFT;

Check warning on line 24 in src/components/Header.tsx

View workflow job for this annotation

GitHub Actions / Lint, Build & Test

'isDraft' is assigned a value but never used
const title = content?.name || t(lang, 'UNTITLED');
const canEdit = mode === 'edit';
const isReviewer = mode === 'review';
Expand Down Expand Up @@ -72,18 +74,24 @@
</button>
)}

{hasContent && hasTranscripts && (
<button
type="button"
className="ce-icon-btn"
onClick={() => setDrawer('transcripts')}
disabled={busy}
data-tooltip={t(lang, 'VIEW_TRANSCRIPT')}
aria-label={t(lang, 'VIEW_TRANSCRIPT')}
>
<CaptionsIcon size={16} />
</button>
)}
{hasContent && presentEnrichmentTypes.map((type) => {
const def = enrichmentDefinition(type);
const ui = ENRICHMENT_UI[type];
if (!def || !ui) return null;
return (
<button
key={type}
type="button"
className="ce-icon-btn"
onClick={() => openEnrichmentDrawer(type)}
disabled={busy}
data-tooltip={t(lang, def.headerLabelKey)}
aria-label={t(lang, def.headerLabelKey)}
>
<ui.icon size={16} />
</button>
);
})}

{canEdit && !isReviewer && hasReviewComments && (
<button
Expand Down
Loading
Loading