Skip to content

Commit 63f335f

Browse files
committed
6871: Fixed screen save issue
1 parent cbe4232 commit 63f335f

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

assets/admin/components/screen/screen-manager.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function ScreenManager({
127127
* @returns {Array | null} A mapped array with group ids or null
128128
*/
129129
function mapGroups() {
130-
if (formStateObject.inScreenGroups) {
130+
if (formStateObject?.inScreenGroups instanceof Array) {
131131
return formStateObject.inScreenGroups.map((group) => {
132132
return idFromUrl(group);
133133
});
@@ -167,16 +167,17 @@ function ScreenManager({
167167
*
168168
* @returns {Array | null} A mapped array with playlist, regions and weight or null
169169
*/
170-
function mapPlaylistsWithRegion() {
170+
function mapPlaylistsWithRegion(playlists, regions) {
171171
const returnArray = [];
172-
const { playlists, regions } = formStateObject;
173-
const regionIds = regions.map((r) => idFromUrl(r["@id"]));
172+
const regionIds = regions.map((r) =>
173+
typeof r === "string" ? idFromUrl(r, 1) : idFromUrl(r["@id"])
174+
);
174175

175176
// The playlists all have a regionId, the following creates a unique list of relevant regions If there are not
176177
// playlists, then an empty playlist is to be saved per region
177178
let playlistRegions = [];
178179
if (playlists?.length > 0) {
179-
playlistRegions = [...new Set(playlists.map(({ region }) => region))];
180+
playlistRegions = [...new Set(playlists.map(({ region }) => idFromUrl(region)))];
180181
}
181182

182183
// Then the playlists are mapped by region Looping through the regions that have a playlist connected...
@@ -191,6 +192,7 @@ function ScreenManager({
191192
regionId: idFromUrl(regionId),
192193
});
193194
});
195+
194196
// The remaining regions are added with empty playlist arrays.
195197
if (regionIds.length > 0) {
196198
regionIds.forEach((regionId) =>
@@ -252,7 +254,7 @@ function ScreenManager({
252254
resolution: getResolution(),
253255
groups: mapGroups(),
254256
orientation: getOrientation(),
255-
regions: mapPlaylistsWithRegion(),
257+
regions: mapPlaylistsWithRegion(localFormStateObject.playlists, localFormStateObject.regions),
256258
}),
257259
};
258260

assets/admin/components/util/helpers/id-from-url.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
function idFromUrl(string, index = 0) {
77
if (typeof string === "string") {
8-
return string.match(/[A-Za-z0-9]{26}/g)[index];
8+
return (string.match(/[A-Za-z0-9]{26}/g) ?? [])[index] ?? "";
99
}
1010
return "";
1111
}

0 commit comments

Comments
 (0)