@@ -20,6 +20,33 @@ import { libraryAuthoringQueryKeys, libraryQueryPredicate, xblockQueryKeys } fro
2020import { getLibraryId } from '../../generic/key-utils' ;
2121import type { UpdateTagsData } from './types' ;
2222
23+ export const contentTagsQueryKeys = {
24+ all : [ 'contentTags' ] ,
25+ taxonomyTags : ( taxonomyId : number , parentTag : string | null , page : number , searchTerm : string ) => [
26+ ...contentTagsQueryKeys . all ,
27+ 'taxonomyTags' ,
28+ taxonomyId ,
29+ parentTag ,
30+ page ,
31+ searchTerm ,
32+ ] ,
33+ contentTaxonomyTags : ( contentId : string ) => [
34+ ...contentTagsQueryKeys . all ,
35+ 'contentTaxonomyTags' ,
36+ contentId ,
37+ ] ,
38+ contentData : ( contentId ?: string ) => [
39+ ...contentTagsQueryKeys . all ,
40+ 'contentData' ,
41+ contentId ,
42+ ] ,
43+ contentTagsCount : ( contentPattern : string ) => [
44+ ...contentTagsQueryKeys . all ,
45+ 'contentTagsCount' ,
46+ contentPattern ,
47+ ] ,
48+ } ;
49+
2350/**
2451 * Builds the query to get the taxonomy tags
2552 */
@@ -43,7 +70,7 @@ export const useTaxonomyTagsData = (
4370 const queries : { queryKey : any [ ] ; queryFn : typeof queryFn ; staleTime : number } [ ] = [ ] ;
4471 for ( let page = 1 ; page <= numPages ; page ++ ) {
4572 queries . push (
46- { queryKey : [ ' taxonomyTags' , taxonomyId , parentTag , page , searchTerm ] , queryFn, staleTime : Infinity } ,
73+ { queryKey : contentTagsQueryKeys . taxonomyTags ( taxonomyId , parentTag , page , searchTerm ) , queryFn, staleTime : Infinity } ,
4774 ) ;
4875 }
4976
@@ -74,7 +101,7 @@ export const useTaxonomyTagsData = (
74101
75102 // Store the pre-loaded descendants into the query cache:
76103 preLoadedData . forEach ( ( tags , parentValue ) => {
77- const queryKey = [ ' taxonomyTags' , taxonomyId , parentValue , 1 , searchTerm ] ;
104+ const queryKey = contentTagsQueryKeys . taxonomyTags ( taxonomyId , parentValue , 1 , searchTerm ) ;
78105 const cachedData : TagListData = {
79106 next : '' ,
80107 previous : '' ,
@@ -106,7 +133,7 @@ export const useTaxonomyTagsData = (
106133 */
107134export const useContentTaxonomyTagsData = ( contentId : string ) => (
108135 useQuery ( {
109- queryKey : [ ' contentTaxonomyTags' , contentId ] ,
136+ queryKey : contentTagsQueryKeys . contentTaxonomyTags ( contentId ) ,
110137 queryFn : ( ) => getContentTaxonomyTagsData ( contentId ) ,
111138 } )
112139) ;
@@ -118,7 +145,7 @@ export const useContentTaxonomyTagsData = (contentId: string) => (
118145 */
119146export const useContentData = ( contentId ?: string , enabled : boolean = true ) => (
120147 useQuery ( {
121- queryKey : [ ' contentData' , contentId ] ,
148+ queryKey : contentTagsQueryKeys . contentData ( contentId ) ,
122149 queryFn : ( enabled && contentId ) ? ( ) => getContentData ( contentId ) : skipToken ,
123150 } )
124151) ;
@@ -137,15 +164,15 @@ export const useContentTaxonomyTagsUpdater = (contentId: string) => {
137164 updateContentTaxonomyTags ( contentId , tagsData )
138165 ) ,
139166 onSettled : ( ) => {
140- queryClient . invalidateQueries ( { queryKey : [ ' contentTaxonomyTags' , contentId ] } ) ;
167+ queryClient . invalidateQueries ( { queryKey : contentTagsQueryKeys . contentTaxonomyTags ( contentId ) } ) ;
141168 /// Invalidate query with pattern on course outline
142169 let contentPattern ;
143170 if ( contentId . includes ( 'course-v1' ) ) {
144171 contentPattern = contentId ;
145172 } else {
146173 contentPattern = contentId . replace ( / \+ t y p e @ .* $ / , '*' ) ;
147174 }
148- queryClient . invalidateQueries ( { queryKey : [ ' contentTagsCount' , contentPattern ] } ) ;
175+ queryClient . invalidateQueries ( { queryKey : contentTagsQueryKeys . contentTagsCount ( contentPattern ) } ) ;
149176 if ( contentId . startsWith ( 'lb:' ) || contentId . startsWith ( 'lib-collection:' ) || contentId . startsWith ( 'lct:' ) ) {
150177 // Obtain library id from contentId
151178 const libraryId = getLibraryId ( contentId ) ;
0 commit comments