Skip to content

Commit

Permalink
fix(FEC-12957): Transcript Plugin - move download transcript inside t…
Browse files Browse the repository at this point in the history
…he plugin menu and "release" the download button.

Remove download and print icons
Add popover menu for download and print
Use close button from common
  • Loading branch information
SivanA-Kaltura authored and semarche-kaltura committed Mar 22, 2023
1 parent 1d250ec commit d2c93cc
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 176 deletions.
29 changes: 23 additions & 6 deletions cypress/e2e/transcript.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const clickTranscriptPluginButton = () => {
};

const clickClosePluginButton = () => {
cy.get('[data-testid="transcriptCloseButton"]').should('exist');
cy.get('[data-testid="transcriptCloseButton"]').click({force: true});
cy.get('[data-testid="transcriptCloseButton"] button').should('exist');
cy.get('[data-testid="transcriptCloseButton"] button').click({force: true});
};

const checkRequest = (reqBody: any, service: string, action: string) => {
Expand Down Expand Up @@ -197,19 +197,32 @@ describe('Transcript plugin', () => {
});
});

describe('popover menu', () => {
it('should not render when print and download are disabled', () => {
mockTranscript();
preparePage({printDisabled: true, downloadDisabled: true});
initiatePlay();
cy.get(`[data-testid="popover-anchor-container"]`).should('not.exist');
});
});

describe('print', () => {
it('should render print button', () => {
mockTranscript();
preparePage({printDisabled: false});
initiatePlay();
cy.get('[data-testid="transcript_printButton"]').should('exist');
cy.get(`[data-testid="popover-anchor-container"]`).should('exist');
cy.get(`[data-testid="popover-anchor-container"]`).click();
cy.get(`[data-testid="print-menu-item"]`).should('exist');
});

it('should not render print button', () => {
mockTranscript();
preparePage({printDisabled: true});
initiatePlay();
cy.get('[data-testid="transcript_printButton"]').should('not.exist');
cy.get(`[data-testid="popover-anchor-container"]`).should('exist');
cy.get(`[data-testid="popover-anchor-container"]`).click();
cy.get(`[data-testid="print-menu-item"]`).should('not.exist');
});
});

Expand All @@ -218,14 +231,18 @@ describe('Transcript plugin', () => {
mockTranscript();
preparePage({downloadDisabled: false});
initiatePlay();
cy.get('[data-testid="transcript_downloadButton"]').should('exist');
cy.get(`[data-testid="popover-anchor-container"]`).should('exist');
cy.get(`[data-testid="popover-anchor-container"]`).click();
cy.get(`[data-testid="download-menu-item"]`).should('exist');
});

it('should not render download button', () => {
mockTranscript();
preparePage({downloadDisabled: true});
initiatePlay();
cy.get('[data-testid="transcript_downloadButton"]').should('not.exist');
cy.get(`[data-testid="popover-anchor-container"]`).should('exist');
cy.get(`[data-testid="popover-anchor-container"]`).click();
cy.get(`[data-testid="download-menu-item"]`).should('not.exist');
});
});
});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"conventional-github-releaser": "3.1.3",
"cross-env": "^7.0.3",
"css-loader": "^6.7.1",
"kaltura-player-js": "https://github.com/kaltura/kaltura-player-js.git#master",
"kaltura-player-js": "https://github.com/kaltura/kaltura-player-js.git#v3.12.1",
"preact": "^10.4.1",
"prettier": "^2.6.2",
"sass": "^1.54.3",
Expand All @@ -31,7 +31,7 @@
"webpack-dev-server": "^4.9.0"
},
"peerDependencies": {
"kaltura-player-js": "https://github.com/kaltura/kaltura-player-js.git#master"
"kaltura-player-js": "https://github.com/kaltura/kaltura-player-js.git#v3.12.1"
},
"scripts": {
"clean": "rm -rf ./dist",
Expand Down Expand Up @@ -68,7 +68,7 @@
"html5 player"
],
"dependencies": {
"@playkit-js/common": "^1.1.2",
"@playkit-js/common": "1.1.6",
"@playkit-js/playkit-js-ui": "^0.73.0",
"@playkit-js/ui-managers": "^1.3.2",
"cypress": "^12.3.0",
Expand Down
11 changes: 0 additions & 11 deletions src/components/close-button/close-button.scss

This file was deleted.

29 changes: 0 additions & 29 deletions src/components/close-button/index.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/icons/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
export namespace icons {
export const PLUGIN_ICON =
'M23.1111111,19 C23.6020309,19 24,19.4477153 24,20 C24,20.5522847 23.6020309,21 23.1111111,21 L8.88888889,21 C8.39796911,21 8,20.5522847 8,20 C8,19.4477153 8.39796911,19 8.88888889,19 L23.1111111,19 Z M24.8695652,3 C26.5984566,3 28,4.24720677 28,5.78571429 L28,26.2142857 C28,27.7527932 26.5984566,29 24.8695652,29 L7.13043478,29 C5.40154339,29 4,27.7527932 4,26.2142857 L4,5.78571429 C4,4.24720677 5.40154339,3 7.13043478,3 L24.8695652,3 Z M26,17 L6,17 L6,26.0833333 C6,26.5895944 6.47127921,27 7.05263158,27 L24.9473684,27 C25.5287208,27 26,26.5895944 26,26.0833333 L26,17 Z M8.88888889,23 L23.1111111,23 C23.6020309,23 24,23.4477153 24,24 C24,24.5128358 23.6568532,24.9355072 23.2147743,24.9932723 L23.1111111,25 L8.88888889,25 C8.39796911,25 8,24.5522847 8,24 C8,23.4871642 8.34314684,23.0644928 8.78522567,23.0067277 L8.88888889,23 L23.1111111,23 L8.88888889,23 Z M24.9473684,5 L7.05263158,5 C6.47127921,5 6,5.41040565 6,5.91666667 L6,15 L26,15 L26,5.91666667 C26,5.41040565 25.5287208,5 24.9473684,5 Z';
export const CLOSE_ICON =
'M17.9113162,16 L24.6072325,9.30408374 C25.1313645,8.77995172 25.1287183,7.92687249 24.6009229,7.3990771 C24.0694478,6.86760201 23.220227,6.86845682 22.6959163,7.39276754 L16,14.0886838 L9.30408374,7.39276754 C8.77995172,6.86863552 7.92687249,6.8712817 7.3990771,7.3990771 C6.86760201,7.93055219 6.86845682,8.77977302 7.39276754,9.30408374 L14.0886838,16 L7.39276754,22.6959163 C6.86863552,23.2200483 6.8712817,24.0731275 7.3990771,24.6009229 C7.93055219,25.132398 8.77977302,25.1315432 9.30408374,24.6072325 L16,17.9113162 L22.6959163,24.6072325 C23.2200483,25.1313645 24.0731275,25.1287183 24.6009229,24.6009229 C25.132398,24.0694478 25.1315432,23.220227 24.6072325,22.6959163 L17.9113162,16 Z';
export const DOWNLOAD_ICON =
'M26,25 C26.5522847,25 27,25.4477153 27,26 C27,26.5522847 26.5522847,27 26,27 L26,27 L7,27 C6.44771525,27 6,26.5522847 6,26 C6,25.4477153 6.44771525,25 7,25 L7,25 Z M15.897,20.797 L15.817,20.73 L15.8163834,20.7298413 L8.34305882,13.7298413 C7.93997861,13.3522902 7.91928313,12.7194636 8.29683417,12.3163834 C8.67438521,11.9133032 9.30721188,11.8926077 9.71029209,12.2701587 L15.4996721,17.693 L15.5,6 C15.5,5.48716416 15.8860402,5.06449284 16.3833789,5.00672773 L16.5,5 C17.0522847,5 17.5,5.44771525 17.5,6 L17.4996721,17.694 L23.2951711,12.2699211 C23.6673663,11.9215418 24.2352038,11.9125649 24.6172049,12.230382 L24.7086128,12.3166371 C25.0860237,12.7198486 25.0651082,13.352668 24.6618968,13.7300789 L17.1833629,20.7300789 L17.1610165,20.7503813 L17.1610165,20.7503813 C17.1421868,20.7669999 17.1224361,20.7831339 17.102079,20.7985075 C17.0891381,20.8082894 17.0764369,20.8174134 17.0635772,20.826204 C17.0434306,20.8399634 17.0223437,20.8532674 17.0007451,20.8657864 C16.9872099,20.8736423 16.9734873,20.8811624 16.959633,20.8883367 L16.8877511,20.9220455 L16.8877511,20.9220455 C16.8756318,20.927087 16.8632234,20.9320132 16.8507409,20.9366814 C16.83028,20.9444208 16.8097352,20.9513578 16.7889039,20.9576336 C16.7705976,20.9630349 16.752126,20.968019 16.7335525,20.9724647 C16.6585039,20.9905214 16.5803589,21 16.5,21 C16.4170842,21 16.3365254,20.9899086 16.2594848,20.9708871 C16.2500284,20.9684434 16.2399293,20.9657886 16.2298654,20.9629733 C16.2028024,20.9554899 16.1769173,20.947049 16.1515197,20.9376057 C16.1370523,20.9321598 16.1223107,20.9262914 16.1076867,20.9200585 C16.0832011,20.9096448 16.0596143,20.8984375 16.036557,20.886357 C16.025923,20.8807972 16.0148138,20.8747205 16.0037984,20.8684173 C15.9792921,20.8543502 15.955966,20.8396537 15.9333153,20.8240474 L15.898,20.798 L15.897,20.797 Z M15.867,20.774 L15.888,20.79 L15.8735171,20.7794831 L15.8735171,20.7794831 L15.867,20.774 Z M15.817,20.73 L15.9035191,20.8027045 C15.8784859,20.7840722 15.8543541,20.7642966 15.831201,20.7434548 L15.817,20.73 Z';
export const PRINT_ICON =
'M21,3 C22.0543618,3 22.9181651,3.81587779 22.9945143,4.85073766 L23,5 L23,9 L26,9 C27.1045695,9 28,9.8954305 28,11 L28,21 C28,22.1045695 27.1045695,23 26,23 L23,23 L23,28 C23,29.1045695 22.1045695,30 21,30 L11,30 C9.8954305,30 9,29.1045695 9,28 L9,23 L6,23 C4.8954305,23 4,22.1045695 4,21 L4,11 C4,9.8954305 4.8954305,9 6,9 L9,9 L9,5 C9,3.9456382 9.81587779,3.08183488 10.8507377,3.00548574 L11,3 L21,3 Z M21,19 L11,19 L11,28 L21,28 L21,19 Z M26,11 L6,11 L6,21 L9,21 L9,19 C8.44771525,19 8,18.5522847 8,18 C8,17.4477153 8.44771525,17 9,17 L23,17 C23.5522847,17 24,17.4477153 24,18 C24,18.5522847 23.5522847,19 23,19 L23,21 L26,21 L26,11 Z M21,5 L11,5 L11,9 L21,9 L21,5 Z';
export const BigSize = 32;
export const MediumSize = 24;
export const SmallSize = 16;
Expand Down
2 changes: 2 additions & 0 deletions src/components/popover-menu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {PopoverMenu, PopoverMenuItemData} from './popover-menu';
export {PopoverMenu, PopoverMenuItemData};
73 changes: 73 additions & 0 deletions src/components/popover-menu/popover-menu.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@import './variables.scss';

.popover-anchor-container {
cursor: pointer;
margin-left: 8px;
border-radius: $roundness-1;

&:hover {
background-color: $tone-4-color;
}

&.active {
background-color: $tone-6-color;
}

.popover-anchor {
pointer-events: none;
}
}

.popover-container {
position: relative;

.popover-component {
background-color: $tone-7-color;
border-radius: $roundness-1;
display: block;
font-size: 15px;
margin-top: 6px;
position: absolute;
right: 0px;
z-index: 1;

&.hidden {
display: none;
}

&.bottom {
top: 100%;
margin-top: 6px;
}

&.left {
right: 0px;
}
}
}
.popover-menu-item {
align-items: center;
display: flex;
font-size: 15px;
line-height: 18px;
min-height: 30px;
padding: 9px 24px 9px 16px;
white-space: nowrap;
margin: 4px;

&:hover {
background-color: $tone-6-color;
border-radius: $roundness-1;
cursor: pointer;
}

&:focus {
outline: 1px solid #222;
}
}

.popover-menu {
padding-top: 6px;
padding-bottom: 6px;
}

107 changes: 107 additions & 0 deletions src/components/popover-menu/popover-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import {A11yWrapper} from '@playkit-js/common/dist/hoc/a11y-wrapper';
import {h, Component, VNode} from 'preact';

const {withEventManager} = KalturaPlayer.ui.Event;
const {ENTER, ESC, SPACE} = KalturaPlayer.ui.utils.KeyMap;

import * as styles from './popover-menu.scss';

interface PopoverMenuItemData {
testId: string;
label: string;
onClick: () => void;
}

interface PopoverMenuProps {
eventManager?: any;
children?: VNode;
items: Array<PopoverMenuItemData>;
}

interface PopoverMenuState {
isOpen: boolean;
}

@withEventManager
class PopoverMenu extends Component<PopoverMenuProps, PopoverMenuState> {
private _controlElementRef: HTMLDivElement | null = null;
private _popoverElementRef: HTMLDivElement | null = null;

eventManager: any;

constructor(props: PopoverMenuProps) {
super(props);
this.state = {isOpen: false};

this.props.eventManager?.listen(document, 'click', this.handleMouseEvent);
this.props.eventManager?.listen(document, 'keydown', this.handleKeyboardEvent);
}

private handleMouseEvent = (event: MouseEvent) => {
if (!this._controlElementRef?.contains(event.target as Node | null)) {
this.closePopover();
}
};

private handleKeyboardEvent = (event: KeyboardEvent) => {
if (this._controlElementRef?.contains(event.target as Node | null) && [ENTER, SPACE].includes(event.keyCode)) {
// use handler of control element
event.preventDefault();
return;
}
if (this._popoverElementRef?.contains(event.target as Node | null) && event.keyCode !== ESC) {
// use handler of popover element
return;
}
this.closePopover();
};

private closePopover() {
this.setState({isOpen: false});
}

private togglePopover = () => {
this.setState({isOpen: !this.state.isOpen});
};

render() {
const {children, items} = this.props;

return (
<div className={styles.popoverContainer}>
<A11yWrapper onClick={this.togglePopover}>
<div
data-testid="popover-anchor-container"
className={`${styles.popoverAnchorContainer} ${this.state.isOpen ? styles.active : ''}`}
ref={node => {
this._controlElementRef = node;
}}>
<div className={styles.popoverAnchor}>{children}</div>
</div>
</A11yWrapper>

<div className={styles.popoverComponent} role="menu" aria-expanded={this.state.isOpen}>
{this.state.isOpen
? items.map(({label, onClick, testId}) => {
return (
<A11yWrapper
onClick={() => {
this.closePopover();
onClick();
}}>
{
<div tabIndex={0} role="menuitem" className={styles.popoverMenuItem} data-testid={testId}>
{label}
</div>
}
</A11yWrapper>
);
})
: null}
</div>
</div>
);
}
}

export {PopoverMenu, PopoverMenuItemData};
2 changes: 2 additions & 0 deletions src/components/transcript-menu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {TranscriptMenu} from './transcript-menu';
export {TranscriptMenu};
56 changes: 56 additions & 0 deletions src/components/transcript-menu/transcript-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {Component, h} from 'preact';
import {PopoverMenu} from '../popover-menu';
import {PopoverMenuItemData} from '../popover-menu';

import {Button, ButtonType} from '@playkit-js/common/dist/components/button';

interface TranscriptMenuProps {
printDownloadAreaLabel?: string;
printTranscript?: string;
downloadTranscript?: string;
onDownload: () => void;
onPrint: () => void;
downloadDisabled?: boolean;
printDisabled?: boolean;
}

interface TranscriptMenuState {
isOpen: boolean;
items: Array<PopoverMenuItemData>;
}

class TranscriptMenu extends Component<TranscriptMenuProps, TranscriptMenuState> {
constructor(props: TranscriptMenuProps) {
super();

const {downloadDisabled, onDownload, printDisabled, onPrint, printDownloadAreaLabel, printTranscript, downloadTranscript} = props;
const items = [];
if (!downloadDisabled) {
items.push({
testId: 'download-menu-item',
label: 'Download transcript',
onClick: onDownload
});
}

if (!printDisabled) {
items.push({
testId: 'print-menu-item',
label: 'Print transcript',
onClick: onPrint
});
}

this.state = {isOpen: false, items};
}

render() {
return this.state.items.length ? (
<PopoverMenu items={this.state.items}>
<Button type={ButtonType.borderless} icon={'more'}></Button>
</PopoverMenu>
) : null;
}
}

export {TranscriptMenu};
Loading

0 comments on commit d2c93cc

Please sign in to comment.