88} from '@wordpress/core-data' ;
99import { useState , useMemo , useCallback , useEffect } from '@wordpress/element' ;
1010import { privateApis as routerPrivateApis } from '@wordpress/router' ;
11- import { useSelect , useDispatch } from '@wordpress/data' ;
11+ import { useSelect } from '@wordpress/data' ;
1212import { DataViews , filterSortAndPaginate } from '@wordpress/dataviews' ;
1313import { privateApis as editorPrivateApis } from '@wordpress/editor' ;
1414import { __ } 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 */
7256function 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 }
0 commit comments