| 1 |
import Collapse from '../../components/collapse'; |
| 2 |
import ContentType from '../../models/content-type'; |
| 3 |
import FavoritesActions from '../../components/favorites-actions'; |
| 4 |
import Kit from '../../models/kit'; |
| 5 |
import OverviewTaxonomyBadge from './overview-taxonomy-badge'; |
| 6 |
import { Heading, CardImage, Text, Grid } from '@elementor/app-ui'; |
| 7 |
import { useState } from 'react'; |
| 8 |
import { appsEventTrackingDispatch } from 'elementor-app/event-track/apps-event-tracking'; |
| 9 |
|
| 10 |
import './overview-sidebar.scss'; |
| 11 |
|
| 12 |
export default function OverviewSidebar( props ) { |
| 13 |
const [ isTagsCollapseOpen, setIsTagsCollapseOpen ] = useState( true ); |
| 14 |
const [ isInformationCollapseOpen, setIsInformationCollapseOpen ] = useState( false ); |
| 15 |
const eventTracking = ( command, section = null, kitName = null, tag = null, isCollapsed = null, eventType = 'click' ) => { |
| 16 |
const action = isCollapsed && isCollapsed ? 'collapse' : 'expand'; |
| 17 |
if ( 'boolean' === typeof isCollapsed ) { |
| 18 |
command = `kit-library/${ action }`; |
| 19 |
} |
| 20 |
appsEventTrackingDispatch( |
| 21 |
command, |
| 22 |
{ |
| 23 |
page_source: 'overview', |
| 24 |
element_location: 'app_sidebar', |
| 25 |
kit_name: kitName, |
| 26 |
tag, |
| 27 |
section, |
| 28 |
event_type: eventType, |
| 29 |
}, |
| 30 |
); |
| 31 |
}; |
| 32 |
|
| 33 |
return ( |
| 34 |
<div className="e-kit-library__item-sidebar"> |
| 35 |
<div className="e-kit-library__item-sidebar-header"> |
| 36 |
<Heading |
| 37 |
tag="h1" |
| 38 |
variant="h5" |
| 39 |
className="e-kit-library__item-sidebar-header-title"> |
| 40 |
{ props.model.title } |
| 41 |
</Heading> |
| 42 |
<FavoritesActions |
| 43 |
isFavorite={ props.model.isFavorite } |
| 44 |
id={ props.model.id } |
| 45 |
/> |
| 46 |
</div> |
| 47 |
<CardImage |
| 48 |
className="e-kit-library__item-sidebar-thumbnail" |
| 49 |
alt={ props.model.title } |
| 50 |
src={ props.model.thumbnailUrl || '' } |
| 51 |
/> |
| 52 |
<Text className="e-kit-library__item-sidebar-description">{ props.model.description || '' }</Text> |
| 53 |
{ |
| 54 |
props.model.taxonomies.length > 0 && |
| 55 |
<Collapse |
| 56 |
isOpen={ isTagsCollapseOpen } |
| 57 |
onChange={ setIsTagsCollapseOpen } |
| 58 |
title={ __( 'TAGS', 'elementor' ) } |
| 59 |
className="e-kit-library__item-sidebar-collapse-tags" |
| 60 |
onClick={ ( collapseState, title ) => { |
| 61 |
eventTracking( null, title, null, null, collapseState ); |
| 62 |
} } |
| 63 |
> |
| 64 |
<Grid container className="e-kit-library__item-sidebar-tags-container"> |
| 65 |
{ props.model.taxonomies.map( ( taxonomy ) => ( |
| 66 |
<OverviewTaxonomyBadge |
| 67 |
key={ taxonomy } |
| 68 |
onClick={ ( taxonomyText ) => { |
| 69 |
eventTracking( 'kit-library/filter', null, props.model.title, taxonomyText ); |
| 70 |
} } |
| 71 |
>{ taxonomy }</OverviewTaxonomyBadge> |
| 72 |
) ) } |
| 73 |
</Grid> |
| 74 |
</Collapse> |
| 75 |
} |
| 76 |
{ |
| 77 |
props.groupedKitContent?.length > 0 && props.model.documents.length > 0 && |
| 78 |
<Collapse |
| 79 |
isOpen={ isInformationCollapseOpen } |
| 80 |
onChange={ setIsInformationCollapseOpen } |
| 81 |
title={ __( 'WHAT\'S INSIDE', 'elementor' ) } |
| 82 |
className="e-kit-library__item-sidebar-collapse-info" |
| 83 |
onClick={ ( collapseState, title ) => { |
| 84 |
eventTracking( null, title, null, null, collapseState ); |
| 85 |
} } |
| 86 |
> |
| 87 |
{ |
| 88 |
props.groupedKitContent.map( ( contentType ) => { |
| 89 |
if ( contentType.documents <= 0 ) { |
| 90 |
return ''; |
| 91 |
} |
| 92 |
|
| 93 |
return ( |
| 94 |
<Text className="e-kit-library__item-information-text" key={ contentType.id }> |
| 95 |
{ contentType.documents.length } { contentType.label } |
| 96 |
</Text> |
| 97 |
); |
| 98 |
} ) |
| 99 |
} |
| 100 |
</Collapse> |
| 101 |
} |
| 102 |
</div> |
| 103 |
); |
| 104 |
} |
| 105 |
|
| 106 |
OverviewSidebar.propTypes = { |
| 107 |
model: PropTypes.instanceOf( Kit ).isRequired, |
| 108 |
index: PropTypes.number, |
| 109 |
groupedKitContent: PropTypes.arrayOf( |
| 110 |
PropTypes.instanceOf( ContentType ), |
| 111 |
), |
| 112 |
}; |
| 113 |
|