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

WIP: adding new featured content block #625

Merged
merged 18 commits into from
Jun 8, 2022

Conversation

iruzevic
Copy link
Member

@iruzevic iruzevic commented May 25, 2022

Description

  • new featured content block.
  • new layout component with 2-3-4 columns
  • new load more component

TODO:

  • featured content block
  • layout component
  • load more component
  • setup featured content preview on storybook
  • fix linters
  • test
  • fix namespace
  • make it pritty

Linked PR

This is a linked PR with libs: infinum/eightshift-libs#297

@iruzevic iruzevic added new block This is a new block request new component This is a new component request labels May 25, 2022
@iruzevic iruzevic self-assigned this May 25, 2022
@iruzevic iruzevic added this to the Next release milestone May 25, 2022
@iruzevic iruzevic marked this pull request as draft May 26, 2022 13:20
@iruzevic iruzevic requested a review from a team June 2, 2022 22:13
@iruzevic iruzevic marked this pull request as ready for review June 2, 2022 22:13
@iruzevic iruzevic modified the milestone: Minor Jun 3, 2022
Copy link
Contributor

@iobrado iobrado left a comment

Choose a reason for hiding this comment

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

This is awesome! 👏 Left some typo fixes 🙂

Copy link
Contributor

@gabriel-glo gabriel-glo 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 of things to consider.
This is so awesome.

Comment on lines 29 to 66
global $post;

$args = [
'post_type' => $featuredContentPostType,
'posts_per_page' => $featuredContentLayoutTotalItems,
'fields' => 'ids',
];

if ($featuredContentTaxonomy) {
$args['tax_query'][0] = [
'taxonomy' => $featuredContentTaxonomy,
'field' => 'id',
];

if ($featuredContentTerms) {
$args['tax_query'][0]['terms'] = array_map(
function ($item) {
return $item['value'];
},
(array)$featuredContentTerms
);
} elseif ($featuredContentUseCurrentTerm && $post instanceof WP_Post && !$featuredContentServerSideRender) {
$currentTerms = get_the_terms($post->ID, $featuredContentTaxonomy);

if ($currentTerms) {
$args['tax_query'][0]['terms'] = [$currentTerms[0]->term_id]; // @phpstan-ignore-line
}
} else {
$args['tax_query'][0]['operator'] = 'NOT IN'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
}
}

$excludeList = [];

if ($featuredContentExcludeCurrentPost && $post instanceof WP_Post) {
$excludeList[] = $post->ID;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be much better if we could have this inside a class method. Ideally this will be a filter that takes multiple arguments (as WP_Query args) and then just returns the query object in $mainQuery variable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

💯

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed but this will overcomplicate the implementation so I would like to not do that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could have a Filters folder with different filter classes that could handle this kind of logic. The implementation would just then be as in other projects (just apply_filter calls).

Copy link
Member Author

Choose a reason for hiding this comment

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

i have opened an issue #631

}

if ($excludeList) {
$args['post__not_in'] = $excludeList;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be handled inside the WP_Query loop. We'd check if current post ID is same as the one in the loop and just continue; with the loop

Copy link
Collaborator

Choose a reason for hiding this comment

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

💯

We should also check the performance impacts that the tax queries are having on huge post numbers.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, but with this approach pagination is a nightmare so In general there max 1-2 items here if any so lets not overcomplicate this for a minor optimisation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll need to really be careful about this because there are projects that have over 10k posts, and this could be a bottleneck.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, i have created an issue for this #632


const layoutUse = checkAttr('layoutUse', attributes, manifest);
const layoutType = checkAttr('layoutType', attributes, manifest);
const layoutTotalItems = checkAttr('layoutTotalItems', attributes, manifest);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This naming is a bit odd, the label says Maximum items to show, would it be better to name it layoutMaxNumberOfItems?

Copy link
Member Author

Choose a reason for hiding this comment

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

i like the keep the attribute naming as short and simple as possible. The label is here for the users. So i think this one is ok


// Prepare body data.
const body = {
method: 'POST',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fetching implies GET, not POST 😬

We should use appropriate HTTP methods for things we do with the API (or AJAX in this case).

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem here is that I send the data from frontend to backend via json format because we have multiple decoded params that can't be sent via get parameter. So this is why I was using POST

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we discussed this yesterday, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep this comment was from earlier than that :D this is resolved

Copy link
Collaborator

@dingo-d dingo-d left a comment

Choose a reason for hiding this comment

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

Left some questions and suggestions. Like the direction where this is going, but the PR is encompassing a bit more than just a featured content block.

For instance, I'd like for the layout component to be extracted in a separate PR for easier review.

You can always create branches, cherry pick, create a separate PR, then once that is merged to develop branch, just rebase the current PR. Keeps things a bit easier to review 😉

iruzevic and others added 7 commits June 6, 2022 12:15
* develop:
  adding variations to store
  updating change log
  tweak column chart icon
  add new block icons and update existing
  indent correction in css variables
  fix ssr render, indent fix for ssr
  remove console log from css-variables js
  Fix a bug in Safari for hamburger animations
  Adds media-breakpoints variable that pulls variables from global manifest.json
  add base font size calc docs, add multiple breakpoints for base font size, removed font-size in editor styles, add frontend specific font size multiplied by 100%
  add useRemBaseSize to manifest, add store manipulations of useRemBaseSize, add useRemBaseSize to manifest schema, add functionality to block generated css variables
Co-authored-by: Denis Žoljom <[email protected]>
Co-authored-by: Igor Obradović <[email protected]>
…block-featured-content

* commit '0c042623c825cb01a49abe09d51bb771d6544af4':
  Apply suggestions from code review
  Update blocks/init/src/Blocks/components/load-more/docs/readme.mdx

# Conflicts:
#	blocks/init/src/Blocks/components/layout/docs/readme.mdx
dadadavorin
dadadavorin previously approved these changes Jun 7, 2022
Copy link
Contributor

@dadadavorin dadadavorin left a comment

Choose a reason for hiding this comment

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

Awesome! 🤩

@dingo-d
Copy link
Collaborator

dingo-d commented Jun 8, 2022

Once the tests are written just squash merge this to have a cleaner commit history.

@iruzevic iruzevic merged commit 8bedad0 into develop Jun 8, 2022
@iruzevic iruzevic deleted the feature/block-featured-content branch June 8, 2022 10:04
iruzevic added a commit that referenced this pull request Jun 8, 2022
* develop:
  adding new featured content block (#625)
  adding postcss transforms
  fixing issue

# Conflicts:
#	.storybook/preview.js
#	blocks/init/storybook/preview.js
iruzevic added a commit that referenced this pull request Jun 8, 2022
* develop:
  Update packages, migrate to Webpack 5 (#595)
  adding new featured content block (#625)

# Conflicts:
#	blocks/init/storybook/preview.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new block This is a new block request new component This is a new component request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants