Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@project-sunbird/generic-editor-v2",
"version": "2.0.4",
"version": "2.0.5",
"description": "Sunbird Generic Editor — React content upload/generic editor (theme-reactive, multilingual). Fork of @sunbird/content-editor that previews via the legacy ekstep content renderer.",
"main": "dist/sunbird-generic-editor.umd.js",
"module": "dist/sunbird-generic-editor.es.js",
Expand Down
2 changes: 2 additions & 0 deletions src/ContentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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 AssetPickerModal from './components/AssetPickerModal';
import Toast from './components/Toast';
import { t } from './i18n/i18n';
Expand Down Expand Up @@ -56,6 +57,7 @@ const ContentEditor: React.FC<ContentEditorProps> = (props) => {
<CollaboratorDrawer ed={ed} />
<ReviewDrawer ed={ed} />
<ReviewCommentsDrawer ed={ed} />
<TranscriptsDrawer ed={ed} />
<AssetPickerModal ed={ed} />

<Toast toast={ed.toast} />
Expand Down
27 changes: 24 additions & 3 deletions src/components/EditorPreview.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import EditorPreview from './EditorPreview';
import { makeEd, mockContext, mockContent } from '../test/mockEd';
import { makeEd, mockContext, mockContent, mockService } from '../test/mockEd';

describe('<EditorPreview />', () => {
it('renders nothing when there is no content (negative)', () => {
Expand Down Expand Up @@ -31,4 +31,25 @@ describe('<EditorPreview />', () => {
const { container } = render(<EditorPreview ed={ed} context={mockContext} />);
expect(container.querySelector('iframe')).toHaveAttribute('src', '/preview.html?foo=1&webview=true');
});

it('does not fetch transcripts for non-video content (negative)', () => {
const service = mockService();
const ed = makeEd({ content: mockContent, service }); // mockContent is application/pdf
render(<EditorPreview ed={ed} context={mockContext} />);
expect(service.readTranscripts).not.toHaveBeenCalled();
});

it('fetches and maps transcripts for video content, remounting the iframe once they arrive', async () => {
const service = mockService({
readTranscripts: vi.fn().mockResolvedValue([
{ code: 'c_en', language: 'English', languageCode: 'en', captionsUrl: 'https://x/en.vtt', status: 'Live', sourceLanguage: true },
{ code: 'c_fr', language: 'French', languageCode: 'fr', status: 'Draft' }, // filtered: not Live
]),
});
const videoContent = { ...mockContent, mimeType: 'video/mp4' };
const ed = makeEd({ content: videoContent, service });
const { container } = render(<EditorPreview ed={ed} context={mockContext} />);
await waitFor(() => expect(service.readTranscripts).toHaveBeenCalledWith('do_1'));
await waitFor(() => expect(container.querySelector('iframe')).toBeInTheDocument());
});
});
57 changes: 52 additions & 5 deletions src/components/EditorPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
import React, { useRef } from 'react';
import React, { useRef, useEffect, useState } from 'react';
import type { EditorController } from '../useEditor';
import type { ContentData, EditorContext } from '../types';
import type { ContentData, EditorContext, RawTranscript } 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 enrichment.transcripts (raw) into the shape sunbird-video-player expects -
* mirrors the portal's ContentService.contentRead mapping exactly, since the legacy
* preview iframe's video sub-player is the same component. artifactUrl here must be
* the VTT (captionsUrl), not the raw transcript.json.
*/
function mapRawTranscripts(raw: RawTranscript[]): PlayerTranscript[] {
return raw
.filter((e): e is RawTranscript & { captionsUrl: string } =>
!!e.captionsUrl && (e.status ?? 'Live').toLowerCase() === 'live')
Comment thread
Deeksha1502 marked this conversation as resolved.
Resolved
.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,
}));
}

/**
* Preview via the legacy ekstep content renderer — the same mechanism the old
Expand Down Expand Up @@ -55,9 +85,26 @@ const RendererPreview: React.FC<{
};

const EditorPreview: React.FC<{ ed: EditorController; context: EditorContext }> = ({ ed, context }) => {
const { content, lang, previewUrl, previewConfig } = ed;
const { content, lang, previewUrl, previewConfig, service } = ed;
const [transcripts, setTranscripts] = useState<PlayerTranscript[]>([]);

useEffect(() => {
setTranscripts([]);
if (!content?.identifier || !isVideoMimeType(content.mimeType)) return;
service
.readTranscripts(content.identifier)
.then((raw) => setTranscripts(mapRawTranscripts(raw)))
.catch(() => setTranscripts([]));
}, [content?.identifier, content?.mimeType, service]);
Comment thread
Deeksha1502 marked this conversation as resolved.
Resolved

if (!content) return null;

// Merging transcripts changes content's identity without changing identifier/artifactUrl,
// so the iframe key below also folds in transcripts.length - forcing exactly one remount
// (+ one re-init) once they arrive, instead of silently never surfacing them. Acceptable
// here (unlike a live learner player) since this is the creator's own edit-time preview.
const previewMetadata = transcripts.length ? { ...content, transcripts } : content;

return (
<div className="ce-preview-card">
<div className="ce-preview-bar">
Expand All @@ -68,8 +115,8 @@ const EditorPreview: React.FC<{ ed: EditorController; context: EditorContext }>
</div>
<div className="ce-preview-frame">
<RendererPreview
key={`${content.identifier}-${content.artifactUrl ?? ''}`}
content={content}
key={`${content.identifier}-${content.artifactUrl ?? ''}-${transcripts.length}`}
Comment thread
Deeksha1502 marked this conversation as resolved.
Resolved
content={previewMetadata}
context={context}
previewUrl={previewUrl}
previewConfig={previewConfig}
Expand Down
26 changes: 26 additions & 0 deletions src/components/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,30 @@ describe('<Header />', () => {
fireEvent.click(btn);
expect(publish).toHaveBeenCalled();
});

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

it('hides "View transcript" for video content with no transcripts yet (negative)', () => {
const ed = makeEd({
view: 'player', mode: 'edit', hasTranscripts: false,
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' } });
render(<Header ed={ed} />);
expect(screen.queryByRole('button', { name: 'View transcript' })).not.toBeInTheDocument();
});
});
17 changes: 15 additions & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import type { EditorController } from '../useEditor';
import { t } from '../i18n/i18n';
import {
ImageIcon, PencilIcon, SaveIcon, CloseIcon, SendIcon, UserPlusIcon, CheckIcon, CommentIcon,
ImageIcon, PencilIcon, SaveIcon, CloseIcon, SendIcon, UserPlusIcon, CheckIcon, CommentIcon, CaptionsIcon,
} from '../icons';
import { STATUS } from '../constants';

const Header: React.FC<{ ed: EditorController }> = ({ ed }) => {
const { content, lang, mode, setDrawer, saveDraft, close, busy, busyAction, setReviewErrors, setReviewSubmitMode, headerLogo, hasReviewComments } = ed;
const { content, lang, mode, setDrawer, saveDraft, close, busy, busyAction, setReviewErrors, setReviewSubmitMode, headerLogo, hasReviewComments, hasTranscripts } = 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 13 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 @@ -61,6 +61,19 @@
</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>
)}

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