Skip to content

Commit 4af212b

Browse files
committed
refactor: container children types
1 parent 19f4204 commit 4af212b

3 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/library-authoring/containers/ContainerRemover.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ describe('<ContainerRemover />', () => {
5959
({ axiosMock } = initializeMocks());
6060
});
6161

62-
afterEach(() => {
63-
jest.clearAllMocks();
64-
axiosMock.restore();
65-
});
66-
6762
it('triggers update container children api call when duplicates are present', async () => {
6863
const user = userEvent.setup();
6964
const url = getLibraryContainerChildrenApiUrl(mockGetContainerChildren.unitIdWithDuplicate);

src/library-authoring/data/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,10 @@ export async function restoreContainer(containerId: string) {
702702
/**
703703
* Fetch a library container's children's metadata.
704704
*/
705-
export async function getLibraryContainerChildren<T>(
705+
export async function getLibraryContainerChildren<ChildType = LibraryBlockMetadata | Container>(
706706
containerId: string,
707707
published: boolean = false,
708-
): Promise<T[]> {
708+
): Promise<ChildType[]> {
709709
const { data } = await getAuthenticatedHttpClient().get(
710710
getLibraryContainerChildrenApiUrl(containerId, published),
711711
);

src/library-authoring/data/apiHooks.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,15 +736,18 @@ export const useRestoreContainer = (containerId: string) => {
736736
/**
737737
* Get the metadata and children for a container in a library
738738
*/
739-
export const useContainerChildren = <T extends { id: string, isNew?: boolean }>(
740-
containerId?: string,
741-
published: boolean = false,
742-
) => (
739+
export const useContainerChildren = <ChildType extends {
740+
id: string;
741+
isNew?: boolean;
742+
} = api.LibraryBlockMetadata | api.Container>(
743+
containerId?: string,
744+
published: boolean = false,
745+
) => (
743746
useQuery({
744747
enabled: !!containerId,
745748
queryKey: libraryAuthoringQueryKeys.containerChildren(containerId!),
746-
queryFn: () => api.getLibraryContainerChildren<T>(containerId!, published),
747-
structuralSharing: (oldData: T[], newData: T[]) => {
749+
queryFn: () => api.getLibraryContainerChildren<ChildType>(containerId!, published),
750+
structuralSharing: (oldData: ChildType[], newData: ChildType[]) => {
748751
// This just sets `isNew` flag to new children components
749752
if (oldData) {
750753
const oldDataIds = oldData.map((obj) => obj.id);

0 commit comments

Comments
 (0)