[MOOSE-403] Comparison Table Block - #363
Conversation
|
|
||
| public function render_table_column_header( int $index ): string { | ||
| $subtitle = $this->get_column_subtitle( $index ); | ||
| $subtitle_markup = '' !== $subtitle |
There was a problem hiding this comment.
This is not a blocker, but we should keep an eye on such comparisons.
For some reason, AI keeps doing a lot of redundant getters/setters and uses them only in the scope of the class they defined. But the hard-to-read things like this comparison and the one below, it keeps as a ternary operation
Moreover, it doesn't re-use that logic and keeps duplication here and in lines below
There was a problem hiding this comment.
I believe both cta_markup and subtitle_markup should be a reimplemented via re-usabled methods with 2 params: tag and type of entity or full class name. Currently they are the same
| /** | ||
| * @return array<int, \Tribe\Plugin\Components\Blocks\Comparison_Row_Block_Controller> | ||
| */ | ||
| public function get_row_controllers(): array { |
There was a problem hiding this comment.
Not a bad solution but maybe we can add some "caching" here? Example:
/**
* Lazily built and cached by get_row_controllers().
*
* @var array<int, \Tribe\Plugin\Components\Blocks\Comparison_Row_Block_Controller>|null
*/
protected ?array $row_controllers = null;
public function get_row_controllers(): array {
if ( null === $this->row_controllers ) {
$this->row_controllers = $this->build_row_controllers();
}
return $this->row_controllers;
}
/**
* @return array<int, \Tribe\Plugin\Components\Blocks\Comparison_Row_Block_Controller>
*/
protected function build_row_controllers(): array {
$columns = $this->columns;
$controllers = [];
foreach ( $this->rows as $row ) {
$controllers[] = Comparison_Row_Block_Controller::factory( [
'attributes' => $row,
'columns' => $columns,
'block_classes' => 'wp-block-tribe-comparison-row',
] );
}
return $controllers;
}
What does this do/fix?
Note
Design would like to see this block in ModernPress so that's why the PR is here and not in MP Resources.
Adds a new Comparison Table block (
tribe/comparison-table) for building feature comparison matrices — pricing tiers, product plans, and similar layouts.Blocks
tribe/comparison-table— Parent block with configurable plan columns and table-wide settings.tribe/comparison-row— Child block for category rows (section headers) and feature rows (comparison cells). Uses block context to stay in sync with parent columns.Column configuration
Each plan column supports:
Cell types
Feature rows support three cell types per column:
Table settings
Editor experience
Frontend
<table>markup with accessible scroll region on desktopview.js)Backend
Comparison_Table_Block_ControllerandComparison_Row_Block_Controllerhandle server-side rendering viarender.phpcircle-check,circle-cross)Blocks_Definer.phpandtheme.jsonQA
Test Plan:
Links to relevant issues
Demo Environment:
Screenshots/video:
Pull request checklist