feat: container delete confirmation modal (#2145)
Update container delete confirmation modal based on #1982 and #1981
This commit is contained in:
@@ -4,6 +4,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||
const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL;
|
||||
|
||||
export const getEntityLinksByDownstreamContextUrl = () => `${getApiBaseUrl()}/api/contentstore/v2/downstreams/`;
|
||||
export const getContainerEntityLinksByDownstreamContextUrl = () => `${getApiBaseUrl()}/api/contentstore/v2/downstream-containers/`;
|
||||
|
||||
export const getEntityLinksSummaryByDownstreamContextUrl = (downstreamContextKey: string) => `${getApiBaseUrl()}/api/contentstore/v2/downstreams/${downstreamContextKey}/summary`;
|
||||
|
||||
@@ -18,9 +19,8 @@ export interface PaginatedData<T> {
|
||||
results: T,
|
||||
}
|
||||
|
||||
export interface PublishableEntityLink {
|
||||
export interface BasePublishableEntityLink {
|
||||
id: number;
|
||||
upstreamUsageKey: string;
|
||||
upstreamContextKey: string;
|
||||
upstreamContextTitle: string;
|
||||
upstreamVersion: number;
|
||||
@@ -33,6 +33,14 @@ export interface PublishableEntityLink {
|
||||
readyToSync: boolean;
|
||||
}
|
||||
|
||||
export interface PublishableEntityLink extends BasePublishableEntityLink {
|
||||
upstreamUsageKey: string;
|
||||
}
|
||||
|
||||
export interface ContainerPublishableEntityLink extends BasePublishableEntityLink {
|
||||
upstreamContainerKey: string;
|
||||
}
|
||||
|
||||
export interface PublishableEntityLinkSummary {
|
||||
upstreamContextKey: string;
|
||||
upstreamContextTitle: string;
|
||||
@@ -58,6 +66,23 @@ export const getEntityLinks = async (
|
||||
return camelCaseObject(data);
|
||||
};
|
||||
|
||||
export const getContainerEntityLinks = async (
|
||||
downstreamContextKey?: string,
|
||||
readyToSync?: boolean,
|
||||
upstreamContainerKey?: string,
|
||||
): Promise<ContainerPublishableEntityLink[]> => {
|
||||
const { data } = await getAuthenticatedHttpClient()
|
||||
.get(getContainerEntityLinksByDownstreamContextUrl(), {
|
||||
params: {
|
||||
course_id: downstreamContextKey,
|
||||
ready_to_sync: readyToSync,
|
||||
upstream_container_key: upstreamContainerKey,
|
||||
no_page: true,
|
||||
},
|
||||
});
|
||||
return camelCaseObject(data);
|
||||
};
|
||||
|
||||
export const getEntityLinksSummaryByDownstreamContext = async (
|
||||
downstreamContextKey: string,
|
||||
): Promise<PublishableEntityLinkSummary[]> => {
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import {
|
||||
useQuery,
|
||||
} from '@tanstack/react-query';
|
||||
import { getEntityLinks, getEntityLinksSummaryByDownstreamContext } from './api';
|
||||
import { getContainerEntityLinks, getEntityLinks, getEntityLinksSummaryByDownstreamContext } from './api';
|
||||
|
||||
export const courseLibrariesQueryKeys = {
|
||||
all: ['courseLibraries'],
|
||||
courseLibraries: (courseId?: string) => [...courseLibrariesQueryKeys.all, courseId],
|
||||
courseReadyToSyncLibraries: ({ courseId, readyToSync, upstreamUsageKey }: {
|
||||
courseReadyToSyncLibraries: ({
|
||||
courseId, readyToSync, upstreamUsageKey, upstreamContainerKey,
|
||||
}: {
|
||||
courseId?: string,
|
||||
readyToSync?: boolean,
|
||||
upstreamUsageKey?: string,
|
||||
upstreamContainerKey?: string,
|
||||
pageSize?: number,
|
||||
}) => {
|
||||
const key: Array<string | boolean | number> = [...courseLibrariesQueryKeys.all];
|
||||
@@ -22,6 +25,9 @@ export const courseLibrariesQueryKeys = {
|
||||
if (upstreamUsageKey !== undefined) {
|
||||
key.push(upstreamUsageKey);
|
||||
}
|
||||
if (upstreamContainerKey !== undefined) {
|
||||
key.push(upstreamContainerKey);
|
||||
}
|
||||
return key;
|
||||
},
|
||||
courseLibrariesSummary: (courseId?: string) => [...courseLibrariesQueryKeys.courseLibraries(courseId), 'summary'],
|
||||
@@ -63,3 +69,29 @@ export const useEntityLinksSummaryByDownstreamContext = (courseId?: string) => (
|
||||
enabled: courseId !== undefined,
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Hook to fetch list of publishable entity links for containers by course key.
|
||||
* (That is, get a list of the library containers used in the given course.)
|
||||
*/
|
||||
export const useContainerEntityLinks = ({
|
||||
courseId, readyToSync, upstreamContainerKey,
|
||||
}: {
|
||||
courseId?: string,
|
||||
readyToSync?: boolean,
|
||||
upstreamContainerKey?: string,
|
||||
}) => (
|
||||
useQuery({
|
||||
queryKey: courseLibrariesQueryKeys.courseReadyToSyncLibraries({
|
||||
courseId,
|
||||
readyToSync,
|
||||
upstreamContainerKey,
|
||||
}),
|
||||
queryFn: () => getContainerEntityLinks(
|
||||
courseId,
|
||||
readyToSync,
|
||||
upstreamContainerKey,
|
||||
),
|
||||
enabled: courseId !== undefined || upstreamContainerKey !== undefined || readyToSync !== undefined,
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user