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

fix: revert "feat(homepage-articles): rename block and reorganise settings (#1943)" #1971

Merged
merged 1 commit into from
Nov 25, 2024
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
514 changes: 261 additions & 253 deletions src/blocks/homepage-articles/edit.tsx

Large diffs are not rendered by default.

50 changes: 0 additions & 50 deletions src/blocks/homepage-articles/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,54 +61,4 @@
opacity: 0.6;
}
}

&__panel {
.spacing-sizes-control {
.components-range-control__root {
> span {
margin-top: 0;
}
}
}

> *:not(.components-panel__body-title) {
margin-bottom: 16px;
margin-top: 0;

&:last-of-type {
margin-bottom: 8px;
}
}

&.is-loop {
.autocomplete-tokenfield + .components-checkbox-control {
margin-top: -8px;
}
}
}

&__button-group {
flex: 0 0 100%;

.components-base-control__label {
width: 100%;
}

.components-button-group {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));

button {
justify-content: center;
}
}
}
}

.components-base-control__field:empty {
display: none;

+ .components-base-control__help {
margin: 0;
}
}
20 changes: 4 additions & 16 deletions src/blocks/homepage-articles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { name, attributes, category } = metadata;
// Name must be exported separately.
export { name };

export const title = __( 'Content Loop', 'newspack-blocks' );
export const title = __( 'Homepage Posts', 'newspack-blocks' );

export const icon = (
<SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
Expand All @@ -48,23 +48,11 @@ export const settings = {
__( 'posts', 'newspack-blocks' ),
__( 'articles', 'newspack-blocks' ),
__( 'latest', 'newspack-blocks' ),
__( 'homepage', 'newspack-blocks' ),
__( 'query', 'newspack-blocks' ),
],
description: __(
'An advanced block that allows displaying content based on different parameters and visual configurations.',
'newspack-blocks'
),
description: __( 'A block for displaying homepage posts.', 'newspack-blocks' ),
styles: [
{
name: 'default',
label: _x('Default', 'block style', 'newspack-blocks'),
isDefault: true,
},
{
name: 'borders',
label: _x('Borders', 'block style', 'newspack-blocks'),
},
{ name: 'default', label: _x( 'Default', 'block style', 'newspack-blocks' ), isDefault: true },
{ name: 'borders', label: _x( 'Borders', 'block style', 'newspack-blocks' ) },
],
supports: {
html: false,
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/homepage-articles/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export const postsBlockDispatch = (
) => {
return {
// Only editor blocks can trigger reflows.
// @ts-expect-error It's a string.
// @ts-ignore It's a string.
triggerReflow: isEditorBlock ? dispatch( STORE_NAMESPACE ).reflow : () => undefined,
};
};
Expand Down
1 change: 0 additions & 1 deletion src/components/autocomplete-tokenfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ class AutocompleteTokenField extends Component {
onChange={ tokens => this.handleOnChange( tokens ) }
onInputChange={ input => this.debouncedUpdateSuggestions( input ) }
label={ label }
__next40pxDefaultSize
/>
{ loading && <Spinner /> }
{ help && <p className="autocomplete-tokenfield__help">{ help }</p> }
Expand Down
13 changes: 2 additions & 11 deletions src/components/autocomplete-tokenfield.scss
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
@use "~@wordpress/base-styles/colors" as wp-colors;

.autocomplete-tokenfield {
max-width: 100%;
position: relative;

.components-spinner {
bottom: 12px;
position: absolute;
top: 2em;
right: 0;
}

&:has(.autocomplete-tokenfield__help) .components-spinner {
bottom: calc(36px + 8px + 12px);
}

/* Workaround for hard-coded help text in FormTokenField. */
.components-form-token-field > .components-form-token-field__help {
display: none;
}

.autocomplete-tokenfield__help {
color: wp-colors.$gray-700;
font-size: 12px;
margin: 8px 0;
font-style: italic;
}
}
44 changes: 26 additions & 18 deletions src/components/editor-panels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { BaseControl, CheckboxControl, PanelBody, Spinner } from '@wordpress/components';
import { Spinner, CheckboxControl, PanelBody, PanelRow } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

const CheckboxesGroup = ( { options, values, onChange } ) => {
if ( ! Array.isArray( options ) ) {
return <Spinner />;
}
return options.map( ( { name, slug } ) => (
<CheckboxControl
label={ name }
checked={ values.indexOf( slug ) > -1 }
onChange={ value => {
const cleanPostType = [ ...new Set( values ) ];
if ( value && cleanPostType.indexOf( slug ) === -1 ) {
cleanPostType.push( slug );
} else if ( ! value && cleanPostType.indexOf( slug ) > -1 ) {
cleanPostType.splice( cleanPostType.indexOf( slug ), 1 );
}
onChange( cleanPostType );
} }
key={ slug }
/>
<PanelRow key={ slug }>
<CheckboxControl
label={ name }
checked={ values.indexOf( slug ) > -1 }
onChange={ value => {
const cleanPostType = [ ...new Set( values ) ];
if ( value && cleanPostType.indexOf( slug ) === -1 ) {
cleanPostType.push( slug );
} else if ( ! value && cleanPostType.indexOf( slug ) > -1 ) {
cleanPostType.splice( cleanPostType.indexOf( slug ), 1 );
}
onChange( cleanPostType );
} }
/>
</PanelRow>
) );
};

Expand All @@ -49,7 +50,7 @@ export const PostTypesPanel = ( { attributes, setAttributes } ) => {
} );

return (
<PanelBody title={ __( 'Post Types', 'newspack-blocks' ) } initialOpen={ false }>
<PanelBody title={ __( 'Post Types', 'newspack-blocks' ) }>
<CheckboxesGroup
options={ availablePostTypes }
values={ attributes.postType }
Expand All @@ -61,8 +62,15 @@ export const PostTypesPanel = ( { attributes, setAttributes } ) => {

export const PostStatusesPanel = ( { attributes, setAttributes } ) => {
return (
<PanelBody title={ __( 'Additional Post Statuses', 'newspack-blocks' ) } initialOpen={ false }>
<BaseControl help={ __( 'Selection here has effect only for editors, regular users will only see published posts.', 'newspack-blocks' ) } />
<PanelBody title={ __( 'Additional Post Statuses', 'newspack-blocks' ) }>
<PanelRow>
<i>
{ __(
'Selection here has effect only for editors, regular users will only see published posts.',
'newspack-blocks'
) }
</i>
</PanelRow>
<CheckboxesGroup
values={ attributes.includedPostStatuses }
options={ [
Expand Down
Loading