-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable allocation of restricted runs
ENT-9411
- Loading branch information
Showing
6 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...nts/learner-credit-management/data/hooks/useCatalogContainsContentItemsMultipleQueries.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useQueries } from '@tanstack/react-query'; | ||
import { camelCaseObject } from '@edx/frontend-platform/utils'; | ||
|
||
import EnterpriseCatalogApiServiceV2 from '../../../../data/services/EnterpriseCatalogApiServiceV2'; | ||
import { learnerCreditManagementQueryKeys } from '../constants'; | ||
|
||
/** | ||
* Retrieves a response from the following enterprise-catalog endpoint for a SINGLE content key: | ||
* | ||
* /api/v2/enterprise-catalogs/{uuid}/contains_content_items/?course_run_ids={content_key} | ||
* | ||
* @param {*} queryKey The queryKey from the associated `useQuery` call. | ||
* @returns The contains_content_items response. | ||
*/ | ||
const getCatalogContainsContentItem = async ({ queryKey }) => { | ||
const catalogUuid = queryKey[2]; | ||
const contentKey = queryKey[4]; | ||
const response = await EnterpriseCatalogApiServiceV2.retrieveContainsContentItems(catalogUuid, contentKey); | ||
return camelCaseObject(response.data); | ||
}; | ||
|
||
const useCatalogContainsContentItemsMultipleQueries = (catalogUuid, contentKeys, { queryOptions } = {}) => { | ||
const multipleResults = useQueries({ | ||
queries: contentKeys.map((contentKey) => ({ | ||
queryKey: learnerCreditManagementQueryKeys.catalogContainsContentItem(catalogUuid, contentKey), | ||
queryFn: getCatalogContainsContentItem, | ||
...queryOptions, | ||
})), | ||
}); | ||
return { | ||
data: multipleResults, | ||
// If at least one query is still loading, then this whole hook is considered to be still loading. | ||
isLoading: multipleResults.some(result => result.isLoading), | ||
}; | ||
}; | ||
|
||
export default useCatalogContainsContentItemsMultipleQueries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
import { configuration } from '../../config'; | ||
|
||
class EnterpriseCatalogApiServiceV2 { | ||
static baseUrl = `${configuration.ENTERPRISE_CATALOG_BASE_URL}/api/v2`; | ||
|
||
static apiClient = getAuthenticatedHttpClient; | ||
|
||
static enterpriseCatalogsUrl = `${EnterpriseCatalogApiServiceV2.baseUrl}/enterprise-catalogs/`; | ||
|
||
/** | ||
* Retrieves the enterprise-catalog based contains_content_items endpoint for | ||
* ONE content key: | ||
* | ||
* /api/v2/enterprise-catalogs/{uuid}/contains_content_items/?course_run_ids={content_key} | ||
* | ||
* This endpoint technically supports an arbitrary number of content keys, | ||
* but this function only supports one. | ||
* | ||
* @param {*} catalogUuid The catalog to check for content inclusion. | ||
* @param {*} contentKey The content to check for inclusion in the requested catalog. | ||
*/ | ||
static retrieveContainsContentItems(catalogUuid, contentKey) { | ||
const queryParams = new URLSearchParams(); | ||
queryParams.append('course_run_ids', contentKey); | ||
const baseCatalogUrl = `${EnterpriseCatalogApiServiceV2.enterpriseCatalogsUrl}${catalogUuid}`; | ||
return EnterpriseCatalogApiServiceV2.apiClient().get( | ||
`${baseCatalogUrl}/contains_content_items/?${queryParams.toString()}`, | ||
); | ||
} | ||
} | ||
|
||
export default EnterpriseCatalogApiServiceV2; |