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

Display the help text in the TextareaArray setting #62

Merged
merged 22 commits into from
May 7, 2021

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Feb 4, 2021

(Testing instructions still valid as of May 5th)

Before

before-no-help

After

multiselect-field

Changes

  • Adds help text to <textarea> settings in Multiselect, Select, and Radio fields

Testing instructions

  1. composer install && npm install && npm run dev
  2. /wp-admin > Custom Blocks > Add New
  3. Add a new field
  4. Change the Field Type to Select
  5. Expected: the new help text displays: help-text
  6. Change the Field Type to Multiselect
  7. Expected: there's new help text under 2 settings: multiselect-field
  8. Change the Field Type to Radio
  9. Expected: there's new help text:

radio-new-help-text

Without this,
it's really hard to know what to enter.
This existed before,
but it usually had markup.
So instead of doing
__dangerouslySetInnerHTML={},
enter the markup in the React file,
and use other help text if it exists.
It looks like it
has to be wp-env in CircleCI.
'genesis-custom-blocks'
) }
</p>
<p className={ helpClass }>
Copy link
Contributor Author

@kienstra kienstra Feb 4, 2021

Choose a reason for hiding this comment

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

Before, this help text was in setting.help, but it has markup.

So instead of doing dangerouslySetInnerHTML={ setting.default }, this has the markup in the React file.

_x( 'foo : Foo', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ),
_x( 'bar : Bar', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' )
),
'help' => '',
Copy link
Contributor Author

@kienstra kienstra Feb 4, 2021

Choose a reason for hiding this comment

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

This is now in the React file.

This is '' here in PHP to not override the React's component's help markup.

@@ -69,7 +63,7 @@ public function register_settings() {
'label' => __( 'Default Value', 'genesis-custom-blocks' ),
'type' => 'textarea_array',
'default' => '',
'help' => __( 'Enter each default value on a new line.', 'genesis-custom-blocks' ),
'help' => __( 'Each default value on a new line.', 'genesis-custom-blocks' ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be similar to the other text. I removed this word from the other text to display on 2 lines instead of 3.

* @property {string} help A help value that display in the GCB editor.
* @property {string} type The setting type, like 'width' or 'text', not a data type like boolean.
* @property {*} default The default value.
*/
Copy link
Contributor Author

@kienstra kienstra Feb 4, 2021

Choose a reason for hiding this comment

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

Not related to this PR, but noticed I forgot to give Setting a @typedef before.

@kienstra
Copy link
Contributor Author

kienstra commented Feb 4, 2021

Hi @dreamwhisper,
Thanks for bringing this up, it's tough to know what to enter in the <textarea> without help text.

How does this look?

@kienstra
Copy link
Contributor Author

Hi @RobStino,
Could you please review this? Thanks!

@kienstra kienstra requested a review from RobStino February 11, 2021 03:17
@kienstra kienstra marked this pull request as ready for review February 16, 2021 15:32
@dreamwhisper
Copy link
Contributor

@kienstra I'm having some trouble with the multiselect.

I see this when the block is on the page. Also, no default appears selected.

  • Add the block to the page.
  • click outside the block or save, then leave the page and come back.
    Screen Shot 2021-03-09 at 10 25 38 AM

@kienstra
Copy link
Contributor Author

kienstra commented Mar 9, 2021

Hi @dreamwhisper,
Thanks a lot for testing this and raising the issue with the multiselect. I'll look at that.

@kienstra
Copy link
Contributor Author

kienstra commented Mar 9, 2021

Hi @dreamwhisper,
Thanks, I saw the same thing you saw:

multiselct-block

I'll work on this when GCB tickets get slotted into a sprint 😄

kienstra added 10 commits April 30, 2021 14:49
There were conflicts in:
js/src/edit-block/components/settings/checkbox.js
package.json
php/Blocks/Controls/Multiselect.php
php/Blocks/Controls/Radio.php
php/Blocks/Controls/Select.php
tests/php/Unit/Blocks/Controls/TestMultiselect.php
tests/php/Unit/Blocks/Controls/TestRadio.php
tests/php/Unit/Blocks/Controls/TestSelect.php

In almost all cases, resolve conflicts in favor of this
branch: add/choices-description.
Expect in package.json.
ControlSetting doesn't have a ->sanitize or ->validate
property anymore.
So no need to pass that.
These settings are saved in React,
and are not validated.
If the field no longer exists,
there's no need to add it to the
block's attributes.
There's a new package
that was just released 3 days ago.
Without this,
<ServerSideRender> could have a network error.
The attribute could be of a different type.
For example, changing from a Url field
to Image, the type will change from from
string to integer.
So this prevents an error in ServerSideRender.
The server-side will only have the saved post values.
So pass the saved previewAttributes,
not just the edited ones.
This looks to prevent errors in <ServerSideRender>.
@@ -109,10 +109,7 @@ const Header = ( { editorMode, setEditorMode } ) => {
</button>
<div id="save-and-publish">
<span className="mr-3 text-sm">
<PostSavedState
forceIsDirty={ false }
forceIsSaving={ false }
Copy link
Contributor Author

@kienstra kienstra May 3, 2021

Choose a reason for hiding this comment

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

These are essentially false by default. So no need to pass false.

kienstra added 3 commits May 3, 2021 18:16
If there is nothing saved,
there will be nothing to preview.
Maybe if this were more effortless,
it would allow them to click a <button> to do that.
Some blocks won't have fields,
just a template.
foo : Foo
</p>
<p className={ helpClass }>
bar : Bar
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Intentionally not translated

kienstra added 4 commits May 4, 2021 15:13
It looks like this was a real failure:
one of the issues was a deletion of
something that didn't exist.
This will look for a combobox (select)
with a lable, as that's more like

what a user would look for.
… adds that dir

When e2e tests fail,
it looks like it uses that to add a screenshot.
*
* @return {React.ReactElement} The editor preview.
*/
const EditorPreview = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is mainly extracted out of editor.js

*
* @return {React.ReactElement} The front-end preview.
*/
const FrontEndPreview = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is mainly extracted from editor.js, with some conditionals in case there's nothing to preview.

_x( 'foo : Foo', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ),
_x( 'bar : Bar', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' )
),
'help' => '',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now rendered in React.

kienstra added 3 commits May 4, 2021 23:46
newAttributes is actually a
key/value pair, I think.
These should be saved as a string[],
not as an array of objects, like before.
* @param {TextareaDefaultProps} props The component props.
* @return {React.ReactElement} The textarea default component.
*/
const TextareaDefault = ( { handleOnChange, setting, value } ) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This component should fix the problem with the Multiselect error. It saves the default value as an array of strings, instead of the array of objects it did before.

@kienstra
Copy link
Contributor Author

kienstra commented May 5, 2021

Hi @dreamwhisper,
Thanks a lot for testing this before.

Could you please test it again? The multiselect issue looks to be fixed in my local.

Thanks, Jen!

@kienstra kienstra requested review from dreamwhisper and removed request for dreamwhisper May 5, 2021 06:23
Copy link
Contributor

@dreamwhisper dreamwhisper left a comment

Choose a reason for hiding this comment

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

Looks good!

@kienstra
Copy link
Contributor Author

kienstra commented May 6, 2021

Thanks so much, Jen!!!

@kienstra kienstra merged commit 1ba74a3 into develop May 7, 2021
@kienstra kienstra deleted the add/choices-description branch May 7, 2021 16:17
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