1- import { useContext } from "react" ;
21import { useTranslation } from "react-i18next" ;
32import ColumnHoc from "../util/column-hoc" ;
43import SelectColumnHoc from "../util/select-column-hoc" ;
5- import UserContext from "../../context/user-context" ;
6- import ListButton from "../util/list/list-button" ;
74import DateValue from "../util/date-value" ;
85import PublishingStatus from "../util/publishingStatus" ;
6+ import useModal from "../../context/modal-context/modal-context-hook.jsx" ;
7+ import { useDispatch } from "react-redux" ;
8+ import { enhancedApi } from "../../../shared/redux/enhanced-api.ts" ;
9+ import idFromUrl from "../util/helpers/id-from-url.jsx" ;
10+ import getAllPages from "../util/helpers/get-all-pages.js" ;
11+ import { Link } from "react-router-dom" ;
12+ import { Button } from "react-bootstrap" ;
13+
14+ function SlidesButton ( { playlist } ) {
15+ const { t } = useTranslation ( "common" , { keyPrefix : "playlists-columns" } ) ;
16+ const { setModal } = useModal ( ) ;
17+ const dispatch = useDispatch ( ) ;
18+
19+ const onClick = ( ) => {
20+ getAllPages ( dispatch , enhancedApi . endpoints . getV2PlaylistsByIdSlides , {
21+ id : idFromUrl ( playlist . id ) ,
22+ } ) . then ( ( playlistSlides ) => {
23+ const content = (
24+ < ul >
25+ { playlistSlides . map ( ( playlistSlide ) => (
26+ < li key = { playlistSlide ?. slide [ "@id" ] } >
27+ < Link
28+ to = { `slide/edit/${ idFromUrl ( playlistSlide ?. slide [ "@id" ] ) } ` }
29+ target = "_blank"
30+ >
31+ { playlistSlide ?. slide . title }
32+ </ Link >
33+ </ li >
34+ ) ) }
35+ </ ul >
36+ ) ;
37+
38+ setModal ( {
39+ info : true ,
40+ modalTitle : t ( "playlist-slide-modal-title" ) ,
41+ content,
42+ } ) ;
43+ } ) ;
44+ } ;
45+
46+ return (
47+ < Button
48+ variant = "secondary"
49+ type = "button"
50+ onClick = { onClick }
51+ disabled = { playlist . slidesLength === 0 }
52+ >
53+ { playlist . slidesLength }
54+ </ Button >
55+ ) ;
56+ }
957
1058/**
1159 * Columns for playlists lists.
@@ -17,40 +65,16 @@ import PublishingStatus from "../util/publishingStatus";
1765 * @param {string } props.dataKey The data key for mapping the data.
1866 * @returns {object } The columns for the playlists lists.
1967 */
20- function getPlaylistColumns ( {
21- apiCall,
22- infoModalRedirect,
23- infoModalTitle,
24- dataKey,
25- } ) {
26- const context = useContext ( UserContext ) ;
68+ function getPlaylistColumns ( ) {
2769 const { t } = useTranslation ( "common" , {
2870 keyPrefix : "playlists-columns" ,
2971 } ) ;
3072
3173 const columns = [
3274 {
33- key : "slides " ,
75+ key : "playlist " ,
3476 label : t ( "number-of-slides" ) ,
35- render : ( { tenants } ) => {
36- return (
37- tenants ?. length === 0 ||
38- ! tenants . find (
39- ( tenant ) =>
40- tenant . tenantKey === context . selectedTenant . get . tenantKey ,
41- )
42- ) ;
43- } ,
44- // eslint-disable-next-line react/prop-types
45- content : ( { slides, playlistSlides } ) => (
46- < ListButton
47- apiCall = { apiCall }
48- redirectTo = { infoModalRedirect }
49- displayData = { slides || playlistSlides }
50- modalTitle = { infoModalTitle }
51- dataKey = { dataKey }
52- />
53- ) ,
77+ content : ( playlist ) => < SlidesButton playlist = { playlist } /> ,
5478 } ,
5579 {
5680 key : "publishing-from" ,
0 commit comments