Skip to content
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: include children info in xblock api #33977

Conversation

rayzhou-bit
Copy link
Contributor

@rayzhou-bit rayzhou-bit commented Dec 28, 2023

This change will send children info for when the xblock api is called with /xblock/{blockId}?fields=childrenInfo. This was created to allow the Library Content Editor Block to access the blocks of its selected library. The frontend PR can be found here: openedx/frontend-lib-content-components#411

Example:
GET http://localhost:18010/xblock/block-v1:edX+DemoX+Demo_Course+type@library_content+block@10391c53c21b4f439c1f3aed3525be89?fields=childrenInfo

returns:

{
  "children": [
    {
      "id": "block-v1:edX+DemoX+Demo_Course+type@html+block@ff2da4992821e87349f9",
      "display_name": "Text",
      "category": "html",
      "has_children": false
    }
  ]
}

@connorhaugh
Copy link
Contributor

that are selected for it.

For others reading this: You mean are its children. The "selected" word here means something else.
I'll take a look.

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't be hard-coding special cases for the library_content block, or any other XBlock type, unless it's absolutely necessary. Is there a way you can get this API to return the data you need that doesn't involve an if LibraryContentBlock conditional?

@rayzhou-bit
Copy link
Contributor Author

@kdmccormick I was looking at a _create_xblock_child but it called create_xblock_info which in turn called _create_xblock_child again. I'll have another look after lunch.

@connorhaugh
Copy link
Contributor

The way to do it would be to actually include the include_children_predicate in the request object (you will have to make a new url in the urls.py file I believe), and then have its presence dictate whether the children are included.

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small requests, then this should be good to go.

I haven't manually tested yet and there are no unit tests, so I trust you have manually tested it.

@@ -824,14 +834,16 @@ def get_block_info(
xblock,
rewrite_static_links=True,
include_ancestor_info=False,
include_child_info=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
include_child_info=False,

unused parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty, I forgot to take this back out

):
"""
metadata, data, id representation of a leaf block fetcher.
:param usage_key: A UsageKey
"""
with modulestore().bulk_operations(xblock.location.course_key):
category = getattr(xblock, "category", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
category = getattr(xblock, "category", "")

unused variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to remove this as well

Comment on lines +181 to +190
elif "childrenInfo" in fields:
xblock = get_xblock(usage_key, request.user)
children_info = _create_xblock_child_info(
xblock,
course_outline=None,
graders=None,
include_children_predicate=ALWAYS,
is_concise=True
)
return JsonResponse(children_info)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better, thanks 👍🏻

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. My only request is that when you squash & merge, please beef up your commit message a bit.

This change will send child info when the xblock api is called. This allows the Library Content Editor Block to see the blocks that are selected for it.

What is the URL of this API? Does the new info require a new query param? Where is the corresponding frontend PR? Those are the sort of questions another dev would be thinking when they read your commit.

@rayzhou-bit rayzhou-bit merged commit 594551e into feat--Library-Content-Block-Reference Jan 3, 2024
37 of 62 checks passed
@rayzhou-bit rayzhou-bit deleted the feat--include-child-info-in-xblock-api branch January 3, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants