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

Collapsible sections #461

Merged
merged 3 commits into from
Dec 19, 2024
Merged

Collapsible sections #461

merged 3 commits into from
Dec 19, 2024

Conversation

krugazul
Copy link
Collaborator

@krugazul krugazul commented Dec 19, 2024

this is a draft, do not review yet.

Summary by CodeRabbit


Release Notes:

  • New Feature: Enhanced the readMoreSet function in custom.js to accept a limit parameter, allowing for more flexible control over content visibility.
  • Refactor: Updated the calls to readMoreSet across the codebase to utilize the new limit functionality, improving content display management.
  • New Feature: Introduced functions for rendering custom blocks, handling post connections and metadata, and rendering permalinks within specific block types in class-bindings.php, expanding the capabilities of block management.
  • Chore: Removed the 'Update URI' field from the plugin header in tour-operator.php for cleaner code structure.

@krugazul krugazul added this to the 2.0.0 milestone Dec 19, 2024
@krugazul krugazul self-assigned this Dec 19, 2024
Copy link

github-actions bot commented Dec 19, 2024

Image description CodeRabbit

Walkthrough

This update introduces enhancements to the lsx_to.readMoreSet function, allowing it to accept a limit parameter for content display. It also includes new functions for rendering custom blocks and handling post connections and metadata. Additionally, the 'Update URI' field has been removed from the plugin header in the PHP file.

Changes

File(s) Summary
assets/js/src/custom.js, includes/classes/blocks/class-bindings.php The lsx_to.readMoreSet function now accepts an additional parameter limit. The calls to this function have been updated to pass a limit of 2. New functions have been added for rendering custom blocks, handling post connections, and metadata.
tour-operator.php Removed the 'Update URI' field from the plugin header.

🐇💻

Code changes here and there,

Enhancements made with care.

Limit set, blocks rendered new,

Connections handled, metadata too.

No more 'Update URI' in sight,

Cleaned up code, oh so light!

Celebrate these changes we must,

In code rabbit, place your trust! 🎉🥕


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 0ac589f and e07f729 commits.
Files selected (4)
  • assets/js/blocks/general.js (2)
  • assets/js/src/custom.js (2)
  • includes/classes/blocks/class-bindings.php (7)
  • tour-operator.php (1)
Files not summarized due to errors (1)
  • assets/js/blocks/general.js (diff tokens exceeds limit)
Files skipped from review due to trivial changes (2)
  • tour-operator.php
  • assets/js/blocks/general.js (diff too large)
Review comments generated (9)
  • Review: 6
  • LGTM: 3

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +72 to 74
lsx_to.readMoreSet = function( button, contentWrapper, limit = 1 ) {
if ( 0 < contentWrapper.length ) {
if ( 1 < contentWrapper.children().length ) {

Choose a reason for hiding this comment

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

Image description CodeRabbit

The change from a fixed limit to a parameterized limit in the lsx_to.readMoreSet function is a good improvement for flexibility. However, it's important to ensure that all calls to this function have been updated with the new parameter across the codebase. If not, it could lead to unexpected behavior.

- lsx_to.readMoreSet = function( button, contentWrapper ) {
+ lsx_to.readMoreSet = function( button, contentWrapper, limit = 1 ) {

Comment on lines +118 to +126
lsx_to.readMoreSet( $(this).find('a'), $(this).closest( '.additional-info' ).find('.content'), 2 );
} );

$( '.single-tour-operator .additional-info .lsx-to-more-link' ).on( 'click', function( event ) {
event.preventDefault();
$( this ).hide();

if ( $( this ).find('a').hasClass( 'less-link' ) ) {
lsx_to.readMoreSet( $(this).find('a'), $(this).closest( '.additional-info' ).find('.content') );
lsx_to.readMoreSet( $(this).find('a'), $(this).closest( '.additional-info' ).find('.content'), 2 );

Choose a reason for hiding this comment

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

Image description CodeRabbit

The changes here reflect the update in the function signature of lsx_to.readMoreSet. The hardcoded limit of '2' is now passed as an argument. This seems fine as long as the limit '2' is the desired behavior in all these cases.

- lsx_to.readMoreSet( $(this).find('a'), $(this).closest( '.additional-info' ).find('.content') );
+ lsx_to.readMoreSet( $(this).find('a'), $(this).closest( '.additional-info' ).find('.content'), 2 );

Comment on lines +431 to +443
/**
* Renders the units block with custom content.
*
* This function processes the block content by checking if it belongs to a specific
* custom block variation and then iteratively builds the units content based on
* predefined fields and templates. It returns the final rendered block content.
*
* @param string $block_content The original content of the block.
* @param array $parsed_block Parsed data for the block, including type and attributes.
* @param object $block_obj Block object instance for the current block being processed.
*
* @return string Returns the modified block content after processing units data.
*/

Choose a reason for hiding this comment

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

Image description CodeRabbit

The function render_units_block checks if $parsed_block['blockName'] and $parsed_block['attrs'] are set but does not handle the case where they might be empty. This could lead to unexpected behavior. Consider adding a check for empty values as well.

- 		if ( ! isset( $parsed_block['blockName'] ) || ! isset( $parsed_block['attrs'] )  ) {
+ 		if ( ! isset( $parsed_block['blockName'] ) || empty($parsed_block['blockName']) || ! isset( $parsed_block['attrs'] ) || empty($parsed_block['attrs']) ) {

Comment on lines +624 to +636
/**
* Renders the gallery block with custom content.
*
* This function processes the block content by checking if it belongs to a specific
* custom block variation and then iteratively builds the gallery content based on
* predefined fields and templates. It returns the final rendered block content.
*
* @param string $block_content The original content of the block.
* @param array $parsed_block Parsed data for the block, including type and attributes.
* @param object $block_obj Block object instance for the current block being processed.
*
* @return string Returns the modified block content after processing gallery data.
*/

Choose a reason for hiding this comment

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

Image description CodeRabbit

Similar to the previous comment, consider adding a check for empty values in the render_gallery_block function.

- 		if ( ! isset( $parsed_block['blockName'] ) || ! isset( $parsed_block['attrs'] )  ) {
+ 		if ( ! isset( $parsed_block['blockName'] ) || empty($parsed_block['blockName']) || ! isset( $parsed_block['attrs'] ) || empty($parsed_block['attrs']) ) {

Comment on lines +729 to +741
/**
* Renders the map block with custom content.
*
* This function processes the block content by checking if it belongs to a specific
* custom block variation and then iteratively builds the map content based on
* predefined fields and templates. It returns the final rendered block content.
*
* @param string $block_content The original content of the block.
* @param array $parsed_block Parsed data for the block, including type and attributes.
* @param object $block_obj Block object instance for the current block being processed.
*
* @return string Returns the modified block content after processing map data.
*/

Choose a reason for hiding this comment

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

Image description CodeRabbit

Again, consider adding a check for empty values in the render_map_block function.

- 		if ( ! isset( $parsed_block['blockName'] ) || ! isset( $parsed_block['attrs'] )  ) {
+ 		if ( ! isset( $parsed_block['blockName'] ) || empty($parsed_block['blockName']) || ! isset( $parsed_block['attrs'] ) || empty($parsed_block['attrs']) ) {

Comment on lines +806 to +842

/**
* Renders the p block with custom content.
*
* @param string $block_content The original content of the block.
* @param array $parsed_block Parsed data for the block, including type and attributes.
* @param object $block_obj Block object instance for the current block being processed.
*
* @return string Returns block with the permalink added.
*/
public function render_permalink_block( $block_content, $parsed_block, $block_obj ) {
// Determine if this is the custom block variation.
if ( ! isset( $parsed_block['blockName'] ) || ! isset( $parsed_block['attrs'] ) ) {
return $block_content;
}
$allowed_blocks = array(
'core/button'
);

if ( ! in_array( $parsed_block['blockName'], $allowed_blocks, true ) ) {
return $block_content;
}

if ( ! isset( $parsed_block['attrs']['metadata']['name'] ) ) {
return $block_content;
}

if ( 'Permalink' !== $parsed_block['attrs']['metadata']['name'] ) {
return $block_content;
}

$url = get_permalink();
$pattern = '/#permalink/s';
$block_content = preg_replace( $pattern, $url, $block_content );

return $block_content;
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

In the render_permalink_block function, you're using preg_replace to replace #permalink with the actual URL. This could potentially replace unintended parts of the content if #permalink appears elsewhere. Consider using a more specific pattern or another method to replace the placeholder.

Also, you're checking if $parsed_block['attrs']['metadata']['name'] is set but not if it's empty. Consider adding a check for empty values as well.

- 		if ( ! isset( $parsed_block['attrs']['metadata']['name'] ) ) {
+ 		if ( ! isset( $parsed_block['attrs']['metadata']['name'] ) || empty($parsed_block['attrs']['metadata']['name']) ) {
- 		$pattern       = '/#permalink/s';
+ 		$pattern       = '/^#permalink$/s'; // Adjust the pattern to match your needs

@krugazul krugazul marked this pull request as ready for review December 19, 2024 12:33
@krugazul krugazul merged commit 3687e89 into 2.0-beta-3 Dec 19, 2024
4 of 5 checks passed
@krugazul krugazul deleted the collapsible-sections branch December 19, 2024 12:33
@krugazul krugazul restored the collapsible-sections branch December 19, 2024 13:06
@ZaredRogers ZaredRogers linked an issue Jan 9, 2025 that may be closed by this pull request
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Read more block variation - Open Modals
1 participant