Skip to content

Commit 6d27945

Browse files
authored
Merge pull request #285 from os2display/feature/screen-save-fix
feature/screen save fix
2 parents 3902d0e + a64fa47 commit 6d27945

File tree

9 files changed

+254
-275
lines changed

9 files changed

+254
-275
lines changed

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"plugins": ["react", "prettier", "only-warn"],
2+
"plugins": ["react", "prettier"],
33
"extends": [
44
"airbnb",
55
"prettier",
@@ -18,7 +18,9 @@
1818
"allowImportExportEverywhere": true
1919
},
2020
"rules": {
21+
"react/react-in-jsx-scope": "off",
2122
"react/require-default-props": "off",
23+
"react/prop-types": "off",
2224
"react/jsx-filename-extension": [
2325
"warn",
2426
{

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
- [#285](https://github.com/os2display/display-admin-client/pull/285)
8+
- Rewrite screen playlists get to use promises
9+
- Fix save screen and go to list
10+
- Disable eslint for proptypes
11+
- Disable eslint for react in scope
712
- [#284](https://github.com/os2display/display-admin-client/pull/284)
813
- Fixed spacer calculations for previews.
9-
- Added border to preview container.
14+
- Added border to preview container
1015
- [#283](https://github.com/os2display/display-admin-client/pull/283)
1116
- Fixed preview issues.
1217
- [#275](https://github.com/os2display/display-admin-client/pull/275)

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,10 @@ setting are required than what is default.
3232
cp public/example-access-config.json public/access-config.json
3333
```
3434

35-
### Up the containers
35+
### Up the containers and install npm packages
3636

3737
```shell
3838
docker compose up --detach
39-
```
40-
41-
### Install npm packages
42-
43-
```shell
4439
docker compose run --rm node yarn install
4540
```
4641

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
"eslint-plugin-import": "^2.23.4",
9090
"eslint-plugin-jsdoc": "^35.4.3",
9191
"eslint-plugin-jsx-a11y": "^6.4.1",
92-
"eslint-plugin-only-warn": "^1.0.2",
9392
"eslint-plugin-prettier": "3.4.0",
9493
"eslint-plugin-react": "^7.24.0",
9594
"eslint-plugin-react-hooks": "^4.2.0",
Lines changed: 45 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { React, useState, useEffect } from "react";
2-
import PropTypes from "prop-types";
1+
import { useState } from "react";
32
import { useTranslation } from "react-i18next";
43
import { SelectPlaylistColumns } from "../playlist/playlists-columns";
54
import PlaylistsDropdown from "../util/forms/multiselect-dropdown/playlists/playlists-dropdown";
@@ -8,87 +7,48 @@ import FormCheckbox from "../util/forms/form-checkbox";
87
import {
98
useGetV2PlaylistsByIdSlidesQuery,
109
useGetV2PlaylistsQuery,
11-
useGetV2ScreensByIdRegionsAndRegionIdPlaylistsQuery,
1210
} from "../../redux/api/api.generated.ts";
1311
import ScreenGanttChart from "../screen/util/screen-gantt-chart";
1412

1513
/**
1614
* A drag and drop component for playlists.
1715
*
1816
* @param {string} props The props.
19-
* @param {Function} props.handleChange - The callback when something changed
20-
* @param {string} props.name - The id of the form element
21-
* @param {string} props.screenId - The screen id for get request
17+
* @param {Array} props.selectedPlaylists - The selected playlists
18+
* @param {string} props.name - The name
19+
* @param {Function} props.handleChange - The callback when something is added
2220
* @param {string} props.regionId - The region id for get request
2321
* @param {string} props.regionIdForInitializeCallback - The region id to add
2422
* regions to formstateobject.
2523
* @returns {object} A drag and drop component
2624
*/
2725
function PlaylistDragAndDrop({
28-
handleChange,
26+
selectedPlaylists,
2927
name,
30-
screenId,
28+
handleChange,
29+
removeFromList,
3130
regionId,
32-
regionIdForInitializeCallback,
3331
}) {
3432
const { t } = useTranslation("common", {
3533
keyPrefix: "playlist-drag-and-drop",
3634
});
37-
3835
const [searchText, setSearchText] = useState();
39-
const [selectedData, setSelectedData] = useState([]);
40-
const [totalItems, setTotalItems] = useState(0);
4136
const [page, setPage] = useState(1);
4237
const [onlySharedPlaylists, setOnlySharedPlaylists] = useState(false);
43-
const { data: selectedPlaylistsByRegion } =
44-
useGetV2ScreensByIdRegionsAndRegionIdPlaylistsQuery({
45-
id: screenId,
46-
regionId,
47-
page,
48-
itemsPerPage: 10,
49-
});
5038

51-
// Get method
52-
const { data } = useGetV2PlaylistsQuery({
39+
const {
40+
data: {
41+
"hydra:member": playlists = null,
42+
"hydra:totalItems": totalItems = 0,
43+
} = {},
44+
} = useGetV2PlaylistsQuery({
5345
isCampaign: false,
5446
title: searchText,
5547
itemsPerPage: 30,
5648
order: { createdAt: "desc" },
5749
sharedWithMe: onlySharedPlaylists,
5850
});
5951

60-
/**
61-
* @param {object} regionsAndPlaylists This method initializes playlists, so
62-
* the initial formstate object in screen manager is not empty
63-
*/
64-
function callbackToinitializePlaylists(regionsAndPlaylists) {
65-
handleChange({
66-
target: {
67-
id: regionIdForInitializeCallback,
68-
value: regionsAndPlaylists["hydra:member"].map(
69-
({ playlist }) => playlist
70-
),
71-
},
72-
});
73-
}
74-
75-
/** Set loaded data into form state. */
76-
useEffect(() => {
77-
if (selectedPlaylistsByRegion) {
78-
setTotalItems(selectedPlaylistsByRegion["hydra:totalItems"]);
79-
const newPlaylists = selectedPlaylistsByRegion["hydra:member"].map(
80-
({ playlist, weight }) => ({ ...playlist, weight })
81-
);
82-
83-
const selected = [...selectedData, ...newPlaylists].sort(
84-
(a, b) => a.weight - b.weight
85-
);
86-
87-
setSelectedData(selected);
88-
callbackToinitializePlaylists(selectedPlaylistsByRegion);
89-
}
90-
}, [selectedPlaylistsByRegion]);
91-
9252
/**
9353
* Fetches data for the multi component
9454
*
@@ -98,39 +58,6 @@ function PlaylistDragAndDrop({
9858
setSearchText(filter);
9959
};
10060

101-
/**
102-
* Removes playlist from list of playlists, and closes modal.
103-
*
104-
* @param {object} removeItem - Item to remove
105-
*/
106-
const removeFromList = (removeItem) => {
107-
const indexOfItemToRemove = selectedData
108-
.map((item) => {
109-
return item["@id"];
110-
})
111-
.indexOf(removeItem);
112-
const selectedDataCopy = [...selectedData];
113-
selectedDataCopy.splice(indexOfItemToRemove, 1);
114-
setSelectedData(selectedDataCopy);
115-
116-
const target = { value: selectedDataCopy, id: name };
117-
handleChange({ target });
118-
};
119-
120-
/**
121-
* Adds group to list of groups.
122-
*
123-
* @param {object} props - The props.
124-
* @param {object} props.target - The target.
125-
*/
126-
const handleAdd = ({ target }) => {
127-
const { value, id } = target;
128-
setSelectedData(value);
129-
handleChange({
130-
target: { id, value },
131-
});
132-
};
133-
13461
const columns = SelectPlaylistColumns({
13562
handleDelete: removeFromList,
13663
apiCall: useGetV2PlaylistsByIdSlidesQuery,
@@ -140,53 +67,43 @@ function PlaylistDragAndDrop({
14067
infoModalTitle: t("select-playlists-table.info-modal.slides"),
14168
});
14269

70+
if (!playlists) return null;
71+
14372
return (
14473
<>
145-
{data && data["hydra:member"] && (
146-
<>
147-
<FormCheckbox
148-
label={t("show-only-shared")}
149-
onChange={() => {
150-
setOnlySharedPlaylists(!onlySharedPlaylists);
151-
}}
152-
value={onlySharedPlaylists}
153-
name="show-only-shared"
154-
/>
155-
<div className="mb-3">
156-
<PlaylistsDropdown
157-
filterCallback={onFilter}
158-
name={name}
159-
handlePlaylistSelection={handleAdd}
160-
selected={selectedData}
161-
data={data["hydra:member"]}
162-
/>
163-
</div>
164-
{selectedData.length > 0 && (
165-
<DragAndDropTable
166-
columns={columns}
167-
onDropped={handleChange}
168-
name={name}
169-
data={selectedData}
170-
callback={() => setPage(page + 1)}
171-
label={t("more-playlists")}
172-
totalItems={totalItems}
173-
/>
174-
)}
175-
{selectedData?.length > 0 && (
176-
<ScreenGanttChart playlists={selectedData} id={regionId} />
177-
)}
178-
</>
74+
<FormCheckbox
75+
label={t("show-only-shared")}
76+
onChange={() => {
77+
setOnlySharedPlaylists(!onlySharedPlaylists);
78+
}}
79+
value={onlySharedPlaylists}
80+
name="show-only-shared"
81+
/>
82+
<div className="mb-3">
83+
<PlaylistsDropdown
84+
filterCallback={onFilter}
85+
name={name}
86+
handlePlaylistSelection={handleChange}
87+
selected={selectedPlaylists}
88+
data={playlists}
89+
/>
90+
</div>
91+
{selectedPlaylists.length > 0 && (
92+
<DragAndDropTable
93+
columns={columns}
94+
onDropped={handleChange}
95+
name={name}
96+
data={selectedPlaylists}
97+
callback={() => setPage(page + 1)}
98+
label={t("more-playlists")}
99+
totalItems={totalItems}
100+
/>
101+
)}
102+
{selectedPlaylists?.length > 0 && (
103+
<ScreenGanttChart playlists={selectedPlaylists} id={regionId} />
179104
)}
180105
</>
181106
);
182107
}
183108

184-
PlaylistDragAndDrop.propTypes = {
185-
name: PropTypes.string.isRequired,
186-
screenId: PropTypes.string.isRequired,
187-
regionIdForInitializeCallback: PropTypes.string.isRequired,
188-
regionId: PropTypes.string.isRequired,
189-
handleChange: PropTypes.func.isRequired,
190-
};
191-
192109
export default PlaylistDragAndDrop;

0 commit comments

Comments
 (0)