Skip to content

Commit

Permalink
19.1 cherry picks (#64876)
Browse files Browse the repository at this point in the history
* DataViews: Add missing styles and remove opinionated ones for generic usage (#64711)

Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>

* Shuffle: Don't call '__experimentalGetAllowedPatterns' for every block (#64736)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: wpsoul <wpsoul@git.wordpress.org>

* DataViews: hide sort direction control if there is no sortable fields (#64817)

Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>

* Block Bindings: Refactor utils file. (#64740)

* Refactor block binding utils

* Add security checks

Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

* Interactivity API: Fix computeds without scope in Firefox (#64825)

* Replace NO_SCOPE symbol with an object

* Update changelog

Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
Co-authored-by: Marc-pi <mdxfr@git.wordpress.org>

---------

Co-authored-by: Riad Benguella <benguella@gmail.com>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: wpsoul <wpsoul@git.wordpress.org>
Co-authored-by: André <583546+oandregal@users.noreply.github.com>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com>
Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: David Arenas <david.arenas@automattic.com>
Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
Co-authored-by: Marc-pi <mdxfr@git.wordpress.org>
  • Loading branch information
20 people authored Aug 28, 2024
1 parent b5f63e5 commit fb74faf
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 29 deletions.
16 changes: 9 additions & 7 deletions packages/block-editor/src/components/block-toolbar/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ export default function Shuffle( { clientId, as = Container } ) {
const _categories = attributes?.metadata?.categories || EMPTY_ARRAY;
const _patternName = attributes?.metadata?.patternName;
const rootBlock = getBlockRootClientId( clientId );
const _patterns = __experimentalGetAllowedPatterns( rootBlock );

// Calling `__experimentalGetAllowedPatterns` is expensive.
// Checking if the block can be shuffled prevents unnecessary selector calls.
// See: https://github.com/WordPress/gutenberg/pull/64736.
const _patterns =
_categories.length > 0
? __experimentalGetAllowedPatterns( rootBlock )
: EMPTY_ARRAY;
return {
categories: _categories,
patterns: _patterns,
Expand All @@ -45,12 +52,7 @@ export default function Shuffle( { clientId, as = Container } ) {
);
const { replaceBlocks } = useDispatch( blockEditorStore );
const sameCategoryPatternsWithSingleWrapper = useMemo( () => {
if (
! categories ||
categories.length === 0 ||
! patterns ||
patterns.length === 0
) {
if ( categories.length === 0 || ! patterns || patterns.length === 0 ) {
return EMPTY_ARRAY;
}
return patterns.filter( ( pattern ) => {
Expand Down
31 changes: 15 additions & 16 deletions packages/block-editor/src/utils/block-bindings.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/**
* WordPress dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { useDispatch, useRegistry } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../store';
import { useBlockEditContext } from '../components/block-edit';

function isObjectEmpty( object ) {
return ! object || Object.keys( object ).length === 0;
}

export function useBlockBindingsUtils() {
const { clientId } = useBlockEditContext();
const { updateBlockAttributes } = useDispatch( blockEditorStore );
const { getBlockAttributes } = useSelect( blockEditorStore );
const { getBlockAttributes } = useRegistry().select( blockEditorStore );

/**
* Updates the value of the bindings connected to block attributes.
Expand Down Expand Up @@ -44,8 +48,10 @@ export function useBlockBindingsUtils() {
* ```
*/
const updateBlockBindings = ( bindings ) => {
const { metadata } = getBlockAttributes( clientId );
const newBindings = { ...metadata?.bindings };
const { metadata: { bindings: currentBindings, ...metadata } = {} } =
getBlockAttributes( clientId );
const newBindings = { ...currentBindings };

Object.entries( bindings ).forEach( ( [ attribute, binding ] ) => {
if ( ! binding && newBindings[ attribute ] ) {
delete newBindings[ attribute ];
Expand All @@ -59,15 +65,12 @@ export function useBlockBindingsUtils() {
bindings: newBindings,
};

if ( Object.keys( newMetadata.bindings ).length === 0 ) {
if ( isObjectEmpty( newMetadata.bindings ) ) {
delete newMetadata.bindings;
}

updateBlockAttributes( clientId, {
metadata:
Object.keys( newMetadata ).length === 0
? undefined
: newMetadata,
metadata: isObjectEmpty( newMetadata ) ? undefined : newMetadata,
} );
};

Expand All @@ -83,14 +86,10 @@ export function useBlockBindingsUtils() {
* ```
*/
const removeAllBlockBindings = () => {
const { metadata } = getBlockAttributes( clientId );
const newMetadata = { ...metadata };
delete newMetadata.bindings;
const { metadata: { bindings, ...metadata } = {} } =
getBlockAttributes( clientId );
updateBlockAttributes( clientId, {
metadata:
Object.keys( newMetadata ).length === 0
? undefined
: newMetadata,
metadata: isObjectEmpty( metadata ) ? undefined : metadata,
} );
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ function SortFieldControl() {

function SortDirectionControl() {
const { view, fields, onChangeView } = useContext( DataViewsContext );

const sortableFields = fields.filter(
( field ) => field.enableSorting !== false
);
if ( sortableFields.length === 0 ) {
return null;
}

let value = view.sort?.direction;
if ( ! value && view.sort?.field ) {
value = 'desc';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
}
}

.dataviews-settings-section:has(.dataviews-settings-section__content:empty) {
display: none;
}

/* stylelint-disable-next-line scss/at-rule-no-unknown -- '@container' not globally permitted */
@container (max-width: 500px) {
.dataviews-settings-section.dataviews-settings-section {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ export const fields = [
id: 'title',
enableHiding: false,
enableGlobalSearch: true,
render: ( { item } ) => {
return <a href="#nothing">{ item.title }</a>;
},
},
{
id: 'date',
Expand Down
1 change: 1 addition & 0 deletions packages/dataviews/src/dataviews-layouts/list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
}

.dataviews-view-list__item {
box-sizing: border-box;
padding: $grid-unit-20 $grid-unit-30;
width: 100%;
scroll-margin: $grid-unit-10 0;
Expand Down
5 changes: 0 additions & 5 deletions packages/dataviews/src/dataviews-layouts/table/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
color: $gray-700;
margin-bottom: auto;

a {
text-decoration: none;
color: $gray-900;
font-weight: 500;
}
th {
text-align: left;
color: $gray-900;
Expand Down
4 changes: 4 additions & 0 deletions packages/interactivity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- Fix computeds without scope in Firefox ([#64825](https://github.com/WordPress/gutenberg/pull/64825)).

## 6.6.0 (2024-08-21)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/interactivity/src/proxies/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { withScope } from '../utils';
/**
* Identifier for property computeds not associated to any scope.
*/
const NO_SCOPE = Symbol();
const NO_SCOPE = {};

/**
* Structure that manages reactivity for a property in a state object. It uses
Expand Down

0 comments on commit fb74faf

Please sign in to comment.