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: page block variables feature #2672

Merged

Conversation

neatbyte-vnobis
Copy link
Collaborator

Changes

Block variables feature

How Has This Been Tested?

Manual

Documentation

None

@Pavel910
Copy link
Collaborator

To start the review, I pulled the branch and just started the app and clicked through. It's looking really good 😃 👏

Things I noticed that I'd like us to address:

  1. On the code level, let's make this a bit more consistent: we have a blockId, but then varRef; varRef is effectively an ID, right? let's just call it that, and use id key instead of varRef. Especially since it's inside of a variables array so we know it's a variable.

CleanShot 2022-10-11 at 11 06 41

  1. Empty grid block got lost, we still need to have it for cases when users want to just drop stuff into the page sporadically.

CleanShot 2022-10-11 at 11 15 55

  1. There's an updatePage mutation being issued for every character that I type into the variable input:
CleanShot.2022-10-11.at.11.33.06.mp4

I'll submit the second part of the review through actual code review, this feedback was easier to post this way.

Copy link
Collaborator

@Pavel910 Pavel910 left a comment

Choose a reason for hiding this comment

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

Overall, this looks good. I didn't want to nitpick too much, but I just want us to address the things from my first PR comment, and that's it.

Comment on lines 288 to 322
for (const pageBlock of page.content?.elements) {
const blockId = pageBlock.data?.blockId;
// If block has blockId, then it is reference block and we need to get elements for it
if (blockId) {
const blockData = await context.pageBuilder.getPageBlock(blockId);
// We check if block has variable values set on the page and use them in priority over ones,
// that are set in blockEditor
const blockDataVariables =
blockData?.content?.data?.variables || [];
const variables = blockDataVariables.map(
(blockDataVariable: any) => {
const value =
pageBlock.data?.variables?.find(
(variable: any) =>
variable.varRef === blockDataVariable.varRef
)?.value || blockDataVariable.value;

return {
...blockDataVariable,
value
};
}
);

blocks.push({
...block,
data: { blockId, ...blockData?.content?.data },
...pageBlock,
data: {
blockId,
...blockData?.content?.data,
variables
},
elements: blockData?.content?.elements || []
});
} else {
blocks.push(block);
blocks.push(pageBlock);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please extract this logic into a separate file, just so we keep the resolvers shorter and easier to read. Besides, you'll be able to unit test this mapping logic if it lives in a standalone function.

formData => {
if (block && block.id) {
const newVariables = block.data?.variables?.map((variable: PbBlockVariable) => {
if (variable?.varRef === element?.data?.varRef) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I mentioned in the PR comment, let's use variableId within individual elements, instead of varRef.

Comment on lines 23 to 26
setTimeout(() => {
showSnackbar(`Block ${block.name} saved successfully!`);
showSnackbar(`Block "${block.name}" saved successfully!`);
history.push(`/page-builder/page-blocks`);
}, 500);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, why do we need a timeout here? This is not a change request, just want to know, because snackbar should be visible even after router change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Pavel910 I have changed it, so setTimeout is not required anymore

but there are few more places where such approach is used:
packages/app-page-builder/src/pageEditor/config/editorBar/PublishPageButton/PublishPageButton.tsx line 45
packages/app-page-builder/src/pageEditor/config/editorBar/PageOptionsMenu/SetAsHomepageButton.tsx line 56

should I change them too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@neatbyte-vnobis To be honest, I think this is a leftover from a long time ago. If you can, please try removing it and see if it works. If not, leave it as is. Thanks a lot!

@neatbyte-vnobis
Copy link
Collaborator Author

@Pavel910
regarding issue 3) about a lot of updatePage API calls: I have fixed this with sage of history: false param in update event
so now only onBlur will trigger an API call (like other editor inputs, aka "heading", etc.)

Copy link
Collaborator

@Pavel910 Pavel910 left a comment

Choose a reason for hiding this comment

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

@neatbyte-vnobis great, thanks!

@neatbyte-vnobis neatbyte-vnobis merged commit ea4298c into page-builder-blocks-v2 Oct 17, 2022
@neatbyte-vnobis neatbyte-vnobis mentioned this pull request Oct 25, 2022
51 tasks
@neatbyte-vnobis neatbyte-vnobis deleted the page-builder-blocks-v2-block-variables branch November 22, 2022 14:46
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.

2 participants