Skip to content

Commit d8e0b13

Browse files
oandregalyouknowriadntsekouras
authored
Move usePostFields to wordpress/editor package (#67024)
Co-authored-by: oandregal <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: ntsekouras <[email protected]>
1 parent a750125 commit d8e0b13

File tree

9 files changed

+74
-58
lines changed

9 files changed

+74
-58
lines changed

packages/dataviews/src/dataforms-layouts/panel/style.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@
4444
.dataforms-layouts-panel__dropdown-header {
4545
margin-bottom: $grid-unit-20;
4646
}
47+
48+
.components-popover.components-dropdown__content.dataforms-layouts-panel__field-dropdown {
49+
z-index: z-index(".components-popover.components-dropdown__content.dataforms-layouts-panel__field-dropdown");
50+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import { privateApis as editorPrivateApis } from '@wordpress/editor';
1818
* Internal dependencies
1919
*/
2020
import Page from '../page';
21-
import usePostFields from '../post-fields';
2221
import { unlock } from '../../lock-unlock';
2322

24-
const { PostCardPanel } = unlock( editorPrivateApis );
23+
const { PostCardPanel, usePostFields } = unlock( editorPrivateApis );
2524

2625
const fieldsWithBulkEditSupport = [
2726
'title',

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

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

packages/edit-site/src/components/post-fields/style.scss

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ import AddNewPostModal from '../add-new-post';
3232
import { unlock } from '../../lock-unlock';
3333
import { useEditPostAction } from '../dataviews-actions';
3434
import { usePrevious } from '@wordpress/compose';
35-
import usePostFields from '../post-fields';
3635

37-
const { usePostActions } = unlock( editorPrivateApis );
36+
const { usePostActions, usePostFields } = unlock( editorPrivateApis );
3837
const { useLocation, useHistory } = unlock( routerPrivateApis );
3938
const { useEntityRecordsWithPermissions } = unlock( coreDataPrivateApis );
4039
const EMPTY_ARRAY = [];

packages/edit-site/src/style.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
@import "./components/editor-canvas-container/style.scss";
3131
@import "./components/post-edit/style.scss";
3232
@import "./components/post-list/style.scss";
33-
@import "./components/post-fields/style.scss";
3433
@import "./components/resizable-frame/style.scss";
3534
@import "./hooks/push-changes-to-global-styles/style.scss";
3635
@import "./components/global-styles/font-library-modal/style.scss";
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { useMemo } from '@wordpress/element';
5+
import { useEntityRecords } from '@wordpress/core-data';
6+
import type { Field } from '@wordpress/dataviews';
7+
import {
8+
featuredImageField,
9+
slugField,
10+
parentField,
11+
passwordField,
12+
statusField,
13+
commentStatusField,
14+
titleField,
15+
dateField,
16+
authorField,
17+
} from '@wordpress/fields';
18+
import type { BasePostWithEmbeddedAuthor } from '@wordpress/fields';
19+
20+
interface UsePostFieldsReturn {
21+
isLoading: boolean;
22+
fields: Field< BasePostWithEmbeddedAuthor >[];
23+
}
24+
25+
interface Author {
26+
id: number;
27+
name: string;
28+
}
29+
30+
function usePostFields(): UsePostFieldsReturn {
31+
const { records: authors, isResolving: isLoadingAuthors } =
32+
useEntityRecords< Author >( 'root', 'user', { per_page: -1 } );
33+
34+
const fields = useMemo(
35+
() =>
36+
[
37+
featuredImageField,
38+
titleField,
39+
{
40+
...authorField,
41+
elements: authors?.map( ( { id, name } ) => ( {
42+
value: id,
43+
label: name,
44+
} ) ),
45+
},
46+
statusField,
47+
dateField,
48+
slugField,
49+
parentField,
50+
commentStatusField,
51+
passwordField,
52+
] as Field< BasePostWithEmbeddedAuthor >[],
53+
[ authors ]
54+
);
55+
56+
return {
57+
isLoading: isLoadingAuthors,
58+
fields,
59+
};
60+
}
61+
62+
/**
63+
* Hook to get the fields for a post (BasePost or BasePostWithEmbeddedAuthor).
64+
*/
65+
export default usePostFields;

packages/editor/src/private-apis.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import PluginPostExcerpt from './components/post-excerpt/plugin';
1616
import PostCardPanel from './components/post-card-panel';
1717
import PreferencesModal from './components/preferences-modal';
1818
import { usePostActions } from './components/post-actions/actions';
19+
import usePostFields from './components/post-fields';
1920
import ToolsMoreMenuGroup from './components/more-menu/tools-more-menu-group';
2021
import ViewMoreMenuGroup from './components/more-menu/view-more-menu-group';
2122
import ResizableEditor from './components/resizable-editor';
@@ -40,6 +41,7 @@ lock( privateApis, {
4041
PostCardPanel,
4142
PreferencesModal,
4243
usePostActions,
44+
usePostFields,
4345
ToolsMoreMenuGroup,
4446
ViewMoreMenuGroup,
4547
ResizableEditor,

packages/fields/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './fields';
22
export * from './actions';
3+
export type * from './types';

0 commit comments

Comments
 (0)