@@ -10,19 +10,18 @@ import {
1010 IconButton ,
1111 Stack ,
1212} from '@openedx/paragon' ;
13- import { AccessTime , ArrowForward , MoreHoriz } from '@openedx/paragon/icons' ;
13+ import { ArrowForward , MoreHoriz } from '@openedx/paragon/icons' ;
1414import { FormattedMessage , useIntl } from '@edx/frontend-platform/i18n' ;
1515import { getConfig } from '@edx/frontend-platform' ;
1616import { Link } from 'react-router-dom' ;
1717
1818import { useWaffleFlags } from '@src/data/apiHooks' ;
1919import { COURSE_CREATOR_STATES } from '@src/constants' ;
20- import { parseLibraryKey } from '@src/generic/key-utils' ;
2120import classNames from 'classnames' ;
2221import { getStudioHomeData } from '../data/selectors' ;
2322import messages from '../messages' ;
2423
25- const PrevToNextName = ( { from, to } : { from : React . ReactNode , to ?: React . ReactNode } ) => (
24+ export const PrevToNextName = ( { from, to } : { from : React . ReactNode , to ?: React . ReactNode } ) => (
2625 < Stack direction = "horizontal" gap = { 2 } >
2726 < span > { from } </ span >
2827 { to
@@ -35,7 +34,7 @@ const PrevToNextName = ({ from, to }: { from: React.ReactNode, to?: React.ReactN
3534 </ Stack >
3635) ;
3736
38- const MakeLinkOrSpan = ( {
37+ export const MakeLinkOrSpan = ( {
3938 when, to, children, className,
4039} : {
4140 when : boolean ,
@@ -54,21 +53,17 @@ interface CardTitleProps {
5453 selectMode ?: 'single' | 'multiple' ;
5554 destinationUrl : string ;
5655 title : string ;
56+ secondaryLink ?: ReactElement | null ;
5757 itemId ?: string ;
58- isMigrated ?: boolean ;
59- migratedToKey ?: string ;
60- migratedToTitle ?: string ;
6158}
6259
6360const CardTitle : React . FC < CardTitleProps > = ( {
6461 readOnlyItem,
6562 selectMode,
6663 destinationUrl,
6764 title,
65+ secondaryLink,
6866 itemId,
69- isMigrated,
70- migratedToTitle,
71- migratedToKey,
7267} ) => {
7368 const getTitle = useCallback ( ( ) => (
7469 < div style = { { marginTop : selectMode ? '-3px' : '' } } >
@@ -82,24 +77,12 @@ const CardTitle: React.FC<CardTitleProps> = ({
8277 { title }
8378 </ MakeLinkOrSpan >
8479 ) }
85- to = {
86- isMigrated && migratedToTitle && (
87- < MakeLinkOrSpan
88- when = { ! readOnlyItem && ! selectMode }
89- to = { `/library/${ migratedToKey } ` }
90- className = "card-item-title"
91- >
92- { migratedToTitle }
93- </ MakeLinkOrSpan >
94- )
95- }
80+ to = { secondaryLink }
9681 />
9782 </ div >
9883 ) , [
9984 readOnlyItem ,
100- isMigrated ,
10185 destinationUrl ,
102- migratedToTitle ,
10386 title ,
10487 selectMode ,
10588 ] ) ;
@@ -209,11 +192,10 @@ interface BaseProps {
209192 rerunLink ?: string | null ;
210193 courseKey ?: string ;
211194 isLibraries ?: boolean ;
212- isMigrated ?: boolean ;
213- migratedToKey ?: string ;
214- migratedToTitle ?: string ;
215- migratedToCollectionKey ?: string | null ;
216- subtitleBeforeComponent ?: ReactElement | null ;
195+ subtitleWrapper ?: ( ( subtitle : JSX . Element ) => ReactElement ) | null ; // Wrapper for the default subtitle element
196+ subtitleBeforeWidget ?: ReactElement | null ; // Adds a widget before the default subtitle element
197+ cardStatusWidget ?: ReactElement | null ;
198+ titleSecondaryLink ?: ReactElement | null ;
217199 selectMode ?: 'single' | 'multiple' ;
218200 selectPosition ?: 'card' | 'title' ;
219201 isSelected ?: boolean ;
@@ -234,7 +216,7 @@ type Props = BaseProps & (
234216/**
235217 * A card on the Studio home page that represents a Course or a Library
236218 */
237- const CardItem : React . FC < Props > = ( {
219+ export const CardItem : React . FC < Props > = ( {
238220 displayName,
239221 onClick,
240222 lmsLink = '' ,
@@ -250,14 +232,12 @@ const CardItem: React.FC<Props> = ({
250232 itemId = '' ,
251233 path,
252234 url,
253- isMigrated = false ,
254- migratedToKey,
255- migratedToTitle,
256- migratedToCollectionKey,
257- subtitleBeforeComponent,
235+ subtitleWrapper,
236+ subtitleBeforeWidget,
237+ titleSecondaryLink,
238+ cardStatusWidget,
258239 scrollIntoView = false ,
259240} ) => {
260- const intl = useIntl ( ) ;
261241 const {
262242 allowCourseReruns,
263243 courseCreatorStatus,
@@ -280,33 +260,19 @@ const CardItem: React.FC<Props> = ({
280260
281261 const getSubtitle = useCallback ( ( ) => {
282262 let subtitle = isLibraries ? < > { org } / { number } </ > : < > { org } / { number } / { run } </ > ;
283- if ( isMigrated && migratedToKey ) {
284- const migratedToKeyObj = parseLibraryKey ( migratedToKey ) ;
285- subtitle = (
286- < PrevToNextName
287- from = { subtitle }
288- to = { < > { migratedToKeyObj . org } / { migratedToKeyObj . lib } </ > }
289- />
290- ) ;
263+ if ( subtitleWrapper ) {
264+ subtitle = subtitleWrapper ( subtitle ) ;
291265 }
292- if ( subtitleBeforeComponent ) {
266+ if ( subtitleBeforeWidget ) {
293267 subtitle = (
294268 < Stack direction = "horizontal" gap = { 2 } >
295- { subtitleBeforeComponent }
269+ { subtitleBeforeWidget }
296270 { subtitle }
297271 </ Stack >
298272 ) ;
299273 }
300274 return subtitle ;
301- } , [ isLibraries , org , number , run , migratedToKey , isMigrated ] ) ;
302-
303- const collectionLink = ( ) => {
304- let libUrl = `/library/${ migratedToKey } ` ;
305- if ( migratedToCollectionKey ) {
306- libUrl += `/collection/${ migratedToCollectionKey } ` ;
307- }
308- return libUrl ;
309- } ;
275+ } , [ isLibraries , org , number , run ] ) ;
310276
311277 useEffect ( ( ) => {
312278 /* istanbul ignore next */
@@ -332,9 +298,7 @@ const CardItem: React.FC<Props> = ({
332298 destinationUrl = { destinationUrl }
333299 title = { title }
334300 itemId = { itemId }
335- isMigrated = { isMigrated }
336- migratedToTitle = { migratedToTitle }
337- migratedToKey = { migratedToKey }
301+ secondaryLink = { titleSecondaryLink }
338302 />
339303 ) }
340304 subtitle = { getSubtitle ( ) }
@@ -353,27 +317,12 @@ const CardItem: React.FC<Props> = ({
353317 />
354318 ) }
355319 />
356- { isMigrated && migratedToKey
357- && (
320+ { cardStatusWidget && (
358321 < Card . Status className = "bg-white pt-0 text-gray-500" >
359- < Stack direction = "horizontal" gap = { 2 } >
360- < Icon src = { AccessTime } size = "sm" className = "mb-1" />
361- { intl . formatMessage ( messages . libraryMigrationStatusText ) }
362- < b >
363- < MakeLinkOrSpan
364- when = { ! readOnlyItem }
365- to = { collectionLink ( ) }
366- className = "text-info-500"
367- >
368- { migratedToTitle }
369- </ MakeLinkOrSpan >
370- </ b >
371- </ Stack >
322+ { cardStatusWidget }
372323 </ Card . Status >
373- ) }
324+ ) }
374325 </ Card >
375326 </ div >
376327 ) ;
377328} ;
378-
379- export default CardItem ;
0 commit comments