-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable allocation of restricted runs #1359
Draft
pwnage101
wants to merge
1
commit into
master
Choose a base branch
from
pwnage101/ENT-9411
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+187
−29
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
48 changes: 48 additions & 0 deletions
48
...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,48 @@ | ||
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, | ||
enabled: !!catalogUuid, | ||
...queryOptions, | ||
})), | ||
}); | ||
return { | ||
data: multipleResults.map(result => result.data), | ||
// Reproduce the above results, but in a form that is more convenient for | ||
// consumers. This only works because we can safely assume the results | ||
// from useQueries are ordered the same as its inputs. | ||
dataByContentKey: Object.fromEntries(multipleResults.map((result, i) => [contentKeys[i], result.data])), | ||
// This whole hook is considered to be still loading if at least one query | ||
// is still loading, implying either that the upstream waterfall query to | ||
// fetch the policy has not yet returned, or at least one call to | ||
// contains-content-items is still being requested. | ||
isLoading: multipleResults.length !== 0 && multipleResults.some(result => result.isLoading), | ||
isFetching: multipleResults.length !== 0 && multipleResults.some(result => result.isFetching), | ||
isError: multipleResults.length !== 0 && multipleResults.some(result => result.isError), | ||
errorByContentKey: Object.fromEntries(multipleResults.map((result, i) => [contentKeys[i], result.error])), | ||
}; | ||
}; | ||
|
||
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
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just a naming consideration; given this list technically contains restricted runs (conditionally included by catalog inclusion), I wonder if a name like
allowedCourseRuns
,unrestrictedCourseRunsForEnterpriseCustomer
, or similar might help mitigate any confusion around whether this list only contains truly unrestricted runs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I constantly face this naming issue. I hesitated to use "allowed" in this case because the purpose of the surrounding function is to determine which runs are "assignable" which could be mistaken for "allowed". Open to suggestions, or if you think "allowed" works with sufficient code comments.