@@ -4,10 +4,10 @@ import {
44 Alert ,
55 Breadcrumb , Button , Card , Icon , Stack ,
66} from '@openedx/paragon' ;
7- import { ArrowBack } from '@openedx/paragon/icons' ;
7+ import { ArrowBack , Add , Delete } from '@openedx/paragon/icons' ;
88import { FormattedMessage , useIntl } from '@edx/frontend-platform/i18n' ;
99
10- import { ContainerType } from '@src/generic/key-utils' ;
10+ import { ContainerType , getBlockType } from '@src/generic/key-utils' ;
1111import ErrorAlert from '@src/generic/alert-error' ;
1212import { LoadingSpinner } from '@src/generic/Loading' ;
1313import { useContainer , useContainerChildren } from '@src/library-authoring/data/apiHooks' ;
@@ -16,7 +16,9 @@ import { BoldText } from '@src/utils';
1616import ChildrenPreview from './ChildrenPreview' ;
1717import ContainerRow from './ContainerRow' ;
1818import { useCourseContainerChildren } from './data/apiHooks' ;
19- import { ContainerChild , ContainerChildBase , WithState } from './types' ;
19+ import {
20+ ContainerChild , ContainerChildBase , ContainerState , WithState ,
21+ } from './types' ;
2022import { diffPreviewContainerChildren , isRowClickable } from './utils' ;
2123import messages from './messages' ;
2224
@@ -30,6 +32,7 @@ interface Props extends ContainerInfoProps {
3032 parent : ContainerInfoProps [ ] ;
3133 onRowClick : ( row : WithState < ContainerChild > ) => void ;
3234 onBackBtnClick : ( ) => void ;
35+ state ?: ContainerState ;
3336 // This two props are used to show an alert for the changes to text components with local overrides.
3437 // They may be removed in the future.
3538 localUpdateAlertCount : number ;
@@ -43,36 +46,54 @@ const CompareContainersWidgetInner = ({
4346 upstreamBlockId,
4447 downstreamBlockId,
4548 parent,
49+ state,
4650 onRowClick,
4751 onBackBtnClick,
4852 localUpdateAlertCount,
4953 localUpdateAlertBlockName,
5054} : Props ) => {
5155 const intl = useIntl ( ) ;
5256 const { data, isError, error } = useCourseContainerChildren ( downstreamBlockId , parent . length === 0 ) ;
57+ // There is the case in which the item is removed, but it still exists
58+ // in the library, for that case, we avoid bringing the children.
5359 const {
5460 data : libData ,
5561 isError : isLibError ,
5662 error : libError ,
57- } = useContainerChildren ( upstreamBlockId , true ) ;
63+ } = useContainerChildren ( state === 'removed' ? undefined : upstreamBlockId , true ) ;
5864 const {
5965 data : containerData ,
6066 isError : isContainerTitleError ,
6167 error : containerTitleError ,
6268 } = useContainer ( upstreamBlockId ) ;
6369
6470 const result = useMemo ( ( ) => {
65- if ( ! data || ! libData ) {
71+ if ( ( ! data || ! libData ) && ! [ 'added' , 'removed' ] . includes ( state || '' ) ) {
6672 return [ undefined , undefined ] ;
6773 }
68- return diffPreviewContainerChildren ( data . children , libData as ContainerChildBase [ ] ) ;
74+
75+ return diffPreviewContainerChildren ( data ?. children || [ ] , libData as ContainerChildBase [ ] || [ ] ) ;
6976 } , [ data , libData ] ) ;
7077
7178 const renderBeforeChildren = useCallback ( ( ) => {
72- if ( ! result [ 0 ] ) {
79+ if ( ! result [ 0 ] && state !== 'added' ) {
7380 return < div className = "m-auto" > < LoadingSpinner /> </ div > ;
7481 }
7582
83+ if ( state === 'added' ) {
84+ return (
85+ < Stack className = "align-items-center justify-content-center bg-light-200 text-gray-800" >
86+ < Icon src = { Add } className = "big-icon" />
87+ < FormattedMessage
88+ { ...messages . newContainer }
89+ values = { {
90+ containerType : getBlockType ( upstreamBlockId ) ,
91+ } }
92+ />
93+ </ Stack >
94+ ) ;
95+ }
96+
7697 return result [ 0 ] ?. map ( ( child ) => (
7798 < ContainerRow
7899 key = { child . id }
@@ -87,10 +108,24 @@ const CompareContainersWidgetInner = ({
87108 } , [ result ] ) ;
88109
89110 const renderAfterChildren = useCallback ( ( ) => {
90- if ( ! result [ 1 ] ) {
111+ if ( ! result [ 1 ] && state !== 'removed' ) {
91112 return < div className = "m-auto" > < LoadingSpinner /> </ div > ;
92113 }
93114
115+ if ( state === 'removed' ) {
116+ return (
117+ < Stack className = "align-items-center justify-content-center bg-light-200 text-gray-800" >
118+ < Icon src = { Delete } className = "big-icon" />
119+ < FormattedMessage
120+ { ...messages . deletedContainer }
121+ values = { {
122+ containerType : getBlockType ( upstreamBlockId ) ,
123+ } }
124+ />
125+ </ Stack >
126+ ) ;
127+ }
128+
94129 return result [ 1 ] ?. map ( ( child ) => (
95130 < ContainerRow
96131 key = { child . id }
@@ -134,12 +169,21 @@ const CompareContainersWidgetInner = ({
134169 ) ;
135170 } , [ parent ] ) ;
136171
137- if ( isError || isLibError || isContainerTitleError ) {
172+ let beforeTitle : string | undefined | null = data ?. displayName ;
173+ let afterTitle = containerData ?. publishedDisplayName ;
174+ if ( ! data && state === 'added' ) {
175+ beforeTitle = containerData ?. publishedDisplayName ;
176+ }
177+ if ( ! containerData && state === 'removed' ) {
178+ afterTitle = data ?. displayName ;
179+ }
180+
181+ if ( isError || ( isLibError && state !== 'removed' ) || ( isContainerTitleError && state !== 'removed' ) ) {
138182 return < ErrorAlert error = { error || libError || containerTitleError } /> ;
139183 }
140184
141185 return (
142- < div className = "row justify-content-center" >
186+ < div className = "compare-changes-widget row justify-content-center" >
143187 { localUpdateAlertCount > 0 && (
144188 < Alert variant = "info" >
145189 < FormattedMessage
@@ -153,15 +197,15 @@ const CompareContainersWidgetInner = ({
153197 </ Alert >
154198 ) }
155199 < div className = "col col-6 p-1" >
156- < Card className = "p-4" >
157- < ChildrenPreview title = { getTitleComponent ( data ?. displayName ) } side = "Before" >
200+ < Card className = "compare-card p-4" >
201+ < ChildrenPreview title = { getTitleComponent ( beforeTitle ) } side = "Before" >
158202 { renderBeforeChildren ( ) }
159203 </ ChildrenPreview >
160204 </ Card >
161205 </ div >
162206 < div className = "col col-6 p-1" >
163- < Card className = "p-4" >
164- < ChildrenPreview title = { getTitleComponent ( containerData ?. publishedDisplayName ) } side = "After" >
207+ < Card className = "compare-card p-4" >
208+ < ChildrenPreview title = { getTitleComponent ( afterTitle ) } side = "After" >
165209 { renderAfterChildren ( ) }
166210 </ ChildrenPreview >
167211 </ Card >
@@ -181,12 +225,14 @@ export const CompareContainersWidget = ({
181225 isReadyToSyncIndividually = false ,
182226} : ContainerInfoProps ) => {
183227 const [ currentContainerState , setCurrentContainerState ] = useState < ContainerInfoProps & {
184- parent : ContainerInfoProps [ ] ;
228+ state ?: ContainerState ;
229+ parent :( ContainerInfoProps & { state ?: ContainerState } ) [ ] ;
185230 } > ( {
186- upstreamBlockId,
187- downstreamBlockId,
188- parent : [ ] ,
189- } ) ;
231+ upstreamBlockId,
232+ downstreamBlockId,
233+ parent : [ ] ,
234+ state : 'modified' ,
235+ } ) ;
190236
191237 const { data } = useCourseContainerChildren ( downstreamBlockId , true ) ;
192238 let localUpdateAlertBlockName = '' ;
@@ -213,9 +259,11 @@ export const CompareContainersWidget = ({
213259 setCurrentContainerState ( ( prev ) => ( {
214260 upstreamBlockId : row . id ! ,
215261 downstreamBlockId : row . downstreamId ! ,
262+ state : row . state ,
216263 parent : [ ...prev . parent , {
217264 upstreamBlockId : prev . upstreamBlockId ,
218265 downstreamBlockId : prev . downstreamBlockId ,
266+ state : prev . state ,
219267 } ] ,
220268 } ) ) ;
221269 } ;
@@ -230,6 +278,7 @@ export const CompareContainersWidget = ({
230278 return {
231279 upstreamBlockId : prevParent ! . upstreamBlockId ,
232280 downstreamBlockId : prevParent ! . downstreamBlockId ,
281+ state : prevParent ! . state ,
233282 parent : prev . parent . slice ( 0 , - 1 ) ,
234283 } ;
235284 } ) ;
@@ -240,6 +289,7 @@ export const CompareContainersWidget = ({
240289 upstreamBlockId = { currentContainerState . upstreamBlockId }
241290 downstreamBlockId = { currentContainerState . downstreamBlockId }
242291 parent = { currentContainerState . parent }
292+ state = { currentContainerState . state }
243293 onRowClick = { onRowClick }
244294 onBackBtnClick = { onBackBtnClick }
245295 localUpdateAlertCount = { localUpdateAlertCount }
0 commit comments