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

Miscellaneous updates #157

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions client/src/block-editor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// External dependencies.
import React from 'react';
import { __ } from '@wordpress/i18n';
import { registerPlugin } from '@wordpress/plugins';

Expand All @@ -8,10 +7,10 @@ import {
BylineManagerPanelInfoProvider,
BylineManagerPanelInfo,
BylineSlotContainer,
} from 'containers';
} from './containers';

// Register our store.
import { store } from './store';
// Get and register our store.
import store from './store';

// Styles.
import './styles/styles.scss';
Expand Down
25 changes: 19 additions & 6 deletions client/src/components/byline-autocomplete/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// External dependencies.
import React from 'react';
import { useState, useEffect } from '@wordpress/element';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import Autocomplete from 'react-autocomplete';

// Hooks.
import { useDebounce } from '@uidotdev/usehooks';

const BylineAutocomplete = ({
id,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think these components could benefit from a forwardRef. But I don't have a use case for it yet. 🤔

profiles,
onUpdate,
profilesApiUrl,
Expand Down Expand Up @@ -40,7 +41,7 @@ const BylineAutocomplete = ({
className: 'components-text-control__input',
type: 'text',
placeholder: addAuthorPlaceholder,
id: 'profiles_autocomplete',
id,
onKeyDown: (e) => {
// If the user hits 'enter', stop the parent form from submitting.
if (13 === e.keyCode) {
Expand All @@ -59,7 +60,7 @@ const BylineAutocomplete = ({
<div className="profile-controls components-base-control__field">
<label
className="components-base-control__label"
htmlFor="profiles_autocomplete"
htmlFor={id}
>
{addAuthorLabel}
</label>
Expand All @@ -69,22 +70,29 @@ const BylineAutocomplete = ({
value={search}
getItemValue={(item) => item.name}
wrapperStyle={{ position: 'relative', display: 'block' }}
onSelect={(value, item) => {
onSelect={(__, item) => {
setSearch('');
setSearchResults([]);

onUpdate(item);
}}
onChange={(event, next) => setSearch(next)}
onChange={(__, next) => setSearch(next)}
renderMenu={(children) => (
<div className="menu">
{children}
</div>
)}
renderItem={(item, isHighlighted) => (
<div
className={`item ${isHighlighted ? 'item-highlighted' : ''}`}
key={item.id}
className={
classNames(
'item',
{
'item-highlighted': isHighlighted,
}
)
}
>
{item.name}
</div>
Expand All @@ -97,7 +105,12 @@ const BylineAutocomplete = ({
);
};

BylineAutocomplete.defaultProps = {
id: 'profiles_autocomplete',
};

BylineAutocomplete.propTypes = {
id: PropTypes.string,
profiles: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.oneOfType([
PropTypes.number,
Expand Down
15 changes: 10 additions & 5 deletions client/src/components/byline-freeform/index.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// External dependencies.
import React from 'react';
import PropTypes from 'prop-types';
import { Button } from '@wordpress/components';
import { useState } from '@wordpress/element';

const BylineFreeform = ({
id,
addFreeformLabel,
addFreeformPlaceholder,
addFreeformButtonLabel,
Expand Down Expand Up @@ -32,15 +32,15 @@ const BylineFreeform = ({
>
<label
className="components-base-control__label"
htmlFor="byline_freeform"
htmlFor={id}
>
{addFreeformLabel}
</label>
<div className="freeformInputGrp">
<input
className="components-text-control__input"
id="byline_freeform"
name="byline_freeform"
id={id}
name={id}
onChange={(e) => {
setTextByline(e.target.value);
}}
Expand All @@ -51,9 +51,9 @@ const BylineFreeform = ({
<Button
label={addFreeformButtonLabel}
className="button"
size="small"
variant="secondary"
disabled={! textByline}
isSmall
onClick={onSubmit}
>
{addFreeformButtonLabel}
Expand All @@ -63,7 +63,12 @@ const BylineFreeform = ({
);
};

BylineFreeform.defaultProps = {
id: 'byline_freeform',
};

BylineFreeform.propTypes = {
id: PropTypes.string,
addFreeformLabel: PropTypes.string.isRequired,
addFreeformPlaceholder: PropTypes.string.isRequired,
addFreeformButtonLabel: PropTypes.string.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/byline-list-item/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const BylineListItem = SortableElement(({
label={removeAuthorLabel}
isDestructive
variant="secondary"
isSmall
size="small"
onClick={(e) => {
e.preventDefault();
removeItem();
Expand Down
1 change: 0 additions & 1 deletion client/src/components/byline-metabox/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global bylineData */

// External dependencies.
import React from 'react';
import PropTypes from 'prop-types';

// Internal dependencies.
Expand Down
28 changes: 18 additions & 10 deletions client/src/components/byline-profiles/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// External dependencies.
import React from 'react';
import PropTypes from 'prop-types';
import { useState, useEffect } from '@wordpress/element';
import classNames from 'classnames';
Expand Down Expand Up @@ -38,7 +37,7 @@ const SortableItem = SortableElement(({
<Button
label={removeAuthorLabel}
isDestructive
isSmall
size="small"
variant="secondary"
onClick={(e) => {
e.preventDefault();
Expand Down Expand Up @@ -72,6 +71,8 @@ const BylineList = SortableContainer(({
));

const BylineProfiles = ({
autocompleteInputId,
freeformInputId,
addAuthorLabel,
addAuthorPlaceholder,
addFreeformButtonLabel,
Expand Down Expand Up @@ -123,7 +124,7 @@ const BylineProfiles = ({
className: 'components-text-control__input',
type: 'text',
placeholder: addAuthorPlaceholder,
id: 'profiles_autocomplete',
id: autocompleteInputId,
onKeyDown: (e) => {
// If the user hits 'enter', stop the parent form from submitting.
if (13 === e.keyCode) {
Expand All @@ -145,7 +146,7 @@ const BylineProfiles = ({
{/* eslint-disable jsx-a11y/label-has-for */}
<label
className="components-base-control__label"
htmlFor="profiles_autocomplete"
htmlFor={autocompleteInputId}
>
{addAuthorLabel}
</label>
Expand All @@ -155,12 +156,12 @@ const BylineProfiles = ({
value={search}
getItemValue={(item) => item.name}
wrapperStyle={{ position: 'relative', display: 'block' }}
onSelect={(item, next) => {
onSelect={(__, next) => {
setSearch('');
setSearchResults([]);
setProfiles([...profiles, next]);
}}
onChange={(event, next) => setSearch(next)}
onChange={(__, next) => setSearch(next)}
renderMenu={(children) => (
<div className="menu">
{children}
Expand All @@ -186,15 +187,15 @@ const BylineProfiles = ({
<div className="freeform-controls components-base-control__field">
<label
className="components-base-control__label"
htmlFor="byline_freeform"
htmlFor={freeformInputId}
>
{addFreeformLabel}
</label>
<div className="freeformInputGrp">
<input
className="components-text-control__input"
id="byline_freeform"
name="byline_freeform"
id={freeformInputId}
name={freeformInputId}
onChange={(e) => {
setValue(e.target.value);
}}
Expand All @@ -206,8 +207,8 @@ const BylineProfiles = ({
label={addFreeformButtonLabel}
className="button"
disabled={! value}
size="small"
variant="secondary"
isSmall
onClick={(e) => {
e.preventDefault();
const newItem = {
Expand Down Expand Up @@ -239,7 +240,14 @@ const BylineProfiles = ({
);
};

BylineProfiles.defaultProps = {
autocompleteInputId: 'profiles_autocomplete',
freeformInputId: 'byline_freeform',
};

BylineProfiles.propTypes = {
autocompleteInputId: PropTypes.string,
freeformInputId: PropTypes.string,
addAuthorLabel: PropTypes.string.isRequired,
addAuthorPlaceholder: PropTypes.string.isRequired,
addFreeformButtonLabel: PropTypes.string.isRequired,
Expand Down
43 changes: 25 additions & 18 deletions client/src/components/byline-slot-wrapper/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global bylineData */

// External dependencies.
import React from 'react';
import PropTypes from 'prop-types';
import { Spinner } from '@wordpress/components';
import { Fragment } from '@wordpress/element';
Expand All @@ -12,17 +11,19 @@ import BylineFreeform from '../byline-freeform';
import BylineList from '../byline-list';

const BylineSlotWrapper = ({
profiles,
addProfile,
removeProfile,
reorderProfile,
addAuthorLabel,
addAuthorPlaceholder,
removeAuthorLabel,
addFreeformButtonLabel,
addFreeformLabel,
addFreeformPlaceholder,
addFreeformButtonLabel,
addProfile,
autocompleteInputId,
freeformInputId,
profiles,
profilesApiUrl,
removeAuthorLabel,
removeProfile,
reorderProfile,
}) => (
<div className="components-base-control">
{null === profiles ? (
Expand All @@ -32,13 +33,15 @@ const BylineSlotWrapper = ({
) : (
<Fragment>
<BylineAutocomplete
id={autocompleteInputId}
profiles={profiles}
onUpdate={addProfile}
profilesApiUrl={profilesApiUrl || bylineData.profilesApiUrl}
addAuthorPlaceholder={addAuthorPlaceholder || bylineData.addAuthorPlaceholder}
addAuthorLabel={addAuthorLabel || bylineData.addAuthorLabel}
/>
<BylineFreeform
id={freeformInputId}
onUpdate={addProfile}
addFreeformLabel={addFreeformLabel || bylineData.addFreeformLabel}
addFreeformPlaceholder={addFreeformPlaceholder || bylineData.addFreeformPlaceholder}
Expand All @@ -60,17 +63,27 @@ const BylineSlotWrapper = ({
);

BylineSlotWrapper.defaultProps = {
profiles: [],
addAuthorLabel: null,
addAuthorPlaceholder: null,
removeAuthorLabel: null,
addFreeformButtonLabel: null,
addFreeformLabel: null,
addFreeformPlaceholder: null,
addFreeformButtonLabel: null,
autocompleteInputId: 'profiles_autocomplete',
freeformInputId: 'byline_freeform',
profiles: [],
profilesApiUrl: null,
removeAuthorLabel: null,
};

BylineSlotWrapper.propTypes = {
addAuthorLabel: PropTypes.string,
addAuthorPlaceholder: PropTypes.string,
addFreeformButtonLabel: PropTypes.string,
addFreeformLabel: PropTypes.string,
addFreeformPlaceholder: PropTypes.string,
addProfile: PropTypes.func.isRequired,
autocompleteInputId: PropTypes.string,
freeformInputId: PropTypes.string,
profiles: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.oneOfType([
PropTypes.number,
Expand All @@ -83,16 +96,10 @@ BylineSlotWrapper.propTypes = {
PropTypes.string,
]),
})),
addProfile: PropTypes.func.isRequired,
profilesApiUrl: PropTypes.string,
removeAuthorLabel: PropTypes.string,
removeProfile: PropTypes.func.isRequired,
reorderProfile: PropTypes.func.isRequired,
addAuthorLabel: PropTypes.string,
addAuthorPlaceholder: PropTypes.string,
removeAuthorLabel: PropTypes.string,
addFreeformLabel: PropTypes.string,
addFreeformPlaceholder: PropTypes.string,
addFreeformButtonLabel: PropTypes.string,
profilesApiUrl: PropTypes.string,
};

export default BylineSlotWrapper;
Loading