Skip to content

Commit

Permalink
feat(FEC-10785): add support to remove ui element (#460)
Browse files Browse the repository at this point in the history
Until now it was possible to add new component or to add and replace existing components.
There was no official way to remove an existing ui component.

Flow - KPUIComponent was separated to KPUIAddComponent and KPUIRemoveComponent
UIWrapper was added a new api - removeComponent(component: KPUIRemoveComponent): Function
getUIComponents handling was changed accordingly
  • Loading branch information
RoyBregman authored Jun 27, 2021
1 parent f0954de commit fd2172c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 9 additions & 1 deletion flow-typed/types/ui-component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// @flow
declare type KPUIComponent = KPUIComponentOptions & {
declare type KPUIAddComponent = KPUIComponentOptions & {
get: Function,
props?: {}
};

declare type KPUIRemoveComponent = {
removeComponent: string,
presets: Array<string>,
area: string
};

declare type KPUIComponent = KPUIAddComponent | KPUIRemoveComponent;
23 changes: 20 additions & 3 deletions src/common/ui-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import {UIManager} from '@playkit-js/playkit-js-ui';
import {UIManager, Components} from '@playkit-js/playkit-js-ui';
import {Env, getLogger, Utils} from '@playkit-js/playkit-js';
import {KalturaPlayer} from '../kaltura-player';

Expand Down Expand Up @@ -55,13 +55,30 @@ class UIWrapper {
/**
* Add a component dynamically
*
* @param {KPUIComponent} component - The component to add
* @param {KPUIAddComponent} component - The component to add
* @returns {Function} - Removal function
*/
addComponent(component: KPUIComponent): Function {
addComponent(component: KPUIAddComponent): Function {
return this._uiManager.addComponent(component);
}

/**
* Remove a component dynamically
*
* @param {KPUIRemoveComponent} component - The component to remove
* @returns {Function} - Undo removal function
*/
removeComponent(component: KPUIRemoveComponent): Function {
let replaceComponent: KPUIAddComponent = {
label: `Remove_${component.removeComponent}`,
get: Components.Remove,
presets: component.presets,
area: component.area || (component: any).container, // supporting also "container" prop for backward compatibility
replaceComponent: component.removeComponent
};
return this._uiManager.addComponent(replaceComponent);
}

/**
* @param {string} name - the manager name
* @param {Object} manager - the manager object
Expand Down

0 comments on commit fd2172c

Please sign in to comment.