diff --git a/README.md b/README.md index 277e6bc..7adfcd7 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/package-lock.json b/package-lock.json index 018f84c..6594b75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@project-sunbird/generic-editor-v2", - "version": "2.0.7", + "version": "2.0.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@project-sunbird/generic-editor-v2", - "version": "2.0.7", + "version": "2.0.8", "dependencies": { "jszip": "^3.10.1" }, @@ -95,6 +95,7 @@ "integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.29.7", "@babel/generator": "^7.29.7", @@ -444,6 +445,7 @@ } ], "license": "MIT", + "peer": true, "engines": { "node": ">=18" }, @@ -467,6 +469,7 @@ } ], "license": "MIT", + "peer": true, "engines": { "node": ">=18" } @@ -2245,8 +2248,7 @@ "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz", "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@types/babel__core": { "version": "7.20.5", @@ -2338,6 +2340,7 @@ "integrity": "sha512-vfEqpXTvwT91yhmwdfouStN2hSKwTvyRs8qpLfADyrq/kxDw0hZM7Wk9Ug1FELj8hIby+S/+kQCSRFF32nv2Qw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/prop-types": "*", "csstype": "^3.2.2" @@ -2349,6 +2352,7 @@ "integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==", "dev": true, "license": "MIT", + "peer": true, "peerDependencies": { "@types/react": "^18.0.0" } @@ -2398,6 +2402,7 @@ "integrity": "sha512-sPhE4iHuJDSvoAiec+Ro8JyXw8f0ql13HFR82P99nCm9GwTEKG0KYLvDe6REk8BCXuit6vJAv/Yxg5ABaNS2rA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.62.1", "@typescript-eslint/types": "8.62.1", @@ -2891,6 +2896,7 @@ "integrity": "sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -2981,7 +2987,6 @@ "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=8" } @@ -3095,6 +3100,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.10.38", "caniuse-lite": "^1.0.30001799", @@ -3463,8 +3469,7 @@ "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/dunder-proto": { "version": "1.0.1", @@ -3628,6 +3633,7 @@ "integrity": "sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -4428,6 +4434,7 @@ "integrity": "sha512-8i7LzZj7BF8uplX+ZyOlIz86V6TAsSs+np6m1kpW9u0JWi4z/1t+FzcK1aek+ybTnAC4KhBL4uXCNT0wcUIeCw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "cssstyle": "^4.1.0", "data-urls": "^5.0.0", @@ -4652,7 +4659,6 @@ "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==", "dev": true, "license": "MIT", - "peer": true, "bin": { "lz-string": "bin/bin.js" } @@ -5046,7 +5052,6 @@ "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "ansi-regex": "^5.0.1", "ansi-styles": "^5.0.0", @@ -5062,7 +5067,6 @@ "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=10" }, @@ -5109,6 +5113,7 @@ "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "loose-envify": "^1.1.0" }, @@ -5122,6 +5127,7 @@ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "loose-envify": "^1.1.0", "scheduler": "^0.23.2" @@ -5135,8 +5141,7 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/react-refresh": { "version": "0.17.0", @@ -5239,6 +5244,7 @@ "integrity": "sha512-RFnrW4lhXA3s3eqHDZvN654g8OTjzRfqpIRJYczCGB6HzphckVAi/Qh4tbPUbRuDi7s1Llv8g/NspLkttY3gTA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/estree": "1.0.9" }, @@ -5304,6 +5310,7 @@ "integrity": "sha512-OL3GoQyoUdDt843DpVmDO6y2k1sc5IhUDSpu8XucEI+35neq5QivZ1iuegnpraEVTJXlQGK1gl27zKcTLEPbQw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "chokidar": "^5.0.0", "immutable": "^5.1.5", @@ -5669,6 +5676,7 @@ "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -5771,6 +5779,7 @@ "integrity": "sha512-NTKlcQjlAK7MlQoyb6LgaqHc8sso/pVyUJYWMws3jg21uTJw/LddqIFPcPqP6PzpgbIcZyKI85sFE4HBrQDA8A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.4.4", diff --git a/package.json b/package.json index fcf256c..658b4c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@project-sunbird/generic-editor-v2", - "version": "2.0.7", + "version": "2.0.8", "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", @@ -49,4 +49,4 @@ "vite-plugin-dts": "^4.5.4", "vitest": "^3.2.6" } -} \ No newline at end of file +} diff --git a/src/ContentEditor.tsx b/src/ContentEditor.tsx index bc79e02..624152c 100644 --- a/src/ContentEditor.tsx +++ b/src/ContentEditor.tsx @@ -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'; @@ -69,7 +69,7 @@ const ContentEditor: React.FC = (props) => { - + diff --git a/src/components/Drawer.tsx b/src/components/Drawer.tsx index db99ff6..650ab16 100644 --- a/src/components/Drawer.tsx +++ b/src/components/Drawer.tsx @@ -12,19 +12,24 @@ interface DrawerProps { closeLabel?: string; /** Extra class on the root, e.g. for a drawer-specific scoped theme override. */ className?: string; + /** Optional control shown in the header, left of the close button. */ + headerAction?: React.ReactNode; } /** Slide-in drawer (right in LTR, left in RTL). Always mounted so the transform transition runs. */ -const Drawer: React.FC = ({ open, onClose, titleIcon, title, footer, children, closeLabel = 'Close', className }) => ( +const Drawer: React.FC = ({ open, onClose, titleIcon, title, footer, children, closeLabel = 'Close', className, headerAction }) => (
{titleIcon}

{title}

- +
+ {headerAction} + +
{children}
{footer &&
{footer}
} diff --git a/src/components/EditorPreview.test.tsx b/src/components/EditorPreview.test.tsx index 3d51eb1..4c2edba 100644 --- a/src/components/EditorPreview.test.tsx +++ b/src/components/EditorPreview.test.tsx @@ -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('', () => { it('renders nothing when there is no content (negative)', () => { @@ -32,66 +33,94 @@ describe('', () => { 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(); 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(); 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(); 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(); const withoutStatusIframe = container.querySelector('iframe'); - const ed2 = makeEd({ - content: videoContent, - transcriptsChecked: true, - transcripts: [], - }); + const ed2 = makeEd({ content: videoContent, enrichmentsChecked: true, enrichmentObjects: [] }); rerender(); - 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('does not remount when a Live object without a caption URL appears (negative)', () => { + const videoContent = { ...mockContent, mimeType: 'video/mp4' }; + const withUrl = { identifier: 't_en', enrichmentObjectType: 'Transcript', parentId: 'do_1', status: 'Live', captionsUrl: 'https://x/en.vtt' } as EnrichmentObject; + const noUrl = { identifier: 't_hi', enrichmentObjectType: 'Transcript', parentId: 'do_1', status: 'Live' } as EnrichmentObject; + const { container, rerender } = render( + , + ); + const first = container.querySelector('iframe'); + rerender(); + expect(container.querySelector('iframe')).toBe(first); }); - 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(); 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(); - 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(); + const firstIframe = container.querySelector('iframe'); + rerender(); + 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(); + 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)', () => { diff --git a/src/components/EditorPreview.tsx b/src/components/EditorPreview.tsx index 473272b..3a08555 100644 --- a/src/components/EditorPreview.tsx +++ b/src/components/EditorPreview.tsx @@ -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 { @@ -87,16 +60,16 @@ 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); + // Keyed on what the player actually receives (Live objects with a caption URL), so a change it can't show never restarts playback. + // A same-count swap (one object leaves as another joins) still changes the key and remounts. + const enrichmentsKey = ((previewMetadata.transcripts ?? []) as { identifier: string; artifactUrl: string }[]) + .map((tr) => `${tr.identifier}:${tr.artifactUrl}`).sort().join(','); return (
@@ -107,8 +80,8 @@ const EditorPreview: React.FC<{ ed: EditorController; context: EditorContext }> {t(lang, 'PREVIEW_MODE')}
- {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.
@@ -117,7 +90,7 @@ const EditorPreview: React.FC<{ ed: EditorController; context: EditorContext }> ) : ( ', () => { 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(
); 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(
); 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(
); 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(
); + expect(screen.getByRole('button', { name: 'View transcript' })).toBeDisabled(); + }); }); describe('
— Regenerate (Dynamic Assess)', () => { diff --git a/src/components/Header.tsx b/src/components/Header.tsx index a0a9f25..0ba5a45 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -2,9 +2,11 @@ import React from 'react'; 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 }) => ( @@ -14,7 +16,7 @@ const DisabledHint: React.FC<{ hint?: string; children: React.ReactNode }> = ({ 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'; @@ -72,18 +74,24 @@ const Header: React.FC<{ ed: EditorController }> = ({ ed }) => { )} - {hasContent && hasTranscripts && ( - - )} + {hasContent && presentEnrichmentTypes.map((type) => { + const def = enrichmentDefinition(type); + const ui = ENRICHMENT_UI[type]; + if (!def || !ui) return null; + return ( + + ); + })} {canEdit && !isReviewer && hasReviewComments && ( -
-
{activeLang!.language}
- {pendingExpectedStatus ? ( - // Once the user has acted, don't keep showing "Needs review" (as if nothing - // happened) while we wait for the server to catch up - show a neutral pending state instead. - - {t(lang, 'STATUS_UPDATING')} - - ) : ( - - {statusLabel(lang, activeLang!.status)} - - )} -
- {tone === 'review' && !isEditingSegments && !pendingExpectedStatus && ( -
- - -
- )} - {actionError && ( -
-

{actionError}

- {pendingExpectedStatus && ( - - )} -
- )} - {canShowEditControls && ( -
- {isEditingSegments ? ( - <> - - - - ) : ( - - )} -
- )} - {saveError &&

{saveError}

} - {segmentsLoading ? ( -
-
-
- ) : segmentsError || !displaySegments ? ( -

{t(lang, 'SEGMENTS_LOAD_ERROR')}

- ) : ( -
- {displaySegments.map((seg, i) => ( -
- {(seg.start != null || seg.end != null) && ( - - {formatTimestamp(seg.start)}{seg.end != null ? `–${formatTimestamp(seg.end)}` : ''} - - )} - {isEditingSegments ? ( -