Skip to content

Commit

Permalink
Merge pull request #630 from alleyinteractive/feature/issue-629/allow…
Browse files Browse the repository at this point in the history
…-custom-post-lookup-function

Issue-629: PostPicker Allow developer to specify post lookup function
  • Loading branch information
mogmarsh authored Apr 9, 2024
2 parents 225d7ba + 621037b commit 45a95b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-papayas-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alleyinteractive/block-editor-tools": patch
---

Feature: Allow override of post preview lookup function in PostPicker.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface PostPickerProps {
onUpdate: (id: number) => void;
params?: object;
// eslint-disable-next-line camelcase
previewLookup?: (id: number) => WP_REST_API_Post;
// eslint-disable-next-line camelcase
previewRender?: (post: object | WP_REST_API_Post) => JSX.Element;
replaceText?: string;
resetText?: string;
Expand Down Expand Up @@ -62,6 +64,7 @@ const PostPicker = ({
onReset,
onUpdate,
params = {},
previewLookup,
previewRender,
replaceText = __('Replace', 'alley-scripts'),
resetText = __('Reset', 'alley-scripts'),
Expand All @@ -83,8 +86,9 @@ const PostPicker = ({
},
);

// eslint-disable-next-line camelcase
const post = usePostById(value, getPostType) as any as WP_REST_API_Post;
const post = previewLookup
? previewLookup(value)
: usePostById(value, getPostType) as any as WP_REST_API_Post; // eslint-disable-line react-hooks/rules-of-hooks, camelcase, max-len

const {
featured_media: featuredMediaId,
Expand Down

0 comments on commit 45a95b5

Please # to comment.