From 73664e2034b375278d3f2ab3a2f992786b9bc8ca Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Thu, 4 Apr 2024 21:50:37 -0500 Subject: [PATCH 1/5] WIP: issue-629 From 64baf9ffe18fd5903732a679e1134ee2a6a499c3 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Sun, 7 Apr 2024 20:25:54 -0500 Subject: [PATCH 2/5] allow passing previewLookup function --- .../src/components/post-picker/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/block-editor-tools/src/components/post-picker/index.tsx b/packages/block-editor-tools/src/components/post-picker/index.tsx index 8f1ede0b..a1478f2f 100644 --- a/packages/block-editor-tools/src/components/post-picker/index.tsx +++ b/packages/block-editor-tools/src/components/post-picker/index.tsx @@ -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; @@ -62,6 +64,7 @@ const PostPicker = ({ onReset, onUpdate, params = {}, + previewLookup, previewRender, replaceText = __('Replace', 'alley-scripts'), resetText = __('Reset', 'alley-scripts'), @@ -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, From 03904236d3ddf9e9f8ea6d2578f2fa1252ac4a09 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Sun, 7 Apr 2024 20:28:49 -0500 Subject: [PATCH 3/5] add changeset --- .changeset/unlucky-papayas-poke.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/unlucky-papayas-poke.md diff --git a/.changeset/unlucky-papayas-poke.md b/.changeset/unlucky-papayas-poke.md new file mode 100644 index 00000000..7ea1e7c4 --- /dev/null +++ b/.changeset/unlucky-papayas-poke.md @@ -0,0 +1,5 @@ +--- +"@alleyinteractive/block-editor-tools": patch +--- + +Allow override of post preview lookup function in PostPicker. From 4b26551dc0e5d3121757d96726b4b11f29686695 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Sun, 7 Apr 2024 20:29:16 -0500 Subject: [PATCH 4/5] modify changeset entry --- .changeset/unlucky-papayas-poke.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/unlucky-papayas-poke.md b/.changeset/unlucky-papayas-poke.md index 7ea1e7c4..8623ffdf 100644 --- a/.changeset/unlucky-papayas-poke.md +++ b/.changeset/unlucky-papayas-poke.md @@ -2,4 +2,4 @@ "@alleyinteractive/block-editor-tools": patch --- -Allow override of post preview lookup function in PostPicker. +Feature: Allow override of post preview lookup function in PostPicker. From cadaa9a6f55ee1530814a1e4ca401f51e2e42b52 Mon Sep 17 00:00:00 2001 From: Greg Marshall Date: Sun, 7 Apr 2024 20:30:04 -0500 Subject: [PATCH 5/5] Ready for review