fix: enable publish button on library after component edit [sumac] [FC-0062] (#1447)

This PR fixes the following bug: After publishing a library then editing a component, the "Publish" button in Library Info doesn't become enabled until you refresh
Fixes: https://github.com/openedx/frontend-app-authoring/issues/1455
Backport: https://github.com/openedx/frontend-app-authoring/pull/1446
This commit is contained in:
Rômulo Penido
2024-11-04 13:56:20 -03:00
committed by GitHub
parent 81d78b9613
commit f10ad9f525

View File

@@ -113,6 +113,8 @@ export const xblockQueryKeys = {
export function invalidateComponentData(queryClient: QueryClient, contentLibraryId: string, usageKey: string) {
queryClient.invalidateQueries({ queryKey: xblockQueryKeys.xblockFields(usageKey) });
queryClient.invalidateQueries({ queryKey: xblockQueryKeys.componentMetadata(usageKey) });
// The description and display name etc. may have changed, so refresh everything in the library too:
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibrary(contentLibraryId) });
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, contentLibraryId) });
}
@@ -150,8 +152,6 @@ export const useDeleteLibraryBlock = () => {
mutationFn: deleteLibraryBlock,
onSettled: (_data, _error, variables) => {
const libraryId = getLibraryId(variables.usageKey);
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibrary(libraryId) });
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
invalidateComponentData(queryClient, libraryId, variables.usageKey);
},
});
@@ -367,11 +367,7 @@ export const useUpdateXBlockOLX = (usageKey: string) => {
mutationFn: (newOLX: string) => setXBlockOLX(usageKey, newOLX),
onSuccess: (olxFromServer) => {
queryClient.setQueryData(xblockQueryKeys.xblockOLX(usageKey), olxFromServer);
// Reload the other data for this component:
invalidateComponentData(queryClient, contentLibraryId, usageKey);
// And the description and display name etc. may have changed, so refresh everything in the library too:
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibrary(contentLibraryId) });
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, contentLibraryId) });
},
});
};