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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
69408f4
Display the help text for the TextareaArray setting
kienstra Feb 4, 2021
9176d61
Let e2e tests run by changing to wp-env
kienstra Feb 4, 2021
dbfdfac
Merge in develop, resolve conflicts.
kienstra Apr 30, 2021
e0c1fc5
Remove sanitize and validate values from settings
kienstra Apr 30, 2021
4af23d4
If a field is deleted, also delete it from the previewAttributes
kienstra May 3, 2021
a344c51
See if upgrading server-side-render is possible
kienstra May 3, 2021
5e84929
Revert "See if upgrading server-side-render is possible"
kienstra May 3, 2021
81c1820
When changing a field name, change the name in the previewAttributes
kienstra May 3, 2021
66452fe
On changing the field type, delete the previewAttribute
kienstra May 3, 2021
f1c4aff
Refactor preview into <FrontEndPreview> component
kienstra May 3, 2021
67ae09b
Possible approach to handling <ServerSideRender> error
kienstra May 3, 2021
236e885
Simpler approach to front-end preview (if it works)
kienstra May 3, 2021
19632aa
Handle the Front-end preview for new post
kienstra May 3, 2021
7cb75db
If there is no field to preview, suggest that they add a field
kienstra May 3, 2021
5028610
Change text to 'edit the block,' as it doesn't need fields
kienstra May 3, 2021
5492839
See if userEven helps the test pass
kienstra May 4, 2021
abd6979
Fix failed e2e test
kienstra May 4, 2021
4a8b58a
Make e2e test more robust: query for role, not selector
kienstra May 4, 2021
094953f
Add artifacts/ to .gitignore, it looks like the new wordpress/scripts…
kienstra May 4, 2021
ce7d120
Pluralize the attributes names and values
kienstra May 5, 2021
a538af9
Add a new component for the Multiselect defaults
kienstra May 5, 2021
96156f2
Fix the failed PHPUnit test
kienstra May 5, 2021
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
node-version: lts
- nodegit-workaround
- set-up-packages
- run: npm run env start && npm run test:e2e
- run: npm run wp-env start && npm run test:e2e

svn-deploy:
executor:
Expand Down
10 changes: 10 additions & 0 deletions js/src/edit-block/components/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ import {
* @property {string} [width] The width, like '25'.
*/

/**
* @typedef {Object} Setting A field setting.
* @see PHP class Genesis\CustomBlocks\Blocks\Controls\ControlSetting
* @property {string} name The name of the setting.
* @property {string} label The label of the setting to display in the GCB editor.
* @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.


/**
* The editor component.
*
Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as React from 'react';
/**
* @typedef {Object} InputProps The component props.
* @property {Function} handleOnChange Handles a change in this setting.
* @property {Object} setting This setting.
* @property {import('./editor').Setting} setting This setting.
* @property {string} type The type of <input>, like 'text'.
* @property {string|undefined} value The setting value.
* @property {number} [min] The min attribute of an input[type="number"].
Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as React from 'react';
* @property {Function} handleOnChange Handles a change in this setting.
* @property {string} id The id attribute.
* @property {Array} options The options, including their label and value.
* @property {Object} setting This setting.
* @property {import('./editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
*/

Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/settings/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as React from 'react';
/**
* @typedef {Object} CheckboxProps The component props.
* @property {Function} handleOnChange Handles a change in this setting.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {boolean|undefined} value The setting value.
*/

Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/settings/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Input } from '../';

/**
* @typedef {Object} EmailProps The component props.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
* @property {Function} handleOnChange Handles a change in this setting.
*/
Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/settings/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { LOCATIONS_WITH_LABEL, LOCATIONS } from '../../constants';

/**
* @typedef {Object} LocationProps The component props.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
* @property {Function} handleOnChange Handles a change to this setting.
* @property {Function} setCurrentLocation Sets the selected location, like 'editor'.
Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/settings/new-line-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Select } from '../';

/**
* @typedef {Object} NewLineFormatProps The component props.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
* @property {Function} handleOnChange Handles a change to this setting.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Input } from '../';

/**
* @typedef {Object} NumberNonNegativeProps The component props.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
* @property {Function} handleOnChange Handles a change in this setting.
*/
Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/settings/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Input } from '../';

/**
* @typedef {Object} NumberProps The component props.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
* @property {Function} handleOnChange Handles a change in this setting.
*/
Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/settings/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Input } from '../';

/**
* @typedef {Object} TextProps The component props.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
* @property {Function} handleOnChange Handles a change in this setting.
*/
Expand Down
30 changes: 29 additions & 1 deletion js/src/edit-block/components/settings/textarea-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import * as React from 'react';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
Expand All @@ -11,7 +16,7 @@ import { convertSettingsStringToArray, convertSettingsArrayToString } from '../.
/**
* @typedef {Object} TextareaArrayProps The component props.
* @property {Function} handleOnChange Handles a change in this setting.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {Array|undefined} value The setting value.
*/

Expand All @@ -25,6 +30,7 @@ const TextareaArray = ( { handleOnChange, setting, value } ) => {
const id = `setting-textarea-array-${ setting.name }`;
const stringValue = convertSettingsArrayToString( value );
const textAreaValue = undefined === stringValue ? setting.default : stringValue;
const helpClass = 'block italic text-xs mt-1';

return (
<>
Expand All @@ -40,6 +46,28 @@ const TextareaArray = ( { handleOnChange, setting, value } ) => {
} }
value={ textAreaValue }
/>
{ Boolean( setting.help )
? (
<p className={ helpClass }>
{ setting.help }
</p>
) : (
<>
<p className={ helpClass }>
{ __(
'Each choice on a new line. To specify the value and label separately, use this format:',
'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.

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

</p>
</>
)
}
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/settings/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as React from 'react';
/**
* @typedef {Object} TextareaProps The component props.
* @property {Function} handleOnChange Handles a change in this setting.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
*/

Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/components/settings/width.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { __ } from '@wordpress/i18n';

/**
* @typedef {Object} WidthProps The component props.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {string|undefined} value The setting value.
* @property {Function} handleOnChange Handles a change in this setting.
*/
Expand Down
2 changes: 1 addition & 1 deletion js/src/edit-block/helpers/getSettingsComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { snakeCaseToPascalCase } from '../../common/helpers';
/**
* @typedef {Object} SettingsComponentProps The component props.
* @property {Function} handleOnChange Handles a change in this setting.
* @property {Object} setting This setting.
* @property {import('../editor').Setting} setting This setting.
* @property {boolean|undefined} value The setting value.
* @property {Function} setCurrentLocation Sets the current location, like 'editor'.
*/
Expand Down
15 changes: 1 addition & 14 deletions js/src/edit-block/helpers/getSettingsDefaults.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/**
* @typedef {Object} Setting A field setting.
* @see PHP class Genesis\CustomBlocks\Blocks\Controls\ControlSetting
* @property {string} name Setting name (slug).
* @property {string} label Setting label.
* @property {string} type Setting type, not a data type like 'object'.
* @property {*} default Setting default value.
* @property {string} help Setting help text for the editor.
* @property {*} sanitize To sanitize the setting value.
* @property {*} validate To validate the value.
* @property {*} value The current value.
*/

/**
* Gets the settings defaults for a given control.
*
Expand All @@ -31,7 +18,7 @@ const getSettingsDefaults = ( controlName, controls ) => {
return controls[ controlName ].settings.reduce(
/**
* @param {Object} accumulator The reducer's accumulator.
* @param {Setting} setting The field setting.
* @param {import('../components/editor').Setting} setting The field setting.
* @return {Object} Key/value pairs of a setting name to its default value.
*/
( accumulator, setting ) => ( {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"check-licenses": "wp-scripts check-licenses --prod --gpl2",
"build": "wp-scripts build",
"dev": "wp-scripts start",
"env": "wp-env",
"wp-env": "wp-env",
"gulp": "gulp",
"lint": "npm-run-all --parallel lint:*",
"lint:css": "wp-scripts lint-style '**/*.scss'",
Expand Down
10 changes: 2 additions & 8 deletions php/Blocks/Controls/Multiselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ public function register_settings() {
'label' => __( 'Choices', 'genesis-custom-blocks' ),
'type' => 'textarea_array',
'default' => '',
'help' => sprintf(
'%s %s<br />%s<br />%s',
__( 'Enter each choice on a new line.', 'genesis-custom-blocks' ),
__( 'To specify the value and label separately, use this format:', 'genesis-custom-blocks' ),
_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.

'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ],
]
);
Expand All @@ -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.

'sanitize' => [ $this, 'sanitize_textarea_array' ],
'validate' => [ $this, 'validate_options' ],
]
Expand Down
8 changes: 1 addition & 7 deletions php/Blocks/Controls/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ public function register_settings() {
'label' => __( 'Choices', 'genesis-custom-blocks' ),
'type' => 'textarea_array',
'default' => '',
'help' => sprintf(
'%s %s<br />%s<br />%s',
__( 'Enter each choice on a new line.', 'genesis-custom-blocks' ),
__( 'To specify the value and label separately, use this format:', 'genesis-custom-blocks' ),
_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' => '',
'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ],
]
);
Expand Down
8 changes: 1 addition & 7 deletions php/Blocks/Controls/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ public function register_settings() {
'label' => __( 'Choices', 'genesis-custom-blocks' ),
'type' => 'textarea_array',
'default' => '',
'help' => sprintf(
'%s %s<br />%s<br />%s',
__( 'Enter each choice on a new line.', 'genesis-custom-blocks' ),
__( 'To specify the value and label separately, use this format:', 'genesis-custom-blocks' ),
_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' => '',
'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ],
]
);
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Unit/Blocks/Controls/TestMultiselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function test_register_settings() {
'label' => 'Choices',
'type' => 'textarea_array',
'default' => '',
'help' => 'Enter each choice on a new line. To specify the value and label separately, use this format:<br />foo : Foo<br />bar : Bar',
'help' => '',
'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ],
'validate' => '',
'value' => null,
Expand All @@ -95,7 +95,7 @@ public function test_register_settings() {
'label' => 'Default Value',
'type' => 'textarea_array',
'default' => '',
'help' => 'Enter each default value on a new line.',
'help' => 'Each default value on a new line.',
'sanitize' => [ $this->instance, 'sanitize_textarea_array' ],
'validate' => [ $this->instance, 'validate_options' ],
'value' => null,
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Unit/Blocks/Controls/TestRadio.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function test_register_settings() {
'label' => 'Choices',
'type' => 'textarea_array',
'default' => '',
'help' => 'Enter each choice on a new line. To specify the value and label separately, use this format:<br />foo : Foo<br />bar : Bar',
'help' => '',
'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ],
'validate' => '',
'value' => null,
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Unit/Blocks/Controls/TestSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function test_register_settings() {
'label' => 'Choices',
'type' => 'textarea_array',
'default' => '',
'help' => 'Enter each choice on a new line. To specify the value and label separately, use this format:<br />foo : Foo<br />bar : Bar',
'help' => '',
'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ],
'validate' => '',
'value' => null,
Expand Down