diff --git src/bp-core/bp-core-blocks.php src/bp-core/bp-core-blocks.php
index d2cda8de1..f2f7a8c2c 100644
|
|
function bp_register_block_components() { |
36 | 36 | 'wp-components', |
37 | 37 | 'wp-i18n', |
38 | 38 | 'wp-api-fetch', |
| 39 | 'wp-url', |
39 | 40 | ), |
40 | 41 | bp_get_version() |
41 | 42 | ); |
diff --git src/bp-core/js/block-components.js src/bp-core/js/block-components.js
index 2aede5129..61fdbd331 100644
|
|
var _wp$element = wp.element, |
260 | 260 | var Popover = wp.components.Popover; |
261 | 261 | var _wp = wp, |
262 | 262 | apiFetch = _wp.apiFetch; |
| 263 | var addQueryArgs = wp.url.addQueryArgs; |
263 | 264 | var __ = wp.i18n.__; |
264 | 265 | |
265 | 266 | var AutoCompleter = /*#__PURE__*/function (_Component) { |
… |
… |
var AutoCompleter = /*#__PURE__*/function (_Component) { |
290 | 291 | var search = this.state.search; |
291 | 292 | var _this$props = this.props, |
292 | 293 | component = _this$props.component, |
293 | | objectStatus = _this$props.objectStatus; |
| 294 | objectQueryArgs = _this$props.objectQueryArgs; |
294 | 295 | this.setState({ |
295 | 296 | search: value |
296 | 297 | }); |
… |
… |
var AutoCompleter = /*#__PURE__*/function (_Component) { |
302 | 303 | } |
303 | 304 | |
304 | 305 | var path = '/buddypress/v1/' + component; |
| 306 | var queryArgs = {}; |
305 | 307 | |
306 | 308 | if (value) { |
307 | | path += '?search=' + encodeURIComponent(value); |
| 309 | queryArgs.search = encodeURIComponent(value); |
308 | 310 | } |
309 | 311 | |
310 | | if (objectStatus) { |
311 | | path += '&status=' + objectStatus; |
| 312 | if (objectQueryArgs) { |
| 313 | queryArgs = Object.assign(queryArgs, objectQueryArgs); |
312 | 314 | } |
313 | 315 | |
314 | 316 | apiFetch({ |
315 | | path: path |
| 317 | path: addQueryArgs(path, queryArgs) |
316 | 318 | }).then(function (items) { |
317 | 319 | _this2.setState({ |
318 | 320 | items: items |
… |
… |
var AutoCompleter = /*#__PURE__*/function (_Component) { |
348 | 350 | var _this$props2 = this.props, |
349 | 351 | ariaLabel = _this$props2.ariaLabel, |
350 | 352 | placeholder = _this$props2.placeholder, |
351 | | useAvatar = _this$props2.useAvatar; |
| 353 | useAvatar = _this$props2.useAvatar, |
| 354 | slugValue = _this$props2.slugValue; |
352 | 355 | var itemsList; |
353 | 356 | |
354 | 357 | if (!ariaLabel) { |
… |
… |
var AutoCompleter = /*#__PURE__*/function (_Component) { |
378 | 381 | }), createElement("span", { |
379 | 382 | key: "name", |
380 | 383 | className: "editor-autocompleters__user-name" |
381 | | }, item.name), item.mention_name && createElement("span", { |
| 384 | }, item.name), slugValue && null !== slugValue(item) && createElement("span", { |
382 | 385 | key: "slug", |
383 | 386 | className: "editor-autocompleters__user-slug" |
384 | | }, item.mention_name)); |
| 387 | }, slugValue(item))); |
385 | 388 | }); |
386 | 389 | } |
387 | 390 | |
diff --git src/bp-groups/css/blocks/group-rtl.css src/bp-groups/css/blocks/group-rtl.css
index dce932ac8..9a562f910 100644
|
|
|
116 | 116 | display: block; |
117 | 117 | float: left; |
118 | 118 | } |
| 119 | |
| 120 | [data-type="bp/group"] input.components-placeholder__input { |
| 121 | flex: 1 1 auto; |
| 122 | border-radius: 2px; |
| 123 | border: 1px solid #757575; |
| 124 | padding: 6px 8px; |
| 125 | } |
diff --git src/bp-groups/css/blocks/group.css src/bp-groups/css/blocks/group.css
index 502b70b69..2244557d4 100644
|
|
|
116 | 116 | display: block; |
117 | 117 | float: right; |
118 | 118 | } |
| 119 | |
| 120 | [data-type="bp/group"] input.components-placeholder__input { |
| 121 | flex: 1 1 auto; |
| 122 | border-radius: 2px; |
| 123 | border: 1px solid #757575; |
| 124 | padding: 6px 8px; |
| 125 | } |
diff --git src/bp-groups/js/blocks/group.js src/bp-groups/js/blocks/group.js
index b92f36f28..103a5908e 100644
|
|
var AVATAR_SIZES = [{ |
155 | 155 | label: __('Full', 'buddypress'), |
156 | 156 | value: 'full' |
157 | 157 | }]; |
| 158 | var GROUP_STATI = { |
| 159 | public: __('Public', 'buddypress'), |
| 160 | private: __('Private', 'buddypress'), |
| 161 | hidden: __('Hidden', 'buddypress') |
| 162 | }; |
| 163 | |
| 164 | var getSlugValue = function getSlugValue(item) { |
| 165 | if (item && item.status && GROUP_STATI[item.status]) { |
| 166 | return GROUP_STATI[item.status]; |
| 167 | } |
| 168 | |
| 169 | return null; |
| 170 | }; |
158 | 171 | |
159 | 172 | var editGroup = function editGroup(_ref) { |
160 | 173 | var attributes = _ref.attributes, |
… |
… |
var editGroup = function editGroup(_ref) { |
174 | 187 | instructions: __('Start typing the name of the group you want to feature into this post.', 'buddypress') |
175 | 188 | }, createElement(AutoCompleter, { |
176 | 189 | component: "groups", |
177 | | objectStatus: "public", |
| 190 | objectQueryArgs: { |
| 191 | 'show_hidden': false |
| 192 | }, |
| 193 | slugValue: getSlugValue, |
178 | 194 | ariaLabel: __('Group\'s name', 'buddypress'), |
179 | 195 | placeholder: __('Enter Group\'s name here…', 'buddypress'), |
180 | 196 | onSelectItem: setAttributes, |
diff --git src/bp-members/css/blocks/member-rtl.css src/bp-members/css/blocks/member-rtl.css
index ff9de024c..7698bc8a0 100644
|
|
|
108 | 108 | display: inline-block; |
109 | 109 | margin: 18px 0 0; |
110 | 110 | } |
| 111 | |
| 112 | [data-type="bp/member"] input.components-placeholder__input { |
| 113 | flex: 1 1 auto; |
| 114 | border-radius: 2px; |
| 115 | border: 1px solid #757575; |
| 116 | padding: 6px 8px; |
| 117 | } |
diff --git src/bp-members/css/blocks/member.css src/bp-members/css/blocks/member.css
index b03ea8687..79f86f393 100644
|
|
|
108 | 108 | display: inline-block; |
109 | 109 | margin: 18px 0 0; |
110 | 110 | } |
| 111 | |
| 112 | [data-type="bp/member"] input.components-placeholder__input { |
| 113 | flex: 1 1 auto; |
| 114 | border-radius: 2px; |
| 115 | border: 1px solid #757575; |
| 116 | padding: 6px 8px; |
| 117 | } |
diff --git src/bp-members/js/blocks/member.js src/bp-members/js/blocks/member.js
index 3f78b0dc5..602568636 100644
|
|
var AVATAR_SIZES = [{ |
156 | 156 | value: 'full' |
157 | 157 | }]; |
158 | 158 | |
| 159 | var getSlugValue = function getSlugValue(item) { |
| 160 | if (item && item.mention_name) { |
| 161 | return item.mention_name; |
| 162 | } |
| 163 | |
| 164 | return null; |
| 165 | }; |
| 166 | |
159 | 167 | var editMember = function editMember(_ref) { |
160 | 168 | var attributes = _ref.attributes, |
161 | 169 | setAttributes = _ref.setAttributes, |
… |
… |
var editMember = function editMember(_ref) { |
175 | 183 | instructions: __('Start typing the name of the member you want to feature into this post.', 'buddypress') |
176 | 184 | }, createElement(AutoCompleter, { |
177 | 185 | component: "members", |
| 186 | slugValue: getSlugValue, |
178 | 187 | ariaLabel: __('Member\'s username', 'buddypress'), |
179 | 188 | placeholder: __('Enter Member\'s username here…', 'buddypress'), |
180 | 189 | onSelectItem: setAttributes, |
diff --git src/js/bp-core/js/block-components/components/autocompleter.js src/js/bp-core/js/block-components/components/autocompleter.js
index 30d0c7c2d..90e04e5d7 100644
|
|
|
4 | 4 | const { Component, Fragment, createElement } = wp.element; |
5 | 5 | const { Popover } = wp.components; |
6 | 6 | const { apiFetch } = wp; |
| 7 | const { addQueryArgs } = wp.url; |
7 | 8 | const { __ } = wp.i18n; |
8 | 9 | |
9 | 10 | class AutoCompleter extends Component { |
… |
… |
class AutoCompleter extends Component { |
22 | 23 | |
23 | 24 | searchItemName( value ) { |
24 | 25 | const { search } = this.state; |
25 | | const { component, objectStatus } = this.props; |
| 26 | const { component, objectQueryArgs } = this.props; |
26 | 27 | this.setState( { search: value } ); |
27 | 28 | |
28 | 29 | if ( value.length < search.length ) { |
… |
… |
class AutoCompleter extends Component { |
30 | 31 | } |
31 | 32 | |
32 | 33 | let path= '/buddypress/v1/' + component; |
| 34 | let queryArgs = {}; |
33 | 35 | |
34 | 36 | if ( value ) { |
35 | | path += '?search=' + encodeURIComponent( value ); |
| 37 | queryArgs.search = encodeURIComponent( value ); |
36 | 38 | } |
37 | 39 | |
38 | | if ( objectStatus ) { |
39 | | path += '&status=' + objectStatus; |
| 40 | if ( objectQueryArgs ) { |
| 41 | queryArgs = Object.assign( queryArgs, objectQueryArgs ); |
40 | 42 | } |
41 | 43 | |
42 | | apiFetch( { path: path } ).then( items => { |
| 44 | apiFetch( { path: addQueryArgs( path, queryArgs ) } ).then( items => { |
43 | 45 | this.setState( { items: items } ); |
44 | 46 | }, error => { |
45 | 47 | this.setState( { error: error.message } ); |
… |
… |
class AutoCompleter extends Component { |
61 | 63 | |
62 | 64 | render() { |
63 | 65 | const { search, items } = this.state; |
64 | | let { ariaLabel, placeholder, useAvatar } = this.props; |
| 66 | let { ariaLabel, placeholder, useAvatar, slugValue } = this.props; |
65 | 67 | let itemsList; |
66 | 68 | |
67 | 69 | if ( ! ariaLabel ) { |
… |
… |
class AutoCompleter extends Component { |
85 | 87 | { useAvatar && ( |
86 | 88 | <img key="avatar" className="editor-autocompleters__user-avatar" alt="" src={ item.avatar_urls.thumb } /> |
87 | 89 | ) } |
| 90 | |
88 | 91 | <span key="name" className="editor-autocompleters__user-name">{ item.name }</span> |
89 | 92 | |
90 | | { item.mention_name && ( |
91 | | <span key="slug" className="editor-autocompleters__user-slug">{ item.mention_name }</span> |
| 93 | { slugValue && null !== slugValue( item ) && ( |
| 94 | <span key="slug" className="editor-autocompleters__user-slug">{ slugValue( item ) }</span> |
92 | 95 | ) } |
93 | 96 | </button> |
94 | 97 | ); |
diff --git src/js/bp-groups/js/blocks/group.js src/js/bp-groups/js/blocks/group.js
index 2d95f05a6..dfb37f9a6 100644
|
|
const AVATAR_SIZES = [ |
30 | 30 | }, |
31 | 31 | ]; |
32 | 32 | |
| 33 | const GROUP_STATI = { |
| 34 | public: __( 'Public', 'buddypress' ), |
| 35 | private: __( 'Private', 'buddypress' ), |
| 36 | hidden: __( 'Hidden', 'buddypress' ), |
| 37 | }; |
| 38 | |
| 39 | const getSlugValue = ( item ) => { |
| 40 | if ( item && item.status && GROUP_STATI[ item.status ] ) { |
| 41 | return GROUP_STATI[ item.status ]; |
| 42 | } |
| 43 | |
| 44 | return null; |
| 45 | } |
| 46 | |
33 | 47 | const editGroup = ( { attributes, setAttributes, bpSettings } ) => { |
34 | 48 | const { isAvatarEnabled, isCoverImageEnabled } = bpSettings; |
35 | 49 | const { avatarSize, displayDescription, displayActionButton, displayCoverImage } = attributes; |
… |
… |
const editGroup = ( { attributes, setAttributes, bpSettings } ) => { |
43 | 57 | > |
44 | 58 | <AutoCompleter |
45 | 59 | component="groups" |
46 | | objectStatus="public" |
| 60 | objectQueryArgs={ { 'show_hidden': false } } |
| 61 | slugValue={ getSlugValue } |
47 | 62 | ariaLabel={ __( 'Group\'s name', 'buddypress' ) } |
48 | 63 | placeholder={ __( 'Enter Group\'s name here…', 'buddypress' ) } |
49 | 64 | onSelectItem={ setAttributes } |
diff --git src/js/bp-members/js/blocks/member.js src/js/bp-members/js/blocks/member.js
index 58ba9cb02..d70a32ae5 100644
|
|
const AVATAR_SIZES = [ |
30 | 30 | }, |
31 | 31 | ]; |
32 | 32 | |
| 33 | const getSlugValue = ( item ) => { |
| 34 | if ( item && item.mention_name ) { |
| 35 | return item.mention_name; |
| 36 | } |
| 37 | |
| 38 | return null; |
| 39 | } |
| 40 | |
33 | 41 | const editMember = ( { attributes, setAttributes, bpSettings } ) => { |
34 | 42 | const { isAvatarEnabled, isMentionEnabled, isCoverImageEnabled } = bpSettings; |
35 | 43 | const { avatarSize, displayMentionSlug, displayActionButton, displayCoverImage } = attributes; |
… |
… |
const editMember = ( { attributes, setAttributes, bpSettings } ) => { |
43 | 51 | > |
44 | 52 | <AutoCompleter |
45 | 53 | component="members" |
| 54 | slugValue={ getSlugValue } |
46 | 55 | ariaLabel={ __( 'Member\'s username', 'buddypress' ) } |
47 | 56 | placeholder={ __( 'Enter Member\'s username here…', 'buddypress' ) } |
48 | 57 | onSelectItem={ setAttributes } |