-
Notifications
You must be signed in to change notification settings - Fork 20
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-5017: Re-implement Spreadsheet block frontend in React #273
Conversation
A few notes about this:
So, I'm not sure about (2), maybe we can test these assumptions? Is the WP overhead that bad? Is parsing the CSV lines to JSON super fast? What do you think? |
Regarding point 2: I'm leaning mostly towards 1st option. Since we already need to render the block in the backend, it seems less complicated and faster for the end-user to use WP cache store. Unless I'm missing something, it also feels more work to do the 2nd option. Which is not necessarily bad if that's the proper way of implementation. But maybe this block is a good opportunity to see how this works and do something similar with WYSIWYG blocks. Rendering on the client-side could be a very good option if we didn't render the block in the backend at all (eg. the native Embed block for Facebook). |
Regarding 1. Seems like the most sensible thing to do indeed. Maybe we can set this up in a generic way for all blocks that are rendered frontend? We could use
for all blocks. Actually, maybe then we can also circumvent the Maybe worth a shot? Then we wouldn't need the render on the backend, which is basically just turning one representation of the block's data into another one (block comment -> data attributes). As for 2. I think the CSV parsing should be really fast and only an issue for huge spreadsheets, like 100k or more rows, far beyond what would make sense to include on a page. But we can try if we want to be sure. Possibly we can get this data as JSON too from the Google sheets API. The reason I remarked it was because I assume that Google sheets has a pretty extensive CDN to deliver this data efficiently anywhere in the world, so very likely the round trip to our server will be significantly longer, even without WP overhead. Note that currently, even though a placeholder for the blocks is rendered on the backend, the data of the sheet doesn't come with that. The frontend needs to do a separate call to a custom endpoint before it can start rendering. So for the end user the difference in speed is between how fast our server can serve that endpoint vs how fast Google sheets CDN can serve a static resource. Though serving it from our backend also has some advantages, as it ensures the sheet will work regardless of possible issues that might prevent the browser from getting the data from Google. There might be some other considerations when including data from external domains. I'm ok with the current approach of caching it on our server as there's probably no noticeable difference to the end user in most cases. Probably the additional load on our servers is also negligible. |
Hey @Inwerpsel , sorry for the delay. Regarding 1: Regarding 2: |
b9c4b8e
to
4f52275
Compare
Branch updated to latest master. I removed the I wrote a deprecation handler to avoid any warnings from the |
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.
Great work 💯 Tested locally and it's working, just a couple of things in there that we need to fix (mainly the block not updating when you change the url in the editor), and couple of small tweaks/extractions. But it's almost there 👍
d7f2d37
to
1c9581c
Compare
Hey @Inwerpsel @comzeradd , branch rebased to master, this is currently deployed in the Mars environment. Addressed all the comments in the review, applied most of the suggestions. I didn't decouple the rendering from the API fetch, I think we can do that later if the requirements change, for example, if we are planning to fetch spreadsheets from other sources than Google docs. I also considered registering a Redux Store in the Gutenberg side to handle the data, using the |
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 great 💯 I have some final nit picking comments, nothing blocking so can approve already, but would be nice if you could have a look. As for decoupling, I guess it would still make sense to do it already. It would have some other benefits, mainly it would make the SpreadsheetFrontend
component less complex. But we can indeed take that up later 👍
5455114
to
0dc62d2
Compare
…ate. Commits squashed in this one: - Separate the Frontend view - Commits squashed in this one: - Added REST method to get the Spreadsheet data from cache if available. - Add search functionality to the React side - Add sorting and sort order icons - Adding arrow icons and some subtle transitions - No-PHP version of the frontend renderer - Add FrontendBlockNode component for consistency - Generic frontend block renderer - Reimplement block-scoped CSS variables in React. Remove render_callback. - Fix PHPCS errors. Validate Sheet ID is an integer in the API endpoint. - Turn into a fully WYSIWYG version. * Move the URL field to the sidebar. * Show a message if there is no URL yet. * Show a loading message only if its actually loading something - Fix the Sheet ID filter in the endpoint. - Take into account possible URL errors. Update the Spreadsheet on URL changes. - PLANET-5017 Use a data attribute for rendering (by PieterV) - Use default sorting from the spreadsheet until a header is clicked. Also: * Small fix for the frontendRendered function. Added some 'warning' comments. * Use the registered block name for the frontend render. * Make sure error messages are only for the editor side. - Updating help message. Removing prepare_data method. Remove unused function. - Extract HighlightMatches and CSSVariablesToText logic. - Address review feedback. - Use section and the .block class - Fix PHPCS errors - Fix stylelint errors - Set search input font to Roboto, address some final review feedback
Porting the Spreadsheet block's frontend to React.
Ref: https://jira.greenpeace.org/browse/PLANET-5017