Skip to content

Commit 6ac49a4

Browse files
authored
Changing themes of series fixed (#1254)
* Changing themes of series fixed In the series dialog the themes selection is fixed. fixes #1205 * Review comments solved * Provides type of variable
1 parent 6c75239 commit 6ac49a4

2 files changed

Lines changed: 60 additions & 73 deletions

File tree

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { updateSeriesTheme } from "../../../../slices/seriesDetailsSlice";
1111
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";
1212
import ModalContentTable from "../../../shared/modals/ModalContentTable";
1313

14+
type SeriesTheme = { id: string; value: string; };
15+
1416
/**
1517
* This component renders the tab for editing the theme of a certain series
1618
*/
@@ -19,23 +21,20 @@ const SeriesDetailsThemeTab = ({
1921
themeNames,
2022
seriesId,
2123
}: {
22-
theme: string,
23-
themeNames: {
24-
id: string;
25-
value: string;
26-
}[],
24+
theme: SeriesTheme | null,
25+
themeNames: SeriesTheme[],
2726
seriesId: string
2827
}) => {
2928
const { t } = useTranslation();
3029
const dispatch = useAppDispatch();
3130

3231
const user = useAppSelector(state => getUserInformation(state));
3332

34-
const handleSubmit = (values: { theme: string }) => {
33+
const handleSubmit = (values: { theme: SeriesTheme | null }) => {
3534
dispatch(updateSeriesTheme({id: seriesId, values: values}));
3635
};
3736

38-
const checkValidity = (formik: FormikProps<{theme: string }>) => {
37+
const checkValidity = (formik: FormikProps<{theme: SeriesTheme | null }>) => {
3938
if (formik.dirty && formik.isValid) {
4039
// check if user provided values differ from initial ones
4140
return !_.isEqual(formik.values, formik.initialValues);
@@ -64,13 +63,13 @@ const SeriesDetailsThemeTab = ({
6463
{themeNames.length > 0 && (
6564
<div className="editable">
6665
<DropDown
67-
value={formik.values.theme}
68-
text={formik.values.theme}
66+
value={formik.values.theme?.id}
67+
text={formik.values.theme?.value || ''}
6968
options={themeNames.map(names => ({ label: names.value, value: names.id }))}
7069
required={false}
7170
handleChange={(element) => {
7271
if (element) {
73-
formik.setFieldValue("theme", element.value)
72+
formik.setFieldValue("theme", {id: element.value, value: element.label})
7473
}
7574
}}
7675
placeholder={t("EVENTS.SERIES.NEW.THEME.LABEL")}

src/slices/seriesDetailsSlice.ts

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type SeriesDetailsState = {
5151
metadata: MetadataCatalog,
5252
extendedMetadata: MetadataCatalog[],
5353
acl: TransformedAcl[],
54-
theme: string,
54+
theme: { id: string, value: string } | null,
5555
themeNames: { id: string, value: string }[],
5656
fetchingStatisticsInProgress: boolean,
5757
statistics: Statistics[],
@@ -83,7 +83,7 @@ const initialState: SeriesDetailsState = {
8383
},
8484
extendedMetadata: [],
8585
acl: [],
86-
theme: "",
86+
theme: null,
8787
themeNames: [],
8888
fetchingStatisticsInProgress: false,
8989
statistics: [],
@@ -165,12 +165,12 @@ export const fetchSeriesDetailsTheme = createAppAsyncThunk('seriesDetails/fetchS
165165
const res = await axios.get(`/admin-ng/series/${id}/theme.json`);
166166
const themeResponse = res.data;
167167

168-
let seriesTheme = "";
168+
let seriesTheme: SeriesDetailsState["theme"] = null;
169169

170170
// check if series has a theme
171171
if (!_.isEmpty(themeResponse)) {
172172
// transform response for further use
173-
seriesTheme = transformToIdValueArray(themeResponse)[0].value;
173+
seriesTheme = transformToIdValueArray(themeResponse)[0];
174174
}
175175

176176
return seriesTheme;
@@ -302,67 +302,55 @@ export const updateSeriesAccess = createAppAsyncThunk('seriesDetails/updateSerie
302302
export const updateSeriesTheme = createAppAsyncThunk('seriesDetails/updateSeriesTheme', async (params: {
303303
id: string,
304304
values: { theme: SeriesDetailsState["theme"] },
305-
}, {dispatch, getState}) => {
305+
}, {dispatch}) => {
306306
const { id, values } = params;
307307

308-
let themeNames = getSeriesDetailsThemeNames(getState());
309-
310-
let themeId = themeNames.find((theme) => theme.value === values.theme)?.id;
311-
312-
if (!values.theme) {
313-
axios
314-
.delete(`/admin-ng/series/${id}/theme`)
315-
.then((response) => {
316-
dispatch(
317-
addNotification({
318-
type: "warning",
319-
key: "SERIES_THEME_REPROCESS_EXISTING_EVENTS",
320-
duration: 10,
321-
parameter: undefined,
322-
context: NOTIFICATION_CONTEXT
323-
})
324-
);
325-
})
326-
.catch((response) => {
327-
console.error(response);
328-
});
329-
} else if (!themeId) {
330-
console.error("Can't update series theme. " + values.theme + " not found");
331-
dispatch(
332-
addNotification({
333-
type: "error",
334-
key: "SERIES_NOT_SAVED",
335-
duration: 10,
336-
parameter: undefined,
337-
context: NOTIFICATION_CONTEXT
338-
})
339-
);
340-
} else {
341-
let data = new URLSearchParams();
342-
data.append("themeId", themeId);
343-
344-
axios
345-
.put(`/admin-ng/series/${id}/theme`, data)
346-
.then((response) => {
347-
let themeResponse = response.data;
348-
349-
let seriesTheme = transformToIdValueArray(themeResponse)[0].value;
350-
351-
dispatch(setSeriesDetailsTheme(seriesTheme));
352-
dispatch(
353-
addNotification({
354-
type: "warning",
355-
key: "SERIES_THEME_REPROCESS_EXISTING_EVENTS",
356-
duration: 10,
357-
parameter: undefined,
358-
context: NOTIFICATION_CONTEXT
359-
})
360-
);
361-
})
362-
.catch((response) => {
363-
console.error(response);
364-
});
365-
}
308+
let themeId = values.theme?.id;
309+
310+
if (!themeId || themeId === '') {
311+
axios
312+
.delete(`/admin-ng/series/${id}/theme`)
313+
.then((response) => {
314+
dispatch(setSeriesDetailsTheme(values.theme));
315+
dispatch(
316+
addNotification({
317+
type: "warning",
318+
key: "SERIES_THEME_REPROCESS_EXISTING_EVENTS",
319+
duration: 10,
320+
parameter: undefined,
321+
context: NOTIFICATION_CONTEXT
322+
})
323+
);
324+
})
325+
.catch((response) => {
326+
console.error(response);
327+
});
328+
} else {
329+
let data = new URLSearchParams();
330+
data.append("themeId", themeId);
331+
332+
axios
333+
.put(`/admin-ng/series/${id}/theme`, data)
334+
.then((response) => {
335+
let themeResponse = response.data;
336+
337+
let seriesTheme = transformToIdValueArray(themeResponse)[0];
338+
339+
dispatch(setSeriesDetailsTheme(seriesTheme));
340+
dispatch(
341+
addNotification({
342+
type: "warning",
343+
key: "SERIES_THEME_REPROCESS_EXISTING_EVENTS",
344+
duration: 10,
345+
parameter: undefined,
346+
context: NOTIFICATION_CONTEXT
347+
})
348+
);
349+
})
350+
.catch((response) => {
351+
console.error(response);
352+
});
353+
}
366354
});
367355

368356
// fetch Tobira data of certain series from server

0 commit comments

Comments
 (0)