Skip to content

Commit fe113d7

Browse files
authored
Respect publication channels listprovider more (#738)
* Respect publication channels listprovider more While we were already getting information on publications from the respective listprovider for the event details, we were not putting all of it to use, for example ordering. Also, the event table did not have access to this information at all. This should fix that. * Fix variable name * Remove unexpected tab character * Fix thunk naming
1 parent a5f60fa commit fe113d7

5 files changed

Lines changed: 93 additions & 75 deletions

File tree

src/components/events/partials/ModalTabsAndPages/EventDetailsPublicationTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const EventDetailsPublicationTab = ({
6161
)}
6262
</span>
6363
<div>
64-
<span>{t(publication.name)}</span>
64+
<span>{publication.label ? t(publication.label) : t(publication.name)}</span>
6565
{publication.description && (
6666
<p className="description">
6767
{publication.description}

src/components/events/partials/PublishedCell.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const PublishCell = ({
4040

4141
const onlyEngage = row.publications.length === 1
4242
&& row.publications[0].enabled
43-
&& !row.publications[0].hiding
43+
&& !row.publications[0].hide
4444
&& row.publications[0].id === 'engage-player';
4545

4646
return (
@@ -65,7 +65,7 @@ const PublishCell = ({
6565
<div className="popover__content">
6666
{/* Show a list item for each publication of an event that isn't hidden*/}
6767
{row.publications.map((publication, key) =>
68-
!publication.hiding ? (
68+
!publication.hide ? (
6969
// Check if publications is enabled and choose icon according
7070
publication.enabled ? (
7171
<a
@@ -75,11 +75,11 @@ const PublishCell = ({
7575
rel='noreferrer'
7676
key={key}
7777
>
78-
<span>{t(publication.name)}</span>
78+
<span>{publication.label ? t(publication.label) : t(publication.name)}</span>
7979
</a>
8080
) : (
8181
<button key={key} className="button-like-anchor popover__list-item">
82-
<span>{t(publication.name)}</span>
82+
<span>{publication.label ? t(publication.label) : t(publication.name)}</span>
8383
</button>
8484
)
8585
) : null

src/slices/eventDetailsSlice.ts

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { fetchRecordings } from "./recordingSlice";
2525
import { getRecordings } from "../selectors/recordingSelectors";
2626
import { createAppAsyncThunk } from '../createAsyncThunkWithTypes';
2727
import { Statistics, fetchStatistics, fetchStatisticsValueUpdate } from './statisticsSlice';
28+
import { enrichPublications } from '../thunks/assetsThunks';
2829
import { TransformedAcl } from './aclDetailsSlice';
2930
import { MetadataCatalog } from './eventSlice';
3031
import { Event } from "./eventSlice";
@@ -127,11 +128,11 @@ export type UploadAssetOption = {
127128

128129
export type Publication = {
129130
enabled: boolean,
130-
hide?: string,
131131
icon?: string,
132132
id: string,
133133
label?: string,
134-
name: string, // translation key
134+
hide?: boolean,
135+
name: string, // translation key
135136
order: number,
136137
url: string,
137138
description?: string,
@@ -910,66 +911,20 @@ export const fetchComments = createAppAsyncThunk('eventDetails/fetchComments', a
910911
return { comments, commentReasons }
911912
});
912913

913-
export const fetchEventPublications = createAppAsyncThunk('eventDetails/fetchEventPublications', async (eventId: string) => {
914+
export const fetchEventPublications = createAppAsyncThunk('eventDetails/fetchEventPublications', async (eventId: string, { dispatch }) => {
914915
let data = await axios.get(`/admin-ng/event/${eventId}/publications.json`);
915916

916917
let publications: {
917-
"start-date": string,
918-
"end-date": string,
919918
publications: {
920919
id: string,
921920
name: string,
922921
url: string,
923922
}[],
923+
"start-date": string,
924+
"end-date": string,
924925
} = await data.data;
925926

926-
// get information about possible publication channels
927-
data = await axios.get("/admin-ng/resources/PUBLICATION.CHANNELS.json");
928-
929-
let publicationChannels: { [key: string]: string } = await data.data;
930-
931-
let now = new Date();
932-
933-
let transformedPublications: Publication[] = [];
934-
935-
// fill publication objects with additional information
936-
publications.publications.forEach((publication) => {
937-
let transformedPublication: Publication = {
938-
...publication,
939-
enabled: false,
940-
order: 0,
941-
};
942-
943-
transformedPublication.enabled = !(
944-
publication.id === "engage-live" &&
945-
(now < new Date(publications["start-date"]) ||
946-
now > new Date(publications["end-date"]))
947-
);
948-
949-
if (publicationChannels[publication.id]) {
950-
let channel = JSON.parse(publicationChannels[publication.id]);
951-
952-
if (channel.label) {
953-
transformedPublication.label = channel.label;
954-
}
955-
if (channel.icon) {
956-
transformedPublication.icon = channel.icon;
957-
}
958-
if (channel.hide) {
959-
transformedPublication.hide = channel.hide;
960-
}
961-
if (channel.description) {
962-
transformedPublication.description = channel.description;
963-
}
964-
if (channel.order) {
965-
transformedPublication.order = channel.order;
966-
}
967-
}
968-
969-
transformedPublications.push(transformedPublication)
970-
});
971-
972-
return transformedPublications;
927+
return await dispatch(enrichPublications(publications)).unwrap();
973928
});
974929

975930
// fetch Tobira data of certain series from server

src/slices/eventSlice.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PayloadAction, SerializedError, createSlice } from '@reduxjs/toolkit'
1+
import { PayloadAction, SerializedError, createSlice, unwrapResult } from '@reduxjs/toolkit'
22
import { eventsTableConfig } from "../configs/tableConfigs/eventsTableConfig";
33
import axios, { AxiosProgressEvent } from 'axios';
44
import moment from "moment-timezone";
@@ -23,9 +23,10 @@ import {
2323
import { getAssetUploadOptions, getSchedulingEditedEvents } from '../selectors/eventSelectors';
2424
import { fetchSeriesOptions } from "./seriesSlice";
2525
import { AppDispatch } from '../store';
26-
import { fetchAssetUploadOptions } from '../thunks/assetsThunks';
26+
import { enrichPublications, fetchAssetUploadOptions } from '../thunks/assetsThunks';
2727
import { TransformedAcl } from './aclDetailsSlice';
2828
import { TableConfig } from '../configs/tableConfigs/aclsTableConfig';
29+
import { Publication } from './eventDetailsSlice';
2930
import { createAppAsyncThunk } from '../createAsyncThunkWithTypes';
3031
import { FormikErrors } from 'formik';
3132

@@ -73,13 +74,7 @@ export type Event = {
7374
managedAcl: string,
7475
needs_cutting: boolean,
7576
presenters: string[],
76-
publications: {
77-
enabled: boolean,
78-
hiding: boolean,
79-
id: string,
80-
name: string,
81-
url: string,
82-
}[],
77+
publications: Publication[],
8378
selected?: boolean,
8479
series?: { id: string, title: string }
8580
source: string,
@@ -233,7 +228,7 @@ const initialState: EventState = {
233228
};
234229

235230
// fetch events from server
236-
export const fetchEvents = createAppAsyncThunk('events/fetchEvents', async (_, { getState }) => {
231+
export const fetchEvents = createAppAsyncThunk('events/fetchEvents', async (_, { dispatch, getState }) => {
237232
const state = getState();
238233
let params: ReturnType<typeof getURLParams> & { getComments?: boolean } = getURLParams(state);
239234

@@ -257,16 +252,15 @@ export const fetchEvents = createAppAsyncThunk('events/fetchEvents', async (_, {
257252
...response.results[i],
258253
date: response.results[i].start_date,
259254
};
260-
// insert enabled and hiding property of publications, if result has publications
255+
// insert enabled and hide property of publications, if result has publications
261256
let result = response.results[i];
262257
if (!!result.publications && result.publications.length > 0) {
263-
let transformedPublications = [];
264-
for (let j = 0; result.publications.length > j; j++) {
265-
transformedPublications.push({
266-
...result.publications[j],
267-
enabled: true,
268-
hiding: false,
269-
});
258+
let transformedPublications: Publication[] = [];
259+
try {
260+
const resultAction = await dispatch(enrichPublications({ publications: result.publications }));
261+
transformedPublications = unwrapResult(resultAction);
262+
} catch (rejectedValueOrSerializedError) {
263+
console.error(rejectedValueOrSerializedError)
270264
}
271265
response.results[i] = {
272266
...response.results[i],

src/thunks/assetsThunks.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios from "axios";
22
import { getAssetUploadOptions } from "../selectors/eventSelectors";
33
import { createAppAsyncThunk } from '../createAsyncThunkWithTypes';
44
import { UploadAssetOption } from "../slices/eventSlice";
5+
import { Publication } from "../slices/eventDetailsSlice";
56

67
// thunks for assets, especially for getting asset options
78

@@ -54,3 +55,71 @@ export const fetchAssetUploadOptions = createAppAsyncThunk('assets/fetchAssetUpl
5455
return { workflow, newAssetUploadOptions };
5556
}
5657
});
58+
59+
/**
60+
* Adds information from the publication list provider to publications.
61+
* The additional info is used for rendering purposes
62+
*/
63+
export const enrichPublications = createAppAsyncThunk('assets/enrichPublications', async (
64+
publications: {
65+
publications: {
66+
id: string,
67+
name: string,
68+
url: string,
69+
}[],
70+
"start-date"?: string,
71+
"end-date"?: string,
72+
},
73+
) => {
74+
// get information about possible publication channels
75+
let data = await axios.get("/admin-ng/resources/PUBLICATION.CHANNELS.json");
76+
77+
let publicationChannels: { [key: string]: string } = await data.data;
78+
79+
let now = new Date();
80+
let combinedPublications: Publication[] = [];
81+
82+
// fill publication objects with additional information
83+
publications.publications.forEach((publication) => {
84+
let newPublication: Publication = {
85+
enabled: true,
86+
id: publication.id,
87+
name: publication.name,
88+
order: 0,
89+
url: publication.url,
90+
};
91+
newPublication.enabled = (publications["start-date"] && publications["end-date"]) ?
92+
!(
93+
publication.id === "engage-live" &&
94+
(now < new Date(publications["start-date"]) ||
95+
now > new Date(publications["end-date"]))
96+
)
97+
:
98+
true;
99+
100+
if (publicationChannels[publication.id]) {
101+
let channel = JSON.parse(publicationChannels[publication.id]);
102+
103+
if (channel.label) {
104+
newPublication.label = channel.label;
105+
}
106+
if (channel.icon) {
107+
newPublication.icon = channel.icon;
108+
}
109+
if (channel.hide) {
110+
newPublication.hide = channel.hide;
111+
}
112+
if (channel.description) {
113+
newPublication.description = channel.description;
114+
}
115+
if (channel.order) {
116+
newPublication.order = channel.order;
117+
}
118+
}
119+
combinedPublications.push(newPublication);
120+
});
121+
122+
combinedPublications = combinedPublications.sort(({order: a}, {order:b}) => a - b);
123+
124+
return combinedPublications;
125+
});

0 commit comments

Comments
 (0)