Skip to content

Commit c6cb55f

Browse files
authored
Custom Views: Remove the experiment (#72123)
1 parent 1631ef0 commit c6cb55f

File tree

12 files changed

+27
-591
lines changed

12 files changed

+27
-591
lines changed

lib/experimental/data-views.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/experimental/editor-settings.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ function gutenberg_enable_experiments() {
1313
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-sync-collaboration', $gutenberg_experiments ) ) {
1414
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableSync = true', 'before' );
1515
}
16-
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-custom-dataviews', $gutenberg_experiments ) ) {
17-
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalCustomViews = true', 'before' );
18-
}
1916
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-color-randomizer', $gutenberg_experiments ) ) {
2017
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableColorRandomizer = true', 'before' );
2118
}

lib/experiments-page.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,6 @@ function gutenberg_initialize_experiments_settings() {
139139
)
140140
);
141141

142-
add_settings_field(
143-
'gutenberg-custom-dataviews',
144-
__( 'Data Views: add Custom Views', 'gutenberg' ),
145-
'gutenberg_display_experiment_field',
146-
'gutenberg-experiments',
147-
'gutenberg_experiments_section',
148-
array(
149-
'label' => __( 'Enables the ability to add, edit, and save custom views when in the Site Editor.', 'gutenberg' ),
150-
'id' => 'gutenberg-custom-dataviews',
151-
)
152-
);
153-
154142
add_settings_field(
155143
'gutenberg-new-posts-dashboard',
156144
__( 'Data Views: enable for Posts', 'gutenberg' ),

lib/load.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ function gutenberg_is_experiment_enabled( $name ) {
165165
require __DIR__ . '/block-supports/aria-label.php';
166166
require __DIR__ . '/block-supports/block-visibility.php';
167167

168-
// Data views.
169-
require_once __DIR__ . '/experimental/data-views.php';
170-
171168
// Client-side media processing.
172169
if ( gutenberg_is_experiment_enabled( 'gutenberg-media-processing' ) ) {
173170
require_once __DIR__ . '/experimental/media/load.php';

packages/edit-site/src/components/post-list/index.js

Lines changed: 18 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@wordpress/core-data';
99
import { useState, useMemo, useCallback, useEffect } from '@wordpress/element';
1010
import { privateApis as routerPrivateApis } from '@wordpress/router';
11-
import { useSelect, useDispatch } from '@wordpress/data';
11+
import { useSelect } from '@wordpress/data';
1212
import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
1313
import { privateApis as editorPrivateApis } from '@wordpress/editor';
1414
import { __ } from '@wordpress/i18n';
@@ -43,68 +43,28 @@ const getDefaultView = ( defaultViews, activeView ) => {
4343
return defaultViews.find( ( { slug } ) => slug === activeView )?.view;
4444
};
4545

46-
const getCustomView = ( editedEntityRecord ) => {
47-
if ( ! editedEntityRecord?.content ) {
48-
return undefined;
49-
}
50-
51-
const content = JSON.parse( editedEntityRecord.content );
52-
if ( ! content ) {
53-
return undefined;
54-
}
55-
56-
return {
57-
...content,
58-
...defaultLayouts[ content.type ],
59-
};
60-
};
61-
6246
/**
63-
* This function abstracts working with default & custom views by
47+
* This function abstracts working with default views by
6448
* providing a [ state, setState ] tuple based on the URL parameters.
6549
*
6650
* Consumers use the provided tuple to work with state
67-
* and don't have to deal with the specifics of default & custom views.
51+
* and don't have to deal with the specifics.
6852
*
6953
* @param {string} postType Post type to retrieve default views for.
7054
* @return {Array} The [ state, setState ] tuple.
7155
*/
7256
function useView( postType ) {
7357
const {
7458
path,
75-
query: { activeView = 'all', isCustom = 'false', layout },
59+
query: { activeView = 'all', layout },
7660
} = useLocation();
7761
const history = useHistory();
78-
7962
const defaultViews = useDefaultViews( { postType } );
80-
const { editEntityRecord } = useDispatch( coreStore );
81-
const editedEntityRecord = useSelect(
82-
( select ) => {
83-
if ( isCustom !== 'true' ) {
84-
return undefined;
85-
}
8663

87-
const { getEditedEntityRecord } = select( coreStore );
88-
return getEditedEntityRecord(
89-
'postType',
90-
'wp_dataviews',
91-
Number( activeView )
92-
);
93-
},
94-
[ activeView, isCustom ]
95-
);
9664
const [ view, setView ] = useState( () => {
97-
let initialView;
98-
if ( isCustom === 'true' ) {
99-
initialView = getCustomView( editedEntityRecord ) ?? {
100-
type: layout ?? LAYOUT_LIST,
101-
};
102-
} else {
103-
initialView = getDefaultView( defaultViews, activeView ) ?? {
104-
type: layout ?? LAYOUT_LIST,
105-
};
106-
}
107-
65+
const initialView = getDefaultView( defaultViews, activeView ) ?? {
66+
type: layout ?? LAYOUT_LIST,
67+
};
10868
const type = layout ?? initialView.type;
10969
return {
11070
...initialView,
@@ -115,18 +75,6 @@ function useView( postType ) {
11575

11676
const setViewWithUrlUpdate = useEvent( ( newView ) => {
11777
setView( newView );
118-
119-
if ( isCustom === 'true' && editedEntityRecord?.id ) {
120-
editEntityRecord(
121-
'postType',
122-
'wp_dataviews',
123-
editedEntityRecord?.id,
124-
{
125-
content: JSON.stringify( newView ),
126-
}
127-
);
128-
}
129-
13078
const currentUrlLayout = layout ?? LAYOUT_LIST;
13179
if ( newView.type !== currentUrlLayout ) {
13280
history.navigate(
@@ -157,15 +105,9 @@ function useView( postType ) {
157105
onUrlLayoutChange();
158106
}, [ onUrlLayoutChange, layout ] );
159107

160-
// When activeView or isCustom URL parameters change, reset the view.
108+
// When activeView URL parameters change, reset the view.
161109
const onUrlActiveViewChange = useEvent( () => {
162-
let newView;
163-
if ( isCustom === 'true' ) {
164-
newView = getCustomView( editedEntityRecord );
165-
} else {
166-
newView = getDefaultView( defaultViews, activeView );
167-
}
168-
110+
const newView = getDefaultView( defaultViews, activeView );
169111
if ( newView ) {
170112
const type = layout ?? newView.type;
171113
setView( {
@@ -177,13 +119,7 @@ function useView( postType ) {
177119
} );
178120
useEffect( () => {
179121
onUrlActiveViewChange();
180-
}, [
181-
onUrlActiveViewChange,
182-
activeView,
183-
isCustom,
184-
defaultViews,
185-
editedEntityRecord,
186-
] );
122+
}, [ onUrlActiveViewChange, activeView ] );
187123

188124
return [ view, setViewWithUrlUpdate ];
189125
}
@@ -202,25 +138,18 @@ export default function PostList( { postType } ) {
202138
const [ view, setView ] = useView( postType );
203139
const history = useHistory();
204140
const location = useLocation();
205-
const {
206-
postId,
207-
quickEdit = false,
208-
isCustom,
209-
activeView = 'all',
210-
} = location.query;
141+
const { postId, quickEdit = false, activeView = 'all' } = location.query;
211142
const [ selection, setSelection ] = useState( postId?.split( ',' ) ?? [] );
212143
const onChangeSelection = useCallback(
213144
( items ) => {
214145
setSelection( items );
215-
if ( ( location.query.isCustom ?? 'false' ) === 'false' ) {
216-
history.navigate(
217-
addQueryArgs( location.path, {
218-
postId: items.join( ',' ),
219-
} )
220-
);
221-
}
146+
history.navigate(
147+
addQueryArgs( location.path, {
148+
postId: items.join( ',' ),
149+
} )
150+
);
222151
},
223-
[ location.path, location.query.isCustom, history ]
152+
[ location.path, history ]
224153
);
225154

226155
const { isLoading: isLoadingFields, fields: fields } = usePostFields( {
@@ -368,7 +297,7 @@ export default function PostList( { postType } ) {
368297
}
369298
>
370299
<DataViews
371-
key={ activeView + isCustom }
300+
key={ activeView }
372301
paginationInfo={ paginationInfo }
373302
fields={ fields }
374303
actions={ actions }

packages/edit-site/src/components/posts-app-routes/posts.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export const postsRoute = {
3636
),
3737
content: <PostList postType="post" />,
3838
preview( { query } ) {
39-
const isListView =
40-
( query.layout === 'list' || ! query.layout ) &&
41-
query.isCustom !== 'true';
39+
const isListView = query.layout === 'list' || ! query.layout;
4240
return isListView ? <Editor isPostsList /> : undefined;
4341
},
4442
mobile: <MobilePostsView />,
@@ -52,9 +50,7 @@ export const postsRoute = {
5250
},
5351
widths: {
5452
content( { query } ) {
55-
const isListView =
56-
( query.layout === 'list' || ! query.layout ) &&
57-
query.isCustom !== 'true';
53+
const isListView = query.layout === 'list' || ! query.layout;
5854
return isListView ? 380 : undefined;
5955
},
6056
edit( { query } ) {

0 commit comments

Comments
 (0)