Skip to content

Commit afd4b23

Browse files
author
Sine Jespersen
committed
coding standards
1 parent a80c93a commit afd4b23

File tree

7 files changed

+38
-76
lines changed

7 files changed

+38
-76
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.
77
- [#285](https://github.com/os2display/display-admin-client/pull/285)
88
- Rewrite screen playlists get to use promises
99
- Fix save screen and go to list
10+
- Disable eslint for proptypes
11+
- Disable eslint for react in scope
1012
- [#283](https://github.com/os2display/display-admin-client/pull/283)
1113
- Fixed preview issues.
1214
- [#275](https://github.com/os2display/display-admin-client/pull/275)

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",

src/components/playlist-drag-and-drop/playlist-drag-and-drop.jsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useState } from "react";
2-
import PropTypes from "prop-types";
32
import { useTranslation } from "react-i18next";
43
import { SelectPlaylistColumns } from "../playlist/playlists-columns";
54
import PlaylistsDropdown from "../util/forms/multiselect-dropdown/playlists/playlists-dropdown";
@@ -10,24 +9,23 @@ import {
109
useGetV2PlaylistsQuery,
1110
} from "../../redux/api/api.generated.ts";
1211
import ScreenGanttChart from "../screen/util/screen-gantt-chart";
13-
12+
// eslint-disable-next-line react/prop-types
1413
/**
1514
* A drag and drop component for playlists.
1615
*
1716
* @param {string} props The props.
18-
* @param {Function} props.handleChange - The callback when something changed
19-
* @param {string} props.name - The id of the form element
20-
* @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
2120
* @param {string} props.regionId - The region id for get request
2221
* @param {string} props.regionIdForInitializeCallback - The region id to add
2322
* regions to formstateobject.
2423
* @returns {object} A drag and drop component
2524
*/
2625
function PlaylistDragAndDrop({
27-
handleChange,
2826
selectedPlaylists,
2927
name,
30-
handleAdd,
28+
handleChange,
3129
removeFromList,
3230
regionId,
3331
}) {
@@ -85,7 +83,7 @@ function PlaylistDragAndDrop({
8583
<PlaylistsDropdown
8684
filterCallback={onFilter}
8785
name={name}
88-
handlePlaylistSelection={handleAdd}
86+
handlePlaylistSelection={handleChange}
8987
selected={selectedPlaylists}
9088
data={playlists}
9189
/>
@@ -108,12 +106,4 @@ function PlaylistDragAndDrop({
108106
);
109107
}
110108

111-
PlaylistDragAndDrop.propTypes = {
112-
name: PropTypes.string.isRequired,
113-
screenId: PropTypes.string.isRequired,
114-
regionIdForInitializeCallback: PropTypes.string.isRequired,
115-
regionId: PropTypes.string.isRequired,
116-
handleChange: PropTypes.func.isRequired,
117-
};
118-
119109
export default PlaylistDragAndDrop;

src/components/screen/screen-form.jsx

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { React, useContext, useEffect, useState } from "react";
1+
import { useContext, useEffect, useState } from "react";
22
import { Button, Form, Spinner, Alert, Col, Row } from "react-bootstrap";
33
import { useTranslation } from "react-i18next";
44
import { useNavigate } from "react-router-dom";
5-
import PropTypes from "prop-types";
65
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
76
import { faExpand } from "@fortawesome/free-solid-svg-icons";
87
import ContentBody from "../util/content-body/content-body";
@@ -31,15 +30,15 @@ import { displayError } from "../util/list/toast-component/display-toast";
3130
* @param {object} props The props.
3231
* @param {object} props.screen Screen The screen object to modify in the form.
3332
* @param {Function} props.handleInput HandleInput Handles form input.
34-
* @param {Function} props.handleSubmit HandleSubmit Handles form submit.
3533
* @param {string} props.headerText HeaderText Headline text.
3634
* @param {string} props.groupId The group id.
3735
* @param {boolean} props.isLoading Indicator of whether the form is loading
3836
* @param {string} props.loadingMessage The loading message for the spinner
3937
* @param {object} props.orientationOptions The options for the orientation dropdown
4038
* @param {object} props.resolutionOptions The options for the resolution dropdown
41-
* @param props.handleSubmitWithoutRedirect
42-
* @param props.handleSubmitWithRedirect
39+
* @param {Function} props.handleSubmitWithoutRedirect Handles form submit
40+
* without redirect.
41+
* @param {Function} props.handleSubmitWithRedirect Handles form submit with redirect.
4342
* @returns {object} The screen form.
4443
*/
4544
function ScreenForm({
@@ -87,7 +86,7 @@ function ScreenForm({
8786
/**
8887
* Check if published is set
8988
*
90-
* @param redirect
89+
* @param {boolean} redirect Whether to redirect after submit
9190
*/
9291
const checkInputsHandleSubmit = (redirect) => {
9392
setLayoutError(false);
@@ -416,40 +415,4 @@ function ScreenForm({
416415
);
417416
}
418417

419-
ScreenForm.propTypes = {
420-
screen: PropTypes.shape({
421-
resolution: PropTypes.string,
422-
"@id": PropTypes.string,
423-
description: PropTypes.string,
424-
orientation: PropTypes.string,
425-
enableColorSchemeChange: PropTypes.bool,
426-
layout: PropTypes.string,
427-
location: PropTypes.string,
428-
regions: PropTypes.arrayOf(
429-
PropTypes.shape({
430-
"@id": PropTypes.string,
431-
})
432-
),
433-
screenUser: PropTypes.string,
434-
size: PropTypes.string,
435-
title: PropTypes.string,
436-
status: PropTypes.shape({}),
437-
playlists: PropTypes.arrayOf(
438-
PropTypes.shape({ name: PropTypes.string, id: PropTypes.number })
439-
),
440-
}),
441-
handleInput: PropTypes.func.isRequired,
442-
handleSubmit: PropTypes.func.isRequired,
443-
headerText: PropTypes.string.isRequired,
444-
groupId: PropTypes.string,
445-
isLoading: PropTypes.bool,
446-
loadingMessage: PropTypes.string,
447-
orientationOptions: PropTypes.arrayOf(
448-
PropTypes.shape({ title: PropTypes.string, id: PropTypes.string })
449-
).isRequired,
450-
resolutionOptions: PropTypes.arrayOf(
451-
PropTypes.shape({ title: PropTypes.string, id: PropTypes.string })
452-
).isRequired,
453-
};
454-
455418
export default ScreenForm;

src/components/screen/util/grid-generation-and-select.jsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import PropTypes from "prop-types";
33
import { Tabs, Tab, Alert } from "react-bootstrap";
44
import { createGridArea, createGrid } from "os2display-grid-generator";
55
import { useTranslation } from "react-i18next";
6+
import { useDispatch } from "react-redux";
67
import idFromUrl from "../../util/helpers/id-from-url";
78
import PlaylistDragAndDrop from "../../playlist-drag-and-drop/playlist-drag-and-drop";
8-
import { useDispatch } from "react-redux";
99
import { api } from "../../../redux/api/api.generated.ts";
1010
import "./grid.scss";
1111

@@ -40,16 +40,17 @@ function GridGenerationAndSelect({
4040
};
4141

4242
/**
43-
* @param root0
44-
* @param root0.value
45-
* @param root0.id
43+
* @param {object} props The props
44+
* @param {Array} props.value The value
45+
* @param {string} props.id The id
46+
* @returns {Array} Mapped data
4647
*/
47-
function mapData({ value, id }) {
48+
function mapData({ value: inputPlaylists, id }) {
4849
// Map to add region id to incoming data.
49-
const localTarget = value.map((value) => {
50+
const localTarget = inputPlaylists.map((playlist) => {
5051
return {
5152
region: idFromUrl(id),
52-
...value,
53+
...playlist,
5354
};
5455
});
5556
// A copy, to be able to remove items.
@@ -63,7 +64,7 @@ function GridGenerationAndSelect({
6364
const selectedWithoutRegion = [];
6465

6566
// Checks if an element has been removed from the list
66-
if (value.length < regionPlaylists.length) {
67+
if (inputPlaylists.length < regionPlaylists.length) {
6768
selectedPlaylists.forEach((playlist) => {
6869
if (!regionPlaylists.includes(playlist.region)) {
6970
selectedWithoutRegion.push(playlist);
@@ -78,10 +79,12 @@ function GridGenerationAndSelect({
7879
...localTarget,
7980
...selectedPlaylistsCopy,
8081
].filter(
81-
(value, index, self) =>
82+
(playlist, index, self) =>
8283
index ===
8384
self.findIndex(
84-
(t) => t["@id"] === value["@id"] && t.region === value.region
85+
(secondPlaylist) =>
86+
secondPlaylist["@id"] === playlist["@id"] &&
87+
secondPlaylist.region === playlist.region
8588
)
8689
);
8790

@@ -151,14 +154,17 @@ function GridGenerationAndSelect({
151154
/**
152155
* Removes playlist from list of playlists, and closes modal.
153156
*
154-
* @param {object} inputPlaylist - inputPlaylist to remove
155-
* @param {object} inputRegion - inputRegion to remove from
157+
* @param {object} inputPlaylist - InputPlaylist to remove
158+
* @param {object} inputRegion - InputRegion to remove from
156159
*/
157160
const removeFromList = (inputPlaylist, inputRegion) => {
158-
const indexOfItemToRemove =selectedPlaylists.findIndex(({"@id": id, region}) => { return region === inputRegion && id === inputPlaylist });
161+
const indexOfItemToRemove = selectedPlaylists.findIndex(
162+
({ "@id": id, region }) => {
163+
return region === inputRegion && id === inputPlaylist;
164+
}
165+
);
159166
const selectedPlaylistsCopy = [...selectedPlaylists];
160167
selectedPlaylistsCopy.splice(indexOfItemToRemove, 1);
161-
console.log(selectedPlaylistsCopy,"selectedPlaylistsCopy")
162168
setSelectedPlaylists(selectedPlaylistsCopy);
163169
};
164170

@@ -201,7 +207,7 @@ function GridGenerationAndSelect({
201207
>
202208
<PlaylistDragAndDrop
203209
id="playlist_drag_and_drop"
204-
handleAdd={handleChange}
210+
handleChange={handleChange}
205211
removeFromList={removeFromList}
206212
name={data["@id"]}
207213
regionIdForInitializeCallback={data["@id"]}

src/components/util/select-column-hoc.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function SelectColumnHoc(columns, omitStandardColumns) {
5151
<Button
5252
variant="danger"
5353
className="remove-from-list"
54-
onClick={() => handleDelete(id,region)}
54+
onClick={() => handleDelete(id, region)}
5555
>
5656
{t("delete-button")}
5757
</Button>

0 commit comments

Comments
 (0)