Skip to content

Commit

Permalink
feat(FEC-11600): Related grid analytics (#34)
Browse files Browse the repository at this point in the history
Fire events on toggle button click and on manual entry selection
Expose event types for kava

Related PR: kaltura/playkit-js-kava#133

Resolves FEC-11600
  • Loading branch information
SivanA-Kaltura authored Jan 15, 2023
1 parent cb75db7 commit dfcc2df
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 385 deletions.
723 changes: 363 additions & 360 deletions docs/api.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/components/next/next.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {PrevNext} = KalturaPlayer.ui.components;
const {withEventManager} = KalturaPlayer.ui.Event;

import {RelatedEvent} from 'event';
import {RelatedInternalEvent} from 'event';
import {useState, useEffect} from 'preact/hooks';
import {RelatedManager} from 'related-manager';
import {Sources} from 'types';
Expand All @@ -28,7 +28,7 @@ const Next = withEventManager(({relatedManager, showPreview, onClick, eventManag
const [entries, setEntries] = useState<Sources[]>([]);

useEffect(() => {
eventManager.listen(eventContext, RelatedEvent.RELATED_ENTRIES_CHANGED, ({payload}: {payload: Sources[]}) => {
eventManager.listen(eventContext, RelatedInternalEvent.RELATED_ENTRIES_CHANGED, ({payload}: {payload: Sources[]}) => {
setEntries(payload);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {withText} = KalturaPlayer.ui.preacti18n;
const {withEventManager} = KalturaPlayer.ui.Event;

import {RelatedEvent} from 'event';
import {RelatedInternalEvent} from 'event';
import {useEffect, useState} from 'preact/hooks';

const {Tooltip} = KalturaPlayer.ui.components;
Expand Down Expand Up @@ -57,7 +57,7 @@ const PrePlaybackPlayOverlayWrapper = withEventManager(
const [isAutoContinueCancelled, setIsAutoContinueCancelled] = useState(relatedManager.isAutoContinueCancelled);

useEffect(() => {
eventManager.listen(eventContext, RelatedEvent.AUTO_CONTINUE_CANCELLED_CHANGED, ({payload}: {payload: boolean}) => {
eventManager.listen(eventContext, RelatedInternalEvent.AUTO_CONTINUE_CANCELLED_CHANGED, ({payload}: {payload: boolean}) => {
setIsAutoContinueCancelled(payload);
});
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {CloseButton, RelatedContext, Thumbnail, Countdown, MultilineText} from '
import {RelatedManager} from 'related-manager';

import * as styles from './related-countdown-preview.scss';
import {RelatedEvent} from 'event';
import {RelatedInternalEvent} from 'event';

const {connect} = KalturaPlayer.ui.redux;
const {withText} = KalturaPlayer.ui.preacti18n;
Expand Down Expand Up @@ -56,10 +56,10 @@ const RelatedCountdownPreview = withText({
const showPreview = isPlaybackEnded && relatedManager.countdownTime > -1 && isListVisible && !isAutoContinueCancelled;

useEffect(() => {
eventManager.listen(eventContext, RelatedEvent.LIST_VISIBILITY_CHANGED, ({payload}: {payload: boolean}) => {
eventManager.listen(eventContext, RelatedInternalEvent.LIST_VISIBILITY_CHANGED, ({payload}: {payload: boolean}) => {
setIsListVisible(payload);
});
eventManager.listen(eventContext, RelatedEvent.AUTO_CONTINUE_CANCELLED_CHANGED, ({payload}: {payload: boolean}) => {
eventManager.listen(eventContext, RelatedInternalEvent.AUTO_CONTINUE_CANCELLED_CHANGED, ({payload}: {payload: boolean}) => {
setIsAutoContinueCancelled(payload);
});
}, []);
Expand Down
4 changes: 2 additions & 2 deletions src/components/related-overlay/related-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {RelatedGrid} from '../related-grid/related-grid';
import {getNextEntry} from '../related-grid/grid-utils';

import * as styles from './related-overlay.scss';
import {RelatedEvent} from 'event';
import {RelatedInternalEvent} from 'event';

const {withEventManager} = KalturaPlayer.ui.Event;
const {connect} = KalturaPlayer.ui.redux;
Expand Down Expand Up @@ -51,7 +51,7 @@ const RelatedOverlay = withEventManager(
const [isAutoContinueCancelled, setIsAutoContinueCancelled] = useState(relatedManager.isAutoContinueCancelled);

useEffect(() => {
eventManager.listen(eventContext, RelatedEvent.AUTO_CONTINUE_CANCELLED_CHANGED, ({payload}: {payload: boolean}) => {
eventManager.listen(eventContext, RelatedInternalEvent.AUTO_CONTINUE_CANCELLED_CHANGED, ({payload}: {payload: boolean}) => {
setIsAutoContinueCancelled(payload);
});
}, []);
Expand Down
4 changes: 3 additions & 1 deletion src/event/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export {RelatedEvent} from './related-event';
import {RelatedEvent} from './related-event';
import {RelatedInternalEvent} from './related-internal-event';
export {RelatedInternalEvent, RelatedEvent};
5 changes: 5 additions & 0 deletions src/event/related-event.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
export namespace RelatedEvent {
const RELATED_CLICKED: string;
const RELATED_SELECTED: string;
}
15 changes: 15 additions & 0 deletions src/event/related-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Related plugin event types.
*/
const RelatedEvent = {
/**
* Fired when the user selects an entry from the list or the grid.
*/
RELATED_SELECTED: 'related_selected',
/**
* Fired when the user clicks the button to show the related list.
*/
RELATED_CLICKED: 'related_clicked'
};

export {RelatedEvent};
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* Internal related plugin events enum.
*
* @enum {string}
* Internal related plugin event types.
*/
enum RelatedEvent {
enum RelatedInternalEvent {
/**
* Fired every time the list of related entries is changed.
*/
Expand All @@ -22,4 +20,4 @@ enum RelatedEvent {
LIST_VISIBILITY_CHANGED = 'list_visibility_changed'
}

export {RelatedEvent};
export {RelatedInternalEvent};
18 changes: 11 additions & 7 deletions src/related-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {RelatedEvent} from 'event';
import {RelatedInternalEvent, RelatedEvent} from 'event';
import {EntryService, ImageService} from 'services';
import {RelatedConfig, Sources} from 'types';
/**
Expand Down Expand Up @@ -145,7 +145,7 @@ class RelatedManager extends KalturaPlayer.core.FakeEventTarget {
}

/**
* Play a selected entry.
* Play an entry by index.
*
* @private
* @param {number} index index of the selected entry to play
Expand Down Expand Up @@ -244,14 +244,15 @@ class RelatedManager extends KalturaPlayer.core.FakeEventTarget {
}

/**
* Wrapper for playByIndex.
* Play the selected entry.
*
* @param {number} internalIndex index of the entry to be played
* @memberof RelatedManager
*/
playSelected(internalIndex: number) {
this.logger.info('going to play selected entry');
this.playByIndex(internalIndex);
this.player.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedEvent.RELATED_SELECTED));
}

/**
Expand Down Expand Up @@ -305,7 +306,7 @@ class RelatedManager extends KalturaPlayer.core.FakeEventTarget {
*/
set isAutoContinueCancelled(isAutoContinueCancelled: boolean) {
this._isAutoContinueCancelled = isAutoContinueCancelled;
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedEvent.AUTO_CONTINUE_CANCELLED_CHANGED, isAutoContinueCancelled));
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedInternalEvent.AUTO_CONTINUE_CANCELLED_CHANGED, isAutoContinueCancelled));
}

/**
Expand Down Expand Up @@ -348,7 +349,7 @@ class RelatedManager extends KalturaPlayer.core.FakeEventTarget {
set entries(entries: Sources[]) {
this.logger.info(`related entries changed`);
this._entries = entries;
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedEvent.RELATED_ENTRIES_CHANGED, this._entries));
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedInternalEvent.RELATED_ENTRIES_CHANGED, this._entries));
}

/**
Expand Down Expand Up @@ -389,7 +390,7 @@ class RelatedManager extends KalturaPlayer.core.FakeEventTarget {
*/
set isGridVisible(isGridVisible: boolean) {
this._isGridVisible = isGridVisible;
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedEvent.GRID_VISIBILITY_CHANGED, this._isGridVisible));
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedInternalEvent.GRID_VISIBILITY_CHANGED, this._isGridVisible));
}

/**
Expand All @@ -409,7 +410,10 @@ class RelatedManager extends KalturaPlayer.core.FakeEventTarget {
*/
set isListVisible(isListVisible: boolean) {
this._isListVisible = isListVisible;
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedEvent.LIST_VISIBILITY_CHANGED, this._isListVisible));
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedInternalEvent.LIST_VISIBILITY_CHANGED, this._isListVisible));
if (this._isListVisible) {
this.player.dispatchEvent(new KalturaPlayer.core.FakeEvent(RelatedEvent.RELATED_CLICKED));
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/related.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Next, PrePlaybackPlayOverlayWrapper, RelatedList, RelatedOverlay, ListTo
import {UpperBarManager, SidePanelsManager} from '@playkit-js/ui-managers';

import {Icon, RelatedConfig} from 'types';
import {RelatedEvent} from 'event';
import {RelatedInternalEvent} from 'event';

const PRESETS = ['Playback', 'Live'];

Expand Down Expand Up @@ -213,11 +213,11 @@ class Related extends KalturaPlayer.core.BasePlugin {
expandMode: this.config.expandMode
}) as number;

this.relatedManager.listen(RelatedEvent.GRID_VISIBILITY_CHANGED, () => {
this.relatedManager.listen(RelatedInternalEvent.GRID_VISIBILITY_CHANGED, () => {
this.upperBarManager?.update(this.iconId);
});

this.relatedManager.listen(RelatedEvent.LIST_VISIBILITY_CHANGED, () => {
this.relatedManager.listen(RelatedInternalEvent.LIST_VISIBILITY_CHANGED, () => {
this.upperBarManager?.update(this.iconId);
this.sidePanelsManager[this.relatedManager.isListVisible ? 'activateItem' : 'deactivateItem'](this.panelId);
});
Expand Down
1 change: 1 addition & 0 deletions types/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {RelatedEvent} from '../src/event/related-event';

0 comments on commit dfcc2df

Please sign in to comment.