react-code-dataset / wp-calypso /apps /wpcom-block-editor /src /wpcom /features /tracking /wpcom-inserter-tab-panel-selected.js
react-code-dataset / wp-calypso /apps /wpcom-block-editor /src /wpcom /features /tracking /wpcom-inserter-tab-panel-selected.js
Download wp-calypso/apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-inserter-tab-panel-selected.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-inserter-tab-panel-selected.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-inserter-tab-panel-selected.js
-
curl -L -o wpcom-inserter-tab-panel-selected.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-inserter-tab-panel-selected.js
1.12 kB
| import tracksRecordEvent from './track-record-event'; | |
| // Curiously, the numeric ids of the tabs increment every time you close and | |
| // reopen the inserter, so we use this regex to ignore that and grab the tab | |
| // slug | |
| const tabPanelRegex = /tab-panel-\d*-(\w*)/; | |
| const gutenbergTabPanelName = ( tabPanel ) => | |
| ( tabPanel.id.match( tabPanelRegex ) || [ null, null ] )[ 1 ]; | |
| /** | |
| * Return the event definition object to track `wpcom_block_picker_tab_panel_selected`. | |
| * @returns {import('./types').DelegateEventHandler} event object definition. | |
| */ | |
| export default () => ( { | |
| id: 'wpcom-inserter-tab-panel-selected', | |
| selector: `.block-editor-inserter__tabs .components-tab-panel__tabs button:not(.is-active)`, | |
| type: 'click', | |
| // Using capture event listener to make sure the tab is not set to active | |
| // before this event listener runs. This way we can prevent the listener | |
| // from triggering when the tab is already active. | |
| capture: true, | |
| handler: ( event ) => { | |
| const tabName = gutenbergTabPanelName( event.target ); | |
| tracksRecordEvent( 'wpcom_block_picker_tab_panel_selected', { | |
| tab: tabName, | |
| } ); | |
| }, | |
| } ); | |