Skip to content

Commit f82f020

Browse files
committed
refactor: Pass undefined on removed state in useContainerChildren
1 parent 5c073aa commit f82f020

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

src/container-comparison/CompareContainersWidget.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ const CompareContainersWidgetInner = ({
5454
}: Props) => {
5555
const intl = useIntl();
5656
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.
5759
const {
5860
data: libData,
5961
isError: isLibError,
6062
error: libError,
61-
} = useContainerChildren(upstreamBlockId, true);
63+
} = useContainerChildren(state === 'removed' ? undefined : upstreamBlockId, true);
6264
const {
6365
data: containerData,
6466
isError: isContainerTitleError,
@@ -70,16 +72,7 @@ const CompareContainersWidgetInner = ({
7072
return [undefined, undefined];
7173
}
7274

73-
let libChildren = libData as ContainerChildBase[] || [];
74-
if (state === 'removed') {
75-
// There is the case in which the item is removed, but it still exists
76-
// in the library, in that case the query will bring its children,
77-
// but we must put it empty so that the status of all the children of
78-
// the downstream are 'removed'
79-
libChildren = [];
80-
}
81-
82-
return diffPreviewContainerChildren(data?.children || [], libChildren);
75+
return diffPreviewContainerChildren(data?.children || [], libData as ContainerChildBase[] || []);
8376
}, [data, libData]);
8477

8578
const renderBeforeChildren = useCallback(() => {

0 commit comments

Comments
 (0)