|
1 | | -import { useState } from 'react'; |
| 1 | +import { useMemo, useState } from 'react'; |
2 | 2 | import { Helmet } from 'react-helmet'; |
3 | 3 | import { useNavigate } from 'react-router-dom'; |
4 | 4 | import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; |
5 | 5 | import { |
6 | | - ActionRow, Button, Container, Layout, Stepper, |
| 6 | + ActionRow, Button, Chip, Container, Layout, Stepper, |
7 | 7 | } from '@openedx/paragon'; |
8 | 8 |
|
9 | | -import { CoursesList } from '@src/studio-home/tabs-section/courses-tab'; |
| 9 | +import { CoursesList, MigrationStatusProps } from '@src/studio-home/tabs-section/courses-tab'; |
10 | 10 | import { useStudioHome } from '@src/studio-home/hooks'; |
11 | 11 | import { useLibraryContext } from '@src/library-authoring/common/context/LibraryContext'; |
12 | 12 | import Loading from '@src/generic/Loading'; |
13 | 13 |
|
14 | 14 | import Header from '@src/header'; |
15 | 15 | import SubHeader from '@src/generic/sub-header/SubHeader'; |
| 16 | +import { useMigrationInfo } from '@src/library-authoring/data/apiHooks'; |
16 | 17 | import { ReviewImportDetails } from './ReviewImportDetails'; |
17 | 18 | import messages from '../messages'; |
18 | 19 | import { HelpSidebar } from '../HelpSidebar'; |
19 | 20 |
|
20 | 21 | type MigrationStep = 'select-course' | 'review-details'; |
21 | 22 |
|
| 23 | +export const MigrationStatus = ({ |
| 24 | + courseId, |
| 25 | + allVisibleCourseIds, |
| 26 | +}: MigrationStatusProps) => { |
| 27 | + const { libraryId } = useLibraryContext(); |
| 28 | + |
| 29 | + const { |
| 30 | + data: migrationInfoData, |
| 31 | + } = useMigrationInfo(allVisibleCourseIds); |
| 32 | + |
| 33 | + const processedMigrationInfo = useMemo(() => { |
| 34 | + const result = {}; |
| 35 | + if (migrationInfoData) { |
| 36 | + for (const libraries of Object.values(migrationInfoData)) { |
| 37 | + // The map key in `migrationInfoData` is in camelCase. |
| 38 | + // In the processed map, we use the key in its original form. |
| 39 | + result[libraries[0].sourceKey] = libraries.map(item => item.targetKey); |
| 40 | + } |
| 41 | + } |
| 42 | + return result; |
| 43 | + }, [migrationInfoData]); |
| 44 | + |
| 45 | + const isPreviouslyMigrated = ( |
| 46 | + courseId in processedMigrationInfo && processedMigrationInfo[courseId].includes(libraryId) |
| 47 | + ); |
| 48 | + |
| 49 | + if (!isPreviouslyMigrated) { |
| 50 | + return null; |
| 51 | + } |
| 52 | + |
| 53 | + return ( |
| 54 | + <div |
| 55 | + key={`${courseId}-${processedMigrationInfo[courseId].join('-')}`} |
| 56 | + className="previously-migrated-chip" |
| 57 | + > |
| 58 | + <Chip> |
| 59 | + <FormattedMessage {...messages.previouslyImported} /> |
| 60 | + </Chip> |
| 61 | + </div> |
| 62 | + ); |
| 63 | +}; |
| 64 | + |
22 | 65 | export const ImportStepperPage = () => { |
23 | 66 | const intl = useIntl(); |
24 | 67 | const navigate = useNavigate(); |
@@ -69,7 +112,7 @@ export const ImportStepperPage = () => { |
69 | 112 | <CoursesList |
70 | 113 | selectedCourseId={selectedCourseId} |
71 | 114 | handleSelect={setSelectedCourseId} |
72 | | - currentLibraryId={libraryId} |
| 115 | + cardMigrationStatusWidget={MigrationStatus} |
73 | 116 | /> |
74 | 117 | </Stepper.Step> |
75 | 118 | <Stepper.Step |
|
0 commit comments