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

Tooltip for template selection buttons #2216

Merged
merged 41 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b847aba
Layout picker - Tooltip - Adding AsyncStorage package
Apr 30, 2020
96a176f
AsyncStorage - Third party podspec
Apr 30, 2020
5473b68
AsyncStorage - Update podspec
Apr 30, 2020
c8c2284
Update gutenberg ref
Apr 30, 2020
a5ab004
Update release notes
May 4, 2020
c6d7322
Merge branch 'develop' into feature/layout-picker-tooltip
May 4, 2020
47cbdfe
Update Gutenberg ref
May 4, 2020
c761dd4
Bundles for testing
May 4, 2020
353b737
Update Gutenberg ref
May 4, 2020
034d6dd
Merge branch 'develop' into feature/layout-picker-tooltip
May 6, 2020
6a28672
Update Gutenberg ref
May 6, 2020
4a46bae
Layout picker - Tooltip - Android flag implementation
May 12, 2020
671e01f
Layout Picker - Tooltip - iOS flag implementation
May 12, 2020
fbeaab7
Layout picker - Tooltip - iOS Flag implementation typo
May 12, 2020
6db633c
Layout Picker - Tooltip - Add iOS flag implementation for the demo app
May 12, 2020
d64a89b
Update Gutenberg ref
May 12, 2020
32e9c5a
Revert "Bundles for testing"
May 12, 2020
e32b349
Merge branch 'develop' into feature/layout-picker-tooltip
May 12, 2020
1d90da0
Fix Release notes after merge
May 12, 2020
e3bc805
Remove async storage
May 12, 2020
41b90b1
Remove Async storage for Android
May 12, 2020
3f38ae4
Update Gutenberg ref
May 12, 2020
da1812a
Bundles for testing
May 13, 2020
1dbc6d0
Revert "Bundles for testing"
May 19, 2020
5fdc010
Merge branch 'develop' into feature/layout-picker-tooltip
May 19, 2020
ad5bc84
Update Gutenberg ref
May 19, 2020
2ee4845
Bundles for testing
May 19, 2020
b67aa13
Revert "Bundles for testing"
May 21, 2020
8ce3d68
Starter Page Templates - Tooltip - Use request name instead of get
May 21, 2020
0494fad
Update Gutenberg ref
May 21, 2020
a37ef95
Merge branch 'develop' into feature/layout-picker-tooltip
May 21, 2020
c7cb63b
Update Gutenberg ref
May 22, 2020
706a2fe
Merge branch 'develop' into feature/layout-picker-tooltip
May 22, 2020
be9bc7f
Bundles for testing
May 22, 2020
6501269
Update Gutenberg ref
May 25, 2020
426021f
Update Gutenberg ref
May 26, 2020
34a1112
Revert "Bundles for testing"
May 26, 2020
11e65da
Merge branch 'develop' into feature/layout-picker-tooltip
May 26, 2020
2f76ad1
Update Gutenberg ref
May 26, 2020
f612740
Update Release Notes
May 26, 2020
0989b9e
Update Gutenberg ref
May 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [***] Trash icon that is used to remove blocks is moved to the new menu reachable via ellipsis button in the block toolbar
* [**] Block toolbar can now collapse when the block width is smaller than the toolbar content
* [**] Creating undo levels less frequently
* [**] Tooltip for page template selection buttons

1.28.0
------
Expand Down
8 changes: 8 additions & 0 deletions android/app/src/main/java/com/gutenberg/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ public void requestMediaEditor(MediaUploadCallback mediaUploadCallback, String m
public void logUserEvent(GutenbergUserEvent gutenbergUserEvent, ReadableMap eventProperties) {
}

@Override
public void setStarterPageTemplatesTooltipShown(boolean tooltipShown) {
}

@Override
public void requestStarterPageTemplatesTooltipShown(StarterPageTemplatesTooltipShownCallback starterPageTemplatesTooltipShownCallback) {
}

@Override
public void editorDidEmitLog(String message, LogLevel logLevel) {
switch (logLevel) {
Expand Down
2 changes: 1 addition & 1 deletion gutenberg
Submodule gutenberg updated 76 files
+4 −1 bin/check-latest-npm.js
+5 −0 changelog.txt
+0 −9 docs/designers-developers/developers/data/data-core-block-editor.md
+1 −1 gutenberg.php
+1 −1 lib/class-wp-rest-block-directory-controller.php
+2 −1 package-lock.json
+1 −1 package.json
+1 −0 packages/block-directory/package.json
+59 −0 packages/block-directory/src/components/downloadable-block-list-item/test/__snapshots__/index.js.snap
+19 −0 packages/block-directory/src/components/downloadable-block-list-item/test/fixtures/index.js
+34 −0 packages/block-directory/src/components/downloadable-block-list-item/test/index.js
+12 −24 packages/block-directory/src/components/downloadable-block-notice/index.js
+2 −2 packages/block-directory/src/components/downloadable-block-notice/style.scss
+22 −0 packages/block-directory/src/components/downloadable-block-notice/test/__snapshots__/index.js.snap
+25 −26 packages/block-directory/src/components/downloadable-block-notice/test/index.js
+10 −82 packages/block-directory/src/components/downloadable-blocks-list/index.js
+57 −0 packages/block-directory/src/components/downloadable-blocks-list/test/__snapshots__/index.js.snap
+21 −44 packages/block-directory/src/components/downloadable-blocks-list/test/index.js
+47 −91 packages/block-directory/src/store/actions.js
+0 −13 packages/block-directory/src/store/constants.js
+40 −122 packages/block-directory/src/store/controls.js
+2 −1 packages/block-directory/src/store/index.js
+3 −12 packages/block-directory/src/store/reducer.js
+5 −1 packages/block-directory/src/store/resolvers.js
+14 −2 packages/block-directory/src/store/selectors.js
+112 −133 packages/block-directory/src/store/test/actions.js
+45 −0 packages/block-directory/src/store/test/controls.js
+78 −10 packages/block-directory/src/store/test/reducer.js
+67 −1 packages/block-directory/src/store/test/selectors.js
+1 −0 packages/block-editor/CHANGELOG.md
+2 −4 packages/block-editor/src/components/inserter/block-list.js
+0 −14 packages/block-editor/src/components/inserter/test/block-list.js
+5 −5 packages/block-editor/src/components/inserter/test/fixtures/index.js
+36 −1 packages/block-editor/src/components/page-template-picker/picker.native.js
+100 −0 packages/block-editor/src/components/page-template-picker/tooltip/index.native.js
+34 −0 packages/block-editor/src/components/page-template-picker/tooltip/style.native.scss
+5 −1 packages/block-editor/src/hooks/color.js
+3 −50 packages/block-editor/src/store/selectors.js
+8 −69 packages/block-editor/src/store/test/selectors.js
+11 −0 packages/block-library/src/columns/block.json
+1 −7 packages/block-library/src/columns/index.js
+12 −0 packages/block-library/src/group/block.json
+0 −9 packages/block-library/src/group/index.js
+9 −0 packages/block-library/src/heading/block.json
+0 −10 packages/block-library/src/heading/index.js
+10 −0 packages/block-library/src/media-text/block.json
+0 −6 packages/block-library/src/media-text/index.js
+1 −3 packages/block-library/src/nextpage/block.json
+8 −0 packages/block-library/src/paragraph/block.json
+0 −9 packages/block-library/src/paragraph/index.js
+0 −1 packages/components/src/custom-select-control/style.scss
+13 −0 packages/compose/README.md
+36 −0 packages/compose/src/hooks/use-previous/README.md
+31 −0 packages/compose/src/hooks/use-previous/index.js
+1 −0 packages/compose/src/index.js
+1 −1 packages/e2e-tests/specs/experiments/block-directory-add.test.js
+7 −1 packages/env/lib/wordpress.js
+3 −3 packages/project-management-automation/README.md
+3 −3 packages/project-management-automation/lib/index.js
+12 −0 packages/project-management-automation/lib/tasks/add-milestone/README.md
+2 −2 packages/project-management-automation/lib/tasks/add-milestone/index.js
+1 −1 packages/project-management-automation/lib/tasks/add-milestone/test/index.js
+10 −0 packages/project-management-automation/lib/tasks/assign-fixed-issues/README.md
+1 −1 packages/project-management-automation/lib/tasks/assign-fixed-issues/index.js
+1 −1 packages/project-management-automation/lib/tasks/assign-fixed-issues/test/index.js
+12 −0 packages/project-management-automation/lib/tasks/first-time-contributor/README.md
+4 −4 packages/project-management-automation/lib/tasks/first-time-contributor/index.js
+3 −3 packages/project-management-automation/lib/tasks/first-time-contributor/test/index.js
+1 −0 packages/scripts/CHANGELOG.md
+12 −0 packages/scripts/README.md
+5 −6 packages/scripts/scripts/test-e2e.js
+5 −8 packages/scripts/scripts/test-unit-jest.js
+30 −3 packages/scripts/utils/config.js
+2 −0 packages/scripts/utils/index.js
+99 −2 packages/scripts/utils/test/index.js
+1 −1 readme.txt
8 changes: 8 additions & 0 deletions ios/gutenberg/GutenbergViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ extension GutenbergViewController: GutenbergBridgeDelegate {
func gutenbergDidRequestMention(callback: @escaping (Result<String, NSError>) -> Void) {
callback(.success("matt"))
}

func gutenbergDidRequestStarterPageTemplatesTooltipShown() -> Bool {
return false;
}

func gutenbergDidRequestSetStarterPageTemplatesTooltipShown(_ tooltipShown: Bool) {
print("Gutenberg requested setting tooltip flag")
}
}

extension GutenbergViewController: GutenbergBridgeDataSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ interface MediaUploadCallback {
void onMediaFileUploadFailed(int mediaId);
}

interface StarterPageTemplatesTooltipShownCallback {
void onRequestStarterPageTemplatesTooltipShown(boolean tooltipShown);
}

// Ref: https://github.com/facebook/react-native/blob/master/Libraries/polyfills/console.js#L376
enum LogLevel {
TRACE(0),
Expand Down Expand Up @@ -140,4 +144,8 @@ public static GutenbergUserEvent getEnum(String eventName) {
void logUserEvent(GutenbergUserEvent gutenbergUserEvent, ReadableMap eventProperties);

void onAddMention(Consumer<String> onSuccess);

void setStarterPageTemplatesTooltipShown(boolean tooltipShown);

void requestStarterPageTemplatesTooltipShown(StarterPageTemplatesTooltipShownCallback starterPageTemplatesTooltipShownCallback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.GutenbergUserEvent;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaType;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.OtherMediaOptionsReceivedCallback;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.StarterPageTemplatesTooltipShownCallback;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.RNMedia;
import org.wordpress.mobile.WPAndroidGlue.MediaOption;

Expand Down Expand Up @@ -256,6 +257,25 @@ public void addMention(Promise promise) {
mGutenbergBridgeJS2Parent.onAddMention(promise::resolve);
}

@ReactMethod
public void setStarterPageTemplatesTooltipShown(boolean tooltipShown) {
mGutenbergBridgeJS2Parent.setStarterPageTemplatesTooltipShown(tooltipShown);
}

@ReactMethod
public void requestStarterPageTemplatesTooltipShown(final Callback jsCallback) {
StarterPageTemplatesTooltipShownCallback starterPageTemplatesTooltipShownCallback = requestStarterPageTemplatesTooltipShownCallback(jsCallback);
mGutenbergBridgeJS2Parent.requestStarterPageTemplatesTooltipShown(starterPageTemplatesTooltipShownCallback);
}

private StarterPageTemplatesTooltipShownCallback requestStarterPageTemplatesTooltipShownCallback(final Callback jsCallback) {
return new StarterPageTemplatesTooltipShownCallback() {
@Override public void onRequestStarterPageTemplatesTooltipShown(boolean tooltipShown) {
jsCallback.invoke(tooltipShown);
}
};
}

private GutenbergBridgeJS2Parent.MediaUploadCallback getNewUploadMediaCallback(final Boolean allowMultipleSelection, final Callback jsCallback) {
return new GutenbergBridgeJS2Parent.MediaUploadCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class WPAndroidGlueCode {
private OnImageFullscreenPreviewListener mOnImageFullscreenPreviewListener;
private OnMediaEditorListener mOnMediaEditorListener;
private OnLogGutenbergUserEventListener mOnLogGutenbergUserEventListener;
private OnStarterPageTemplatesTooltipShownEventListener mOnStarterPageTemplatesTooltipShownListener;
private boolean mIsEditorMounted;

private String mContentHtml = "";
Expand Down Expand Up @@ -166,6 +167,11 @@ public interface OnLogGutenbergUserEventListener {
void onGutenbergUserEvent(GutenbergUserEvent event, Map<String, Object> properties);
}

public interface OnStarterPageTemplatesTooltipShownEventListener {
void onSetStarterPageTemplatesTooltipShown(boolean tooltipShown);
boolean onRequestStarterPageTemplatesTooltipShown();
}

public void mediaSelectionCancelled() {
mAppendsMultipleSelectedToSiblingBlocks = false;
}
Expand Down Expand Up @@ -338,6 +344,17 @@ public void logUserEvent(GutenbergUserEvent event, ReadableMap eventProperties)
@Override public void onAddMention(Consumer<String> onSuccess) {
mAddMentionUtil.getMention(onSuccess);
}

@Override
public void setStarterPageTemplatesTooltipShown(boolean showTooltip) {
mOnStarterPageTemplatesTooltipShownListener.onSetStarterPageTemplatesTooltipShown(showTooltip);
}

@Override
public void requestStarterPageTemplatesTooltipShown(StarterPageTemplatesTooltipShownCallback starterPageTemplatesTooltipShownCallback) {
boolean tooltipShown = mOnStarterPageTemplatesTooltipShownListener.onRequestStarterPageTemplatesTooltipShown();
starterPageTemplatesTooltipShownCallback.onRequestStarterPageTemplatesTooltipShown(tooltipShown);
}
}, mIsDarkMode);

return Arrays.asList(
Expand Down Expand Up @@ -448,6 +465,7 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener
OnMediaEditorListener onMediaEditorListener,
OnLogGutenbergUserEventListener onLogGutenbergUserEventListener,
AddMentionUtil addMentionUtil,
OnStarterPageTemplatesTooltipShownEventListener onStarterPageTemplatesTooltipListener,
boolean isDarkMode) {

MutableContextWrapper contextWrapper = (MutableContextWrapper) mReactRootView.getContext();
Expand All @@ -462,6 +480,7 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener
mOnMediaEditorListener = onMediaEditorListener;
mOnLogGutenbergUserEventListener = onLogGutenbergUserEventListener;
mAddMentionUtil = addMentionUtil;
mOnStarterPageTemplatesTooltipShownListener = onStarterPageTemplatesTooltipListener;

sAddCookiesInterceptor.setOnAuthHeaderRequestedListener(onAuthHeaderRequestedListener);

Expand Down
8 changes: 8 additions & 0 deletions react-native-gutenberg-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,12 @@ export function addMention() {
return RNReactNativeGutenbergBridge.addMention();
}

export function requestStarterPageTemplatesTooltipShown( callback ) {
return RNReactNativeGutenbergBridge.requestStarterPageTemplatesTooltipShown( callback );
}

export function setStarterPageTemplatesTooltipShown( tooltipShown ) {
return RNReactNativeGutenbergBridge.setStarterPageTemplatesTooltipShown( tooltipShown );
}

export default RNReactNativeGutenbergBridge;
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,20 @@ public protocol GutenbergBridgeDelegate: class {
///
func gutenbergDidRequestMediaEditor(with mediaUrl: URL, callback: @escaping MediaPickerDidPickMediaCallback)


/// Tells the delegate that the editor needs to log a custom event
/// - Parameter event: The event key to be logged
func gutenbergDidLogUserEvent(_ event: GutenbergUserEvent)

/// Tells the delegate that the editor requested a mention
/// - Parameter callback: Completion handler to be called with an user mention or an error
func gutenbergDidRequestMention(callback: @escaping (Swift.Result<String, NSError>) -> Void)

/// Tells the delegate that the editor requested to show the tooltip
func gutenbergDidRequestStarterPageTemplatesTooltipShown() -> Bool

/// Tells the delegate that the editor requested to set the tooltip's visibility
/// - Parameter tooltipShown: Tooltip's visibility value
func gutenbergDidRequestSetStarterPageTemplatesTooltipShown(_ tooltipShown: Bool)
Comment on lines +170 to +176
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @geriux @chipsnyder !
First congrats for merging this feature 🎉

I just recently came across with these new bridge delegate methods, and I was wondering what was the intention. My first thought was that we were displaying UI on native side, but it seems like it's used only to do persistent storage of user actions (in this case, tooltips already shown to the user). In this case I was wondering if it makes sense to do this persistence internally in the bridge itself, and relieve the client from this responsibility that seems to be quite low level.

Also, it would be interesting to be able to get and set settings in general, in order to avoid new bridge messages for every different setting we might have in the future.

Furthermore, web already has a similar system in place that uses LocalStorage as persistence. It's used (between other things) to know if gutenberg should display NUX UI. Maybe we can reuse this system and create this generic bridge method to store a JSON payload in the same way that the browser's LocalStorage does.

This is clearly no hi-pri, but I've been thinking in ways to improve the bridge usage anyway.

Please let me know what do you think, or perhaps these ideas wouldn't help this feature in particular.

Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @etoledom 👋 😃 As I understand, AsyncStorage was considered (to mirror the behavior of LocalStorage), however, it was decided that though that would simplify the implementation of persistent flags, it was more desirable to have all app-level persistence in one place.

While reviewing the Android side of this feature, I had a similar thought about how this pattern might "grow". But, since there aren't any other similar flags (yet) there was nothing to DRY up. My thinking is, we should keep an eye out if a pattern emerges where we can propose a more general solution to settings / persistent flag retrieval and reduce the "footprint" of the interface / protocol.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @mkevins for the explanation!

What do you think about the first part? Maybe we still can avoid giving the responsibility to store the flag to the client. Could we do de persistence inside the bridge without the need for WP apps to know about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we still can avoid giving the responsibility to store the flag to the client. Could we do de persistence inside the bridge without the need for WP apps to know about it?

I think this was the case in an earlier implementation:
https://github.com/WordPress/gutenberg/blob/9aaf218b11481ebb4fe227426921181b21d252b4/packages/block-editor/src/components/page-template-picker/picker.native.js#L94

I'm not sure I have all the context on the decision to centralize the persistence into the parent apps. Perhaps it is to avoid "fragmenting" settings screens, but that is purely a guess on my part. This particular flag is not a user-toggleable setting, so it seems moot in this instance, but maybe this is more of a general architecture decision? I'm not sure there is a way to access the AsyncStorage data from the native side, so perhaps that's a concern as well? Maybe @hypest or @geriux can shed some more light on this.

I found this which looks interesting, but I'm not sure if there is an equivalent iOS module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @etoledom 👋 thanks for bringing this up and also thanks @mkevins for joining the conversation.

As @mkevins mentioned when I started this feature my intention was to use AsyncStorage. Since it didn't require much other than adding the library to the main apps (because React Native removed it in favor of lean core).

In the process of that, there were some discussions about maybe avoid using AsyncStorage and use what we currently use for some flags instead. Mainly to store data in the same place, even if it's a flag. So I ended up deciding to do it this way.

For this case though, as @mkevins mentions, it is not a user-togglable setting so having it stored somewhere else would work just fine.

Also, it would be interesting to be able to get and set settings in general, in order to avoid new bridge messages for every different setting we might have in the future.

This could be an option to avoid adding extra code for these types of settings.

Furthermore, web already has a similar system in place that uses LocalStorage as persistence. It's used (between other things) to know if gutenberg should display NUX UI. Maybe we can reuse this system and create this generic bridge method to store a JSON payload in the same way that the browser's LocalStorage does.

I guess this could also work, in my experience, AsyncStorage works just fine. Not sure how complicated it would be to develop what you mention but I'd lean more for adding AsyncStorage if we decide to go for this kind of system.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you both for your explanations! Everything seems more clear now 🙂

Let's wait for a good moment to re-think this, probably when we need to store a new similar flag.

}

// MARK: - Optional GutenbergBridgeDelegate methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject)
RCT_EXTERN_METHOD(requestMediaEditor:(NSString *)mediaUrl callback:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(logUserEvent:(NSString *)event properties:(NSDictionary *)properties)
RCT_EXTERN_METHOD(addMention:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)rejecter)
RCT_EXTERN_METHOD(requestStarterPageTemplatesTooltipShown:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(setStarterPageTemplatesTooltipShown:(BOOL)tooltipShown)

@end
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
}
})
}

@objc
func requestStarterPageTemplatesTooltipShown(_ callback: @escaping RCTResponseSenderBlock) {
callback([self.delegate?.gutenbergDidRequestStarterPageTemplatesTooltipShown() ?? false])
}

@objc
func setStarterPageTemplatesTooltipShown(_ tooltipShown: Bool) {
self.delegate?.gutenbergDidRequestSetStarterPageTemplatesTooltipShown(tooltipShown)
}

}

// MARK: - RCTBridgeModule delegate
Expand Down