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

[RNMobile] Latest Posts Block v1 Support in Mobile #20301

Merged
merged 42 commits into from
Mar 11, 2020

Conversation

chipsnyder
Copy link
Contributor

@chipsnyder chipsnyder commented Feb 18, 2020

Fixes: wordpress-mobile/gutenberg-mobile#1746
Related PRs:

Description

Adds v1 support for the Latest Posts Block on mobile.

The block in the editor looks similar to an unsupported block but with the word "Customize" instead of unsupported.

After the block is selected you can open the settings menu by:

  • Tapping on the block
  • Tapping on the gear icon

In the settings, you can configure the following settings:

Setting Type Default Notes
Show post content Toggle false
Show full post content Toggle false false translates to excerpt and true translates to full_post
Max number of words in excerpt range 10 - 100 55 Only available if show post content is on and Show full post content is false
Display post date Toggle false
Order by "Newest to Oldest," "Oldest to Newest," "A -> Z," "Z -> A" Newest to Oldest
Category All categories configured in site plus a generic one for "All" All see "Categories known behaviors" for more info
Number of items range 1 to 100 5

How has this been tested?

These tests were validated via WPiOS and WPAndroid
Categories make a network request to fetch the available categories, so they were tested against a Wordpress.com site as well as a self-hosted site.

Add New Block

  1. Select an existing Page or create a new one
  2. Add a Latest Posts Block

Expect: block to be added

  1. Tap on the block or the gear menu

Expect the settings to show
Validate the block is configured based on the settings in the table above

Modify Block

This should be tested by modifying in mobile and validating on the web and by modifying on the web and testing on mobile.

  1. Select a Latest Post Block and bring up the settings
  2. Modify Settings

Conditional items:

  • Tapping on the toggle for "Show Post Content" should add a row for "Show" with the options of "Excerpt" or "Full Post" depending on the configuration of the block.
  • Changing "Show full post content" to true should hide "Max number of words in excerpt"
  • Changing "Show full post content" to false should show "Max number of words in excerpt" with the last selected value
  1. Close the settings
  2. Save as a draft or publish
  3. Leave the screen

Validate by checking the page on the other platform and by going into the same page/post that all settings match how you configured them.

Categories known behaviors

Categories are fetched in componentDidMount which results in a flow where multiple Latest-Posts Blocks can show different data.

  1. Open a page
  2. Add a Latest-Post Block
    - Take Note of the Categories -
  3. Modify the available categories. If on the web, do this in a new tab.
    - Note the first block does not reflect the changes in the categories -
  4. Add a new Latest-Post Block
    - Note the second block does reflect the changes in the categories -

This behavior is consistent on the web and mobile. Leaving the page and coming back will sync the categories.

Screenshots

latestPost

Types of changes

  • Adds v1 support for Latest Post Block

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@chipsnyder chipsnyder added [Type] Enhancement A suggestion for improvement. [Status] In Progress Tracking issues with work in progress Needs Design Feedback Needs general design feedback. Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Block] Latest Posts Affects the Latest Posts Block labels Feb 18, 2020
@chipsnyder chipsnyder added this to the Future milestone Feb 18, 2020
@github-actions
Copy link

github-actions bot commented Feb 19, 2020

Size Change: +226 B (0%)

Total Size: 864 kB

Filename Size Change
build/block-library/index.js 116 kB +147 B (0%)
build/components/index.js 191 kB +79 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.01 kB 0 B
build/annotations/index.js 3.43 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.58 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.02 kB 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-editor/index.js 105 kB 0 B
build/block-editor/style-rtl.css 10.6 kB 0 B
build/block-editor/style.css 10.6 kB 0 B
build/block-library/editor-rtl.css 7.23 kB 0 B
build/block-library/editor.css 7.24 kB 0 B
build/block-library/style-rtl.css 7.38 kB 0 B
build/block-library/style.css 7.39 kB 0 B
build/block-library/theme-rtl.css 669 B 0 B
build/block-library/theme.css 671 B 0 B
build/block-serialization-default-parser/index.js 1.65 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 57.7 kB 0 B
build/components/style-rtl.css 15.6 kB 0 B
build/components/style.css 15.6 kB 0 B
build/compose/index.js 5.75 kB 0 B
build/core-data/index.js 10.6 kB 0 B
build/data-controls/index.js 1.03 kB 0 B
build/data/index.js 8.22 kB 0 B
build/date/index.js 5.36 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 3.06 kB 0 B
build/edit-post/index.js 91.3 kB 0 B
build/edit-post/style-rtl.css 8.64 kB 0 B
build/edit-post/style.css 8.64 kB 0 B
build/edit-site/index.js 4.64 kB 0 B
build/edit-site/style-rtl.css 2.48 kB 0 B
build/edit-site/style.css 2.48 kB 0 B
build/edit-widgets/index.js 4.44 kB 0 B
build/edit-widgets/style-rtl.css 2.58 kB 0 B
build/edit-widgets/style.css 2.58 kB 0 B
build/editor/editor-styles-rtl.css 381 B 0 B
build/editor/editor-styles.css 382 B 0 B
build/editor/index.js 43.8 kB 0 B
build/editor/style-rtl.css 3.98 kB 0 B
build/editor/style.css 3.97 kB 0 B
build/element/index.js 4.45 kB 0 B
build/escape-html/index.js 734 B 0 B
build/format-library/index.js 7.09 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 1.92 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.49 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.3 kB 0 B
build/keycodes/index.js 1.68 kB 0 B
build/list-reusable-blocks/index.js 2.99 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 4.85 kB 0 B
build/notices/index.js 1.57 kB 0 B
build/nux/index.js 3.01 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.54 kB 0 B
build/primitives/index.js 1.49 kB 0 B
build/priority-queue/index.js 780 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/rich-text/index.js 14.3 kB 0 B
build/server-side-render/index.js 2.55 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4 kB 0 B
build/viewport/index.js 1.61 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

Copy link
Contributor

@mkevins mkevins left a comment

Choose a reason for hiding this comment

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

I tested via the steps in the description, and everything works as described. Nice work 🎉 !

Minor note (not introduced by this PR):

While testing this, I noticed an issue with the bottomsheet: The PanelBody titles do not allow scrolling. Instead, a drag-up does nothing, and a drag-down begins to dismiss the bottomsheet.

Screencast:

I'm not sure if this is a known issue?

@chipsnyder
Copy link
Contributor Author

I'm not sure if this is a known issue?

Yeah, good call out. I believe this is a known issue because @iamthomasbishop had mentioned it to me in slack. I think this is tracked by this issue wordpress-mobile/gutenberg-mobile#1884

font-size: 14;
font-weight: 600;
color: #2e4453;
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, why do we hard code this in place of the sass var?

Copy link
Contributor Author

@chipsnyder chipsnyder Feb 28, 2020

Choose a reason for hiding this comment

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

We had made some design tweaks and I was aligning to what’s in the media placeholder. That used the hex color instead of a var and when I searched it looked like this color hasn't been transferred to a var yet. So I decided to stick with the current pattern for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, this one was using the darken function, so might have been harder to spot: https://github.com/wordpress-mobile/gutenberg-mobile/blob/7500e0eb4d62279659c3af100c1311d255e099a7/src/_colors.scss#L98

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah that one didn't pop up on my search. I'll make a PR to fix that.

Copy link
Member

@geriux geriux left a comment

Choose a reason for hiding this comment

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

LGTM! Great work @chipsnyder !

Tested on the main iOS app and ✅

On the demo app it shows a red screen when opening the settings though, pretty sure its related to the categories but I guess it's not a blocker.

@chipsnyder
Copy link
Contributor Author

chipsnyder commented Feb 28, 2020

On the demo app it shows a red screen when opening the settings though, pretty sure its related to the categories but I guess it's not a blocker.

That actually sounds odd to me. I didn't test in the demo app but mocked failed network requests and didn't get a red screen. The user should just see "All" in the categories. I'll take a look and make sure there isn't a different object or status code being returned by the demo app that a user might see.

Good call out!

@chipsnyder
Copy link
Contributor Author

chipsnyder commented Feb 28, 2020

On the demo app it shows a red screen

I'm glad you checked that @geriux! The demo app was returning an object that wasn't an array as a result of its failure where in my other testing the request would fail and fall through to the catch block. So I added some additional checking to make sure we have a non-empty array.

parsedCategoriesList = JSON.parse( categoriesList );
}

if ( isEmpty( parsedCategoriesList ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The demo app was returning an object on its failure to fetch categories. I tried to add typeof categoriesList === 'array' here but got a lint error. So instead I'm checking to see if it's empty which seems to handle the weird object case.

Copy link
Contributor

@koke koke left a comment

Choose a reason for hiding this comment

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

I didn't look much into the code as this has already one approval, but I tested on Android with a bunch of different combinations of settings, and it seems to be working great 🎉

@geriux
Copy link
Member

geriux commented Mar 11, 2020

I'm glad you checked that @geriux! The demo app was returning an object that wasn't an array as a result of its failure where in my other testing the request would fail and fall through to the catch block. So I added some additional checking to make sure we have a non-empty array.

Thank you! Just tested it again on both the demo app and the main app and it's working correctly.

@chipsnyder chipsnyder merged commit 12b81b0 into master Mar 11, 2020
@chipsnyder chipsnyder deleted the rnmobile/issue-1746-latest-post branch March 11, 2020 18:34
import { __ } from '@wordpress/i18n';
import { postList as icon } from '@wordpress/icons';
import { InspectorControls } from '@wordpress/block-editor';
import { fetchRequest } from 'react-native-gutenberg-bridge';
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be used directly and instead, it should use the GB apiFecth interface. This will provide support for retries and cache of the data.

The only thing needed is to add the /wp/v2/categories to the white list here: https://github.com/wordpress-mobile/gutenberg-mobile/blob/e288c45e882db9808e0396715f379edb07f32416/src/api-fetch-setup.js#L44

@chipsnyder if you need help please ping me or @etoledom.

Copy link
Contributor Author

@chipsnyder chipsnyder Mar 19, 2020

Choose a reason for hiding this comment

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

Thanks @SergioEstevao! I'll make a PR either today and push it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Latest Posts Affects the Latest Posts Block Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants