From f1791c5dbaf771d093c51f4f6ffc61f490da4380 Mon Sep 17 00:00:00 2001 From: Dan Tovbein Date: Fri, 3 May 2024 12:17:45 -0300 Subject: [PATCH] Fix Analytics Tracking Sidebar component - It should be merged before we move to WP6.5 --- .../Sidebar/AnalyticsTrackingSidebar.js | 71 +++++++++---------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/assets/src/block-editor/Sidebar/AnalyticsTrackingSidebar.js b/assets/src/block-editor/Sidebar/AnalyticsTrackingSidebar.js index 6f65abf7ec..e19ff29345 100644 --- a/assets/src/block-editor/Sidebar/AnalyticsTrackingSidebar.js +++ b/assets/src/block-editor/Sidebar/AnalyticsTrackingSidebar.js @@ -1,3 +1,4 @@ +import {useEffect} from '@wordpress/element'; import {PluginDocumentSettingPanel} from '@wordpress/edit-post'; import {dispatch, useSelect} from '@wordpress/data'; import {SelectSidebarField} from '../SidebarFields/SelectSidebarField'; @@ -6,54 +7,46 @@ import {getSidebarFunctions} from './getSidebarFunctions'; const {__} = wp.i18n; -dispatch('core').addEntities([{ - baseURL: '/planet4/v1/analytics-values', - kind: 'planet4/v1', - name: 'analytics-values', - label: 'Analytics and tracking values', -}]); - -const GLOBAL_PROJECT = 'p4_campaign_name'; -const LOCAL_PROJECT = 'p4_local_project'; -const BASKET = 'p4_basket_name'; -const DEPARTMENT = 'p4_department'; - export const AnalyticsTrackingSidebar = { getId: () => 'planet4-analytics-sidebar', render: () => { const {getParams} = getSidebarFunctions(); const postId = wp.data.select('core/editor').getCurrentPostId(); const options = useSelect(select => { - return select('core').getEntityRecords('planet4/v1', 'analytics-values', {id: postId}); + return select('core').getEntityRecord('planet4/v1', 'analytics-values'); }); - const globalOptions = options ? options[0].global_projects : []; - const localOptions = options ? options[0].local_projects : []; - const basketOptions = options ? options[0].baskets : []; + useEffect(() => { + dispatch('core').addEntities([{ + baseURL: '/planet4/v1/analytics-values', + baseURLParams: {post_id: postId}, + kind: 'planet4/v1', + name: 'analytics-values', + label: 'Analytics and tracking values', + }]); + }, [postId]); - return ( - <> - - - - - - - + return options && ( + + + + + + ); }, };