Skip to content

feat: include children info in xblock api - #33977

Merged
rayzhou-bit merged 4 commits into
feat--Library-Content-Block-Referencefrom
feat--include-child-info-in-xblock-api
Jan 3, 2024
Merged

feat: include children info in xblock api#33977
rayzhou-bit merged 4 commits into
feat--Library-Content-Block-Referencefrom
feat--include-child-info-in-xblock-api

Conversation

@rayzhou-bit

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

Copy link
Copy Markdown
Contributor

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-unsupported/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
Copy Markdown
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.

@kdmccormick kdmccormick left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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.

@kdmccormick kdmccormick left a comment

Copy link
Copy Markdown
Member

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.

xblock,
rewrite_static_links=True,
include_ancestor_info=False,
include_child_info=False,

Copy link
Copy Markdown
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
Copy Markdown
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

:param usage_key: A UsageKey
"""
with modulestore().bulk_operations(xblock.location.course_key):
category = getattr(xblock, "category", "")

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks better, thanks 👍🏻

@kdmccormick kdmccormick left a comment

Copy link
Copy Markdown
Member

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
@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