Skip to content

Commit 52ccd8a

Browse files
authored
Merge pull request #340 from os2display/feature/reintroduce-lodash
Reintroduce lodash
2 parents 44136b3 + 54bb2fe commit 52ccd8a

12 files changed

Lines changed: 83 additions & 49 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ All notable changes to this project will be documented in this file.
2525
- Fix data fetching bug + tests
2626
- Refactored screen layout commands.
2727
- Moved list components (search and checkboxes) around.
28-
- Replaced lodash functions with native ones.
2928
- Aligned environment variable names.
3029
- Aligned with v. 2.6.0.
3130

assets/admin/components/playlist/playlist-campaign-manager.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
usePutV2PlaylistsByIdMutation,
1717
usePostV2PlaylistsMutation,
1818
} from "../../../shared/redux/enhanced-api.ts";
19+
import { set } from "lodash/object";
1920

2021
/**
2122
* The shared manager component.
@@ -280,7 +281,7 @@ function PlaylistCampaignManager({
280281
*/
281282
const handleInput = ({ target }) => {
282283
const localFormStateObject = { ...formStateObject };
283-
localFormStateObject[target.id] = target.value;
284+
set(localFormStateObject, target.id, target.value);
284285
setFormStateObject(localFormStateObject);
285286
};
286287

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
displayError,
1212
} from "../util/list/toast-component/display-toast";
1313
import idFromUrl from "../util/helpers/id-from-url";
14+
import { set } from "lodash/object";
1415

1516
/**
1617
* The screen manager component.
@@ -95,7 +96,7 @@ function ScreenManager({
9596
const handleInput = ({ target }) => {
9697
let localFormStateObject = { ...formStateObject };
9798
localFormStateObject = JSON.parse(JSON.stringify(localFormStateObject));
98-
localFormStateObject[target.id] = target.value;
99+
set(localFormStateObject, target.id, target.value);
99100
setFormStateObject(localFormStateObject);
100101
};
101102

assets/admin/components/slide/content/contacts/contact-form.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Col, Row } from "react-bootstrap";
22
import { useTranslation } from "react-i18next";
33
import FileSelector from "../file-selector";
44
import FormInput from "../../../util/forms/form-input";
5+
import { set } from "lodash/object";
56

67
/**
78
* Contact form.
@@ -27,7 +28,7 @@ function ContactForm({
2728
*/
2829
const onInput = ({ target }) => {
2930
const localContact = { ...contact };
30-
localContact[target.name] = target.value;
31+
set(localContact, target.name, target.value);
3132
onChange(localContact);
3233
};
3334

assets/admin/components/slide/content/feed-selector.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ContentForm from "./content-form";
1212
import MultiselectFromEndpoint from "./multiselect-from-endpoint";
1313
import PosterSelectorV1 from "./poster/poster-selector-v1";
1414
import PosterSelectorV2 from "./poster/poster-selector-v2";
15+
import { set } from "lodash/object";
1516

1617
/**
1718
* Feed selector.
@@ -99,12 +100,12 @@ function FeedSelector({
99100
const configuration = { ...value.configuration };
100101

101102
if (target !== null) {
102-
configuration[target.id] = target.value;
103+
set(configuration, target.id, target.value);
103104
}
104105

105106
if (targets !== null) {
106107
targets.forEach(({ id, value: targetValue }) => {
107-
configuration[id] = targetValue;
108+
set(configuration, id, targetValue);
108109
});
109110
}
110111

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "../util/list/toast-component/display-toast";
2020
import idFromUrl from "../util/helpers/id-from-url";
2121
import localStorageKeys from "../util/local-storage-keys";
22+
import { get, set } from "lodash/object";
2223

2324
/**
2425
* The slide manager component.
@@ -153,7 +154,7 @@ function SlideManager({
153154
*/
154155
const handleInput = ({ target }) => {
155156
const localFormStateObject = { ...formStateObject };
156-
localFormStateObject[target.id] = target.value;
157+
set(localFormStateObject, target.id, target.value);
157158
setFormStateObject(localFormStateObject);
158159
};
159160

@@ -206,7 +207,7 @@ function SlideManager({
206207
const value =
207208
target.type === "number" ? target.valueAsNumber : target.value;
208209
const localFormStateObject = { ...formStateObject };
209-
localFormStateObject.content[target.id] = value;
210+
set(localFormStateObject.content, target.id, value);
210211
setFormStateObject(localFormStateObject);
211212
};
212213

@@ -351,12 +352,12 @@ function SlideManager({
351352
// It is an already added temp file.
352353
if (entry.tempId) {
353354
newField.push(entry.tempId);
354-
localMediaData[entry.tempId] = entry;
355+
set(localMediaData, entry.tempId, entry);
355356
}
356357
// It is a new temp file.
357358
else {
358359
if (!Array.isArray(localFormStateObject.content[fieldId])) {
359-
localFormStateObject.content[fieldId] = [];
360+
set(localFormStateObject.content, fieldId, []);
360361
}
361362

362363
// Create a tempId for the media.
@@ -367,7 +368,7 @@ function SlideManager({
367368

368369
const newEntry = { ...entry };
369370
newEntry.tempId = tempId;
370-
localMediaData[tempId] = newEntry;
371+
set(localMediaData, tempId, newEntry);
371372
}
372373
}
373374
// Previously selected file.
@@ -381,16 +382,18 @@ function SlideManager({
381382
if (
382383
!Object.prototype.hasOwnProperty.call(localMediaData, entry["@id"])
383384
) {
384-
localMediaData[entry["@id"]] = entry;
385+
set(localMediaData, entry["@id"], entry);
385386

386387
localFormStateObject.media.push(entry["@id"]);
387388
}
388389
}
389390
});
390391
}
391392

392-
localFormStateObject.content[fieldId] = newField;
393-
localFormStateObject.media = [...new Set([...localFormStateObject.media])];
393+
set(localFormStateObject.content, fieldId, newField);
394+
set(localFormStateObject, "media", [
395+
...new Set([...localFormStateObject.media]),
396+
]);
394397

395398
setFormStateObject(localFormStateObject);
396399
setMediaData(localMediaData);
@@ -402,7 +405,7 @@ function SlideManager({
402405

403406
// Setup submittingMedia list.
404407
mediaFields.forEach((fieldName) => {
405-
const fieldData = formStateObject.content[fieldName];
408+
const fieldData = get(formStateObject.content, fieldName);
406409

407410
if (fieldData) {
408411
if (Array.isArray(fieldData)) {
@@ -552,10 +555,14 @@ function SlideManager({
552555
newFormStateObject.media.push(savedMediaData["@id"]);
553556

554557
// Replace TEMP-- id with real id.
555-
newFormStateObject.content[submittedMedia.fieldName] =
556-
newFormStateObject.content[submittedMedia.fieldName].map((mediaId) =>
557-
mediaId === submittedMedia.tempId ? savedMediaData["@id"] : mediaId,
558-
);
558+
set(
559+
newFormStateObject.content,
560+
submittedMedia.fieldName,
561+
get(newFormStateObject.content, submittedMedia.fieldName).map(
562+
(mediaId) =>
563+
mediaId === submittedMedia.tempId ? savedMediaData["@id"] : mediaId,
564+
),
565+
);
559566

560567
const newMediaData = { ...mediaData };
561568
newMediaData[savedMediaData["@id"]] = savedMediaData;

assets/admin/components/util/table/table-body.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Fragment } from "react";
22
import useModal from "../../../context/modal-context/modal-context-hook";
3+
import { get } from "lodash/object";
34

45
/**
56
* @param {object} props The props.
@@ -22,7 +23,7 @@ function TableBody({ columns, data }) {
2223
return column.content(item);
2324
}
2425

25-
let cellData = item[column.path];
26+
let cellData = get(item, column.path);
2627

2728
if (column.dataFunction) {
2829
cellData = column.dataFunction(cellData);

assets/client/data-sync/pull-strategy.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import isPublished from "../util/isPublished";
22
import logger from "../logger/logger";
33
import ApiHelper from "./api-helper";
4+
import { cloneDeep } from "lodash";
45

56
/**
67
* PullStrategy.
@@ -135,7 +136,7 @@ class PullStrategy {
135136
async getSlidesForRegions(regions) {
136137
return new Promise((resolve, reject) => {
137138
const promises = [];
138-
const regionData = structuredClone(regions);
139+
const regionData = cloneDeep(regions);
139140

140141
// @TODO: Fix eslint-raised issues.
141142
// eslint-disable-next-line guard-for-in,no-restricted-syntax
@@ -199,7 +200,7 @@ class PullStrategy {
199200
return;
200201
}
201202

202-
const newScreen = structuredClone(screen);
203+
const newScreen = cloneDeep(screen);
203204

204205
newScreen.hasActiveCampaign = false;
205206

@@ -303,7 +304,7 @@ class PullStrategy {
303304
const dataEntrySlidesData = dataEntryPlaylist.slidesData;
304305

305306
for (const slideKey of Object.keys(dataEntrySlidesData)) {
306-
const slide = structuredClone(dataEntrySlidesData[slideKey]);
307+
const slide = cloneDeep(dataEntrySlidesData[slideKey]);
307308

308309
let previousSlide = null;
309310

@@ -314,7 +315,7 @@ class PullStrategy {
314315
this.lastestScreenData.regionData[regionKey][playlistKey]
315316
.slidesData[slideKey]
316317
) {
317-
previousSlide = structuredClone(
318+
previousSlide = cloneDeep(
318319
this.lastestScreenData.regionData[regionKey][playlistKey]
319320
.slidesData[slideKey],
320321
);

assets/client/service/schedule-service.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import isPublished from "../util/isPublished";
55
import logger from "../logger/logger";
66
import ClientConfigLoader from "../util/client-config-loader.js";
77
import ScheduleUtils from "../util/schedule";
8+
import { cloneDeep } from "lodash";
89

910
/**
1011
* ScheduleService.
@@ -213,7 +214,7 @@ class ScheduleService {
213214
return;
214215
}
215216

216-
const newSlide = structuredClone(slide);
217+
const newSlide = cloneDeep(slide);
217218

218219
// Execution id is the product of region, playlist and slide id, to ensure uniqueness in the client.
219220
const executionId = Md5(regionId + playlist["@id"] + slide["@id"]);

assets/tests/template/template-calendar.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ const fixTime = async (page) => {
1010
await page.clock.install({ time: newDate });
1111
};
1212

13-
const fixTimeToNow = async (page) => {
14-
const newDate = new Date();
15-
await page.clock.install({ time: newDate });
16-
};
17-
1813
test("calendar-0-multiple-days: ui tests", async ({ page }) => {
1914
await fixTime(page);
2015

@@ -236,7 +231,7 @@ test("calendar-0-single-booking: ui tests", async ({ page }) => {
236231
});
237232

238233
test("calendar-1-single-booking: ui tests", async ({ page }) => {
239-
await fixTimeToNow(page);
234+
await fixTime(page);
240235
await page.goto("/template/calendar-1-single-booking");
241236
await expect(page.getByText("Ledigt")).toHaveCount(1);
242237
await expect(page.getByText("Ledigt")).toBeVisible();

0 commit comments

Comments
 (0)