| 1 |
import Content from 'elementor-app/layout/content'; |
| 2 |
import ElementorLoading from 'elementor-app/molecules/elementor-loading'; |
| 3 |
import ItemHeader from '../../components/item-header'; |
| 4 |
import Layout from '../../components/layout'; |
| 5 |
import OverviewContentGroup from './overview-content-group'; |
| 6 |
import OverviewSidebar from './overview-sidebar'; |
| 7 |
import useKit from '../../hooks/use-kit'; |
| 8 |
import useKitDocumentByType from '../../hooks/use-kit-document-by-type'; |
| 9 |
import usePageTitle from 'elementor-app/hooks/use-page-title'; |
| 10 |
import { useMemo } from 'react'; |
| 11 |
import { useNavigate } from '@reach/router'; |
| 12 |
import { appsEventTrackingDispatch } from 'elementor-app/event-track/apps-event-tracking'; |
| 13 |
|
| 14 |
import './overview.scss'; |
| 15 |
|
| 16 |
function useHeaderButtons( id, kitName ) { |
| 17 |
const navigate = useNavigate(); |
| 18 |
|
| 19 |
return useMemo( () => [ |
| 20 |
{ |
| 21 |
id: 'view-demo', |
| 22 |
text: __( 'View Demo', 'elementor' ), |
| 23 |
hideText: false, |
| 24 |
variant: 'outlined', |
| 25 |
color: 'secondary', |
| 26 |
size: 'sm', |
| 27 |
onClick: () => { |
| 28 |
appsEventTrackingDispatch( |
| 29 |
'kit-library/view-demo-page', |
| 30 |
{ |
| 31 |
kit_name: kitName, |
| 32 |
page_source: 'overview', |
| 33 |
element_position: 'app_header', |
| 34 |
view_type_clicked: 'demo', |
| 35 |
}, |
| 36 |
); |
| 37 |
navigate( `/kit-library/preview/${ id }` ); |
| 38 |
}, |
| 39 |
includeHeaderBtnClass: false, |
| 40 |
}, |
| 41 |
], [ id ] ); |
| 42 |
} |
| 43 |
|
| 44 |
export default function Overview( props ) { |
| 45 |
const { data: kit, isError, isLoading } = useKit( props.id ); |
| 46 |
const { data: documentsByType } = useKitDocumentByType( kit ); |
| 47 |
const headerButtons = useHeaderButtons( props.id, kit && kit.title ); |
| 48 |
|
| 49 |
usePageTitle( { |
| 50 |
title: kit |
| 51 |
? `${ __( 'Kit Library', 'elementor' ) } | ${ kit.title }` |
| 52 |
// eslint-disable-next-line @wordpress/i18n-ellipsis |
| 53 |
: __( 'Loading...', 'elementor' ), |
| 54 |
} ); |
| 55 |
|
| 56 |
if ( isError ) { |
| 57 |
// Will be caught by the App error boundary. |
| 58 |
throw new Error(); |
| 59 |
} |
| 60 |
|
| 61 |
if ( isLoading ) { |
| 62 |
return <ElementorLoading />; |
| 63 |
} |
| 64 |
|
| 65 |
return ( |
| 66 |
<Layout |
| 67 |
header={ <ItemHeader model={ kit } buttons={ headerButtons } pageId="overview" /> } |
| 68 |
sidebar={ <OverviewSidebar model={ kit } groupedKitContent={ documentsByType } /> } |
| 69 |
> |
| 70 |
{ |
| 71 |
documentsByType.length > 0 && |
| 72 |
<Content> |
| 73 |
{ |
| 74 |
documentsByType.map( ( contentType ) => ( |
| 75 |
<OverviewContentGroup |
| 76 |
key={ contentType.id } |
| 77 |
contentType={ contentType } |
| 78 |
kitId={ props.id } |
| 79 |
kitTitle={ kit.title } |
| 80 |
/> |
| 81 |
) ) |
| 82 |
} |
| 83 |
</Content> |
| 84 |
} |
| 85 |
</Layout> |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
Overview.propTypes = { |
| 90 |
id: PropTypes.string, |
| 91 |
}; |
| 92 |
|