Skip to content

Commit

Permalink
revert gallery udpates
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Jun 28, 2022
1 parent d6f36a5 commit 4a243f3
Show file tree
Hide file tree
Showing 19 changed files with 1,986 additions and 54 deletions.
63 changes: 56 additions & 7 deletions packages/block-library/src/gallery/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { some, omit } from 'lodash';
import { map, some, omit } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -19,6 +19,7 @@ import {
LINK_DESTINATION_MEDIA,
LINK_DESTINATION_NONE,
} from './constants';
import { isGalleryV2Enabled } from './shared';

const DEPRECATED_LINK_DESTINATION_MEDIA = 'file';
const DEPRECATED_LINK_DESTINATION_ATTACHMENT = 'post';
Expand Down Expand Up @@ -281,7 +282,11 @@ const v6 = {
);
},
migrate( attributes ) {
return runV2Migration( attributes );
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

return attributes;
},
};
const v5 = {
Expand Down Expand Up @@ -367,7 +372,23 @@ const v5 = {
return ! linkTo || linkTo === 'attachment' || linkTo === 'media';
},
migrate( attributes ) {
return runV2Migration( attributes );
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

let linkTo = attributes.linkTo;

if ( ! attributes.linkTo ) {
linkTo = 'none';
} else if ( attributes.linkTo === 'attachment' ) {
linkTo = 'post';
} else if ( attributes.linkTo === 'media' ) {
linkTo = 'file';
}
return {
...attributes,
linkTo,
};
},
save( { attributes } ) {
const {
Expand Down Expand Up @@ -514,7 +535,17 @@ const v4 = {
return ids && ids.some( ( id ) => typeof id === 'string' );
},
migrate( attributes ) {
return runV2Migration( attributes );
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

return {
...attributes,
ids: map( attributes.ids, ( id ) => {
const parsedId = parseInt( id, 10 );
return Number.isInteger( parsedId ) ? parsedId : null;
} ),
};
},
save( { attributes } ) {
const {
Expand Down Expand Up @@ -710,7 +741,10 @@ const v3 = {
);
},
migrate( attributes ) {
return runV2Migration( attributes );
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}
return attributes;
},
};
const v2 = {
Expand Down Expand Up @@ -776,7 +810,18 @@ const v2 = {
);
},
migrate( attributes ) {
return runV2Migration( attributes );
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}
return {
...attributes,
ids: map( attributes.images, ( { id } ) => {
if ( ! id ) {
return null;
}
return parseInt( id, 10 );
} ),
};
},
supports: {
align: true,
Expand Down Expand Up @@ -929,7 +974,11 @@ const v1 = {
);
},
migrate( attributes ) {
return runV2Migration( attributes );
if ( isGalleryV2Enabled() ) {
return runV2Migration( attributes );
}

return attributes;
},
};

Expand Down
27 changes: 27 additions & 0 deletions packages/block-library/src/gallery/edit-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import { withNotices } from '@wordpress/components';

/**
* Internal dependencies
*/
import EditWithInnerBlocks from './edit';
import EditWithoutInnerBlocks from './v1/edit';
import { isGalleryV2Enabled } from './shared';

/*
* Using a wrapper around the logic to load the edit for v1 of Gallery block
* or the refactored version with InnerBlocks. This is to prevent conditional
* use of hooks lint errors if adding this logic to the top of the edit component.
*/
function GalleryEditWrapper( props ) {
if ( ! isGalleryV2Enabled() ) {
return <EditWithoutInnerBlocks { ...props } />;
}

return <EditWithInnerBlocks { ...props } />;
}

export default compose( [ withNotices ] )( GalleryEditWrapper );
2 changes: 2 additions & 0 deletions packages/block-library/src/gallery/gallery-styles.native.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "./v1/gallery-styles.native.scss";

.galleryAppender {
padding-top: $grid-unit-20;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/gallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { gallery as icon } from '@wordpress/icons';
* Internal dependencies
*/
import deprecated from './deprecated';
import edit from './edit';
import edit from './edit-wrapper';
import metadata from './block.json';
import save from './save';
import transforms from './transforms';
Expand Down
10 changes: 10 additions & 0 deletions packages/block-library/src/gallery/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ import {
__experimentalGetElementClassName,
} from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import saveWithoutInnerBlocks from './v1/save';
import { isGalleryV2Enabled } from './shared';

export default function saveWithInnerBlocks( { attributes } ) {
if ( ! isGalleryV2Enabled() ) {
return saveWithoutInnerBlocks( { attributes } );
}

const { caption, columns, imageCrop } = attributes;

const className = classnames( 'has-nested-images', {
Expand Down
Loading

0 comments on commit 4a243f3

Please sign in to comment.