Skip to content

Commit 456da67

Browse files
draganescufushar
andauthored
OpenTable block: use only restaurant IDs and remove searching for name (#41162)
* Remove the name search feature for restaurants and use only restaurant IDs * changelog * Clarify restaurant => restaurant id in the block settings * Fix Embed button height * Update changelog --------- Co-authored-by: Ashar Fuadi <[email protected]>
1 parent 71da576 commit 456da67

File tree

5 files changed

+19
-66
lines changed

5 files changed

+19
-66
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: other
3+
4+
OpenTable block: removed the ability to search restaurants by name

projects/plugins/jetpack/extensions/blocks/opentable/edit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function OpenTableEdit( {
235235
label={ __( 'OpenTable Reservation', 'jetpack' ) }
236236
icon={ icon }
237237
instructions={ __(
238-
'Enter your restaurant name, or paste an OpenTable Reservation Widget embed code.',
238+
'Enter your restaurants IDs, separated by comma, or paste an OpenTable Reservation Widget embed code.',
239239
'jetpack'
240240
) }
241241
notices={ noticeUI }

projects/plugins/jetpack/extensions/blocks/opentable/editor.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
padding-top: 0px;
5858
padding-right: 8px;
5959
padding-left: 8px;
60-
height: 42px;
60+
height: 38px;
6161
align-items: center;
6262
line-height: normal;
6363

Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
import { Button, FormTokenField, Notice } from '@wordpress/components';
1+
import { Button, FormTokenField } from '@wordpress/components';
22
import { useState } from '@wordpress/element';
33
import { __, _n } from '@wordpress/i18n';
44
import { isEmpty } from 'lodash';
5-
import useRestaurantSearch, { possibleEmbed } from './use-restaurant-search';
65

7-
const MAX_SUGGESTIONS = 20;
6+
export const possibleEmbed = /^\s*(http[s]?:\/\/|<script)/;
87

98
export default function RestaurantPicker( props ) {
109
const [ input, setInput ] = useState( '' );
11-
const { restaurants, hasRequestFailed } = useRestaurantSearch( input, MAX_SUGGESTIONS );
1210
const [ selectedRestaurants, setSelectedRestaurants ] = useState( props.rids || [] );
1311

1412
const idRegex = /^(\d+)$|\(#(\d+)\)$/;
1513

1614
const onChange = selected => {
15+
// we try to parse the restaurant id
1716
const selectedIds = selected.map( restaurant => {
1817
const parsed = idRegex.exec( restaurant );
19-
const selectedId = parsed[ 1 ] || parsed[ 2 ];
20-
21-
return selectedId;
18+
if ( parsed ) {
19+
const selectedId = parsed[ 1 ] || parsed[ 2 ];
20+
return selectedId;
21+
}
22+
// and default we to user entry
23+
return restaurant;
2224
} );
2325
setSelectedRestaurants( selectedIds );
2426
props.onChange && props.onChange( selectedIds );
2527
};
2628

27-
const restaurantNames = restaurants
28-
.filter( restaurant => selectedRestaurants.indexOf( restaurant.rid.toString() ) < 0 )
29-
.map( restaurant => restaurant.name + ` (#${ restaurant.rid })` );
30-
3129
const onSubmit = event => {
3230
event.preventDefault();
3331
props.onSubmit( isEmpty( selectedRestaurants ) ? input : selectedRestaurants );
3432
};
3533

34+
// Even though we don't search the OpenTable API
35+
// we still allow for multiple restaurants, hence
36+
// still use the token field
3637
const formInput = (
3738
<FormTokenField
3839
value={ selectedRestaurants }
39-
suggestions={ restaurantNames }
4040
saveTransform={ token => ( possibleEmbed.test( token ) ? '' : token.trim() ) }
4141
onInputChange={ setInput }
42-
maxSuggestions={ MAX_SUGGESTIONS }
43-
label={ _n( 'Restaurant', 'Restaurants', selectedRestaurants.length, 'jetpack' ) }
42+
label={ _n( 'Restaurant ID', 'Restaurant IDs', selectedRestaurants.length, 'jetpack' ) }
4443
{ ...props }
4544
onChange={ onChange }
4645
__nextHasNoMarginBottom={ true }
@@ -59,14 +58,6 @@ export default function RestaurantPicker( props ) {
5958
) : (
6059
formInput
6160
) }
62-
{ hasRequestFailed && (
63-
<Notice status="error" isDismissible={ false }>
64-
{ __(
65-
"OpenTable can't find this restaurant right now. Please try again later.",
66-
'jetpack'
67-
) }
68-
</Notice>
69-
) }
7061
</div>
7162
);
7263
}

projects/plugins/jetpack/extensions/blocks/opentable/use-restaurant-search.js

-42
This file was deleted.

0 commit comments

Comments
 (0)