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
PLANET-6156: Split Spreadsheet block scripts #591
Conversation
Test instance is ready 🚀🌑 oberon ⌚ 2021.05.26 11:38:27 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on local with both existing block and new block, everything seems to be working as expected 👍 However while testing I did find a few bugs/issues that are unrelated to the changes since they also happen in production:
- Trying to “unselect” a color for the block by double-clicking on it in the sidebar causes the block to crash with console error (see screenshot)
- When searching for terms in the sheet, if the string is only one character long and has no corresponding results (for example “h” in the example sheet that you provided in order to test this ticket) nothing shows instead of the expected “No data matching your search” message... This is due to this check being
> 1
instead of> 0
, not sure if there’s a reason for that or if it’s a mistake 🤔 - There’s also a console warning:
componentWillReceiveProps has been renamed, and is not recommended for use
so we should probably update that 😬
Of course these are out of the scope of this ticket, so if it's too long to solve and too many changes it's probably best to tackle them in a follow-up ticket 🙂
@mleray Fixed the first 2 points, not sure the last one is fast to fix so I'll open a ticket for it. |
classes/blocks/class-spreadsheet.php
Outdated
/** | ||
* Spreadsheet has no editor style. | ||
*/ | ||
public static function enqueue_editor_style(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding this override here, wouldn't it be possible to check in the original function that the files exist? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point, I was thinking about the overhead of checking files on disk, but it's minimal and we serve mostly cached content, so it's easier that way. Done 👍
Ref: https://jira.greenpeace.org/browse/PLANET-6156 Split Spreadsheet scripts to only be loaded when a block is present on the page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
Ref: https://jira.greenpeace.org/browse/PLANET-6156
Split Spreadsheet scripts to only be loaded when a block is present on the page.
Test
Spreadsheet block should work as expected
Common functions imported
For this split I checked bits webpack imported in the compiled file that are used elsewhere and that we could load globally once instead:
We could create a ticket to import all functions in our namespace in one go,
p4.fetchJson()
, etc. and declare it asexternals
for webpack ?Generic method for following tickets
Replacing
{Blockname}
by PascalCase block name, and{blockname}
by lowercase block name.Styles
In
assets/src/styles/blocks
:mkdir {Blockname}
git mv {Blockname}.scss {Blockname}/{Blockname}Style.scss
git mv {Blockname}Editor.scss {Blockname}/{Blockname}EditorStyle.scss
If no style file exists, you don't have to create an empty one.
Scripts
In
assets/src/blocks
:touch {Blockname}/{Blockname}Script.js
assets/src/frontendIndex.js
git mv {Blockname}/{Blockname}Editor.js {Blockname}/{Blockname}EditorScript.js
assets/src/editorIndex.js
accordinglyPHP class
classes/blocks/class-{blockname}.php
, extract register function from constructor