Skip to content

Commit f88aaa9

Browse files
committed
Fix bugs caught by sonar
1 parent c100a02 commit f88aaa9

20 files changed

Lines changed: 63 additions & 73 deletions

Plan/react/dashboard/src/components/cards/server/graphs/CurrentPlayerbaseCard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const CurrentPlayerbaseCardWithData = ({data, title}) => {
1616
<Card.Header>
1717
<h6 className="col-text" style={{width: '100%'}}>
1818
<Fa icon={faUsers}
19-
className="col-players-activity-index"/> {t(title ? title : 'html.label.currentPlayerbase')}
19+
className="col-players-activity-index"/> {t(title || 'html.label.currentPlayerbase')}
2020
</h6>
2121
</Card.Header>
2222
<GroupVisualizer groups={data.activity_pie_series} name={t('html.label.players')}/>

Plan/react/dashboard/src/components/graphs/ServerPie.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const ServerPie = ({colors, series}) => {
5151
},
5252
tooltip: {
5353
formatter: function () {
54-
return '<b>' + this.point.name + ':</b> ' + formatTimeAmount(this.y) + ' (' + this.percentage.toFixed(2) + '%)';
54+
return '<b>' + this.point.name + ':</b> ' + formatTimeAmount(timePreferences, this.y) + ' (' + this.percentage.toFixed(2) + '%)';
5555
}
5656
},
5757
series: [pieSeries]

Plan/react/dashboard/src/components/table/KillsTable.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const SimpleKillsTable = ({kills}) => {
108108
<Scrollable>
109109
<table className={"table mb-0"}>
110110
<tbody>
111-
{kills.length ? kills.map((kill, i) => <KillRow key={i} kill={kill}/>) :
111+
{kills.length ? kills.map(kill => <KillRow key={JSON.stringify(kill)} kill={kill}/>) :
112112
<tr>
113113
<td>{t('html.generic.none')}</td>
114114
<td>-</td>

Plan/react/dashboard/src/components/theme/ColorBox.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
2-
import {getContrastColor} from '../../util/colors';
32
import {Col} from 'react-bootstrap';
43
import {HoverTrigger, useHoverContext} from "../../hooks/interaction/hoverHook.jsx";
54
import {useColorEditContext} from "../../hooks/context/colorEditContextHook.jsx";
65
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
76
import {faPencil, faTrash} from "@fortawesome/free-solid-svg-icons";
7+
import {getContrastColor} from "../../util/Color.js";
88

99
const Contents = ({name, color}) => {
1010
const cssColor = color.startsWith('var(') ? color : `var(--color-${name})`;
@@ -13,7 +13,7 @@ const Contents = ({name, color}) => {
1313
if (name.includes('percent') && name.includes('white')) {
1414
contrastColor = 'var(--color-night-black)'
1515
}
16-
const {hovered} = useHoverContext();
16+
const hovered = useHoverContext();
1717
const {editColor, deleting, deleteColor} = useColorEditContext();
1818

1919
return (

Plan/react/dashboard/src/components/theme/ColorEditForm.jsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
import React, {forwardRef, useEffect, useRef, useState} from 'react';
1+
import React, {forwardRef, useEffect, useRef} from 'react';
22
import {Col, InputGroup, Row} from "react-bootstrap";
33
import {useColorEditContext} from "../../hooks/context/colorEditContextHook.jsx";
44
import {useTranslation} from "react-i18next";
55
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
6-
import {getContrastColor} from "../../util/colors.js";
76
import {faCheck, faExclamationTriangle, faPalette, faPlus, faTrash} from "@fortawesome/free-solid-svg-icons";
87
import ActionButton from "../input/ActionButton.jsx";
98
import DangerButton from "../input/button/DangerButton.jsx";
109
import SecondaryActionButton from "../input/button/SecondaryActionButton.jsx";
1110
import Chrome from "@uiw/react-color-chrome";
1211
import {GithubPlacement} from '@uiw/react-color-github';
1312
import Wheel from "@uiw/react-color-wheel";
14-
import {getColorArrayConverter, getColorConverter} from "../../util/Color.js";
13+
import {getColorArrayConverter, getColorConverter, getContrastColor} from "../../util/Color.js";
1514

1615

1716
const ColorInput = forwardRef(({color, contrastColor, invalid, onChange}, ref) => {
18-
const [focused, setFocused] = useState(true);
1917
const onChangeText = event => {
2018
onChange(event.target.value);
2119
}
@@ -43,8 +41,6 @@ const ColorInput = forwardRef(({color, contrastColor, invalid, onChange}, ref) =
4341
value={color}
4442
aria-invalid={invalid}
4543
onChange={onChangeText}
46-
onFocus={() => setFocused(true)}
47-
onBlur={() => setFocused(false)}
4844
/>
4945
<Row className={"color-selector p-0"}
5046
style={{

Plan/react/dashboard/src/components/theme/ExampleSection.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {TableUseCase} from "./usecase/TableUseCases.jsx";
2222
import {formatLabel} from "./UseCase.jsx";
2323

2424
const findExample = (path, examples) => {
25-
if (!path || !path.length) return undefined;
25+
if (!path?.length) return undefined;
2626
const found = examples[path];
2727
if (found) return found;
2828
return findExample(path.split('.').slice(0, -1).join('.'), examples);

Plan/react/dashboard/src/components/theme/ThemeOption.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useEffect, useRef} from 'react';
2-
import {ThemeContextProvider, useTheme} from "../../hooks/themeHook.jsx";
3-
import {getLocallyStoredThemes, ThemeStorageContextProvider} from "../../hooks/context/themeContextHook.jsx";
2+
import {getLocallyStoredThemes, ThemeContextProvider, useTheme} from "../../hooks/themeHook.jsx";
3+
import {ThemeStorageContextProvider} from "../../hooks/context/themeContextHook.jsx";
44
import {ThemeStyleCss} from "./ThemeStyleCss.jsx";
55
import {Card, Col} from "react-bootstrap";
66
import logo from "../../Flaticon_circle.png";

Plan/react/dashboard/src/components/theme/ThemeStyleCss.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {addToObject, flattenObject} from '../../util/mutator';
2-
import {getContrastColor, nameToCssVariable} from '../../util/colors';
3-
import {getColorConverter} from "../../util/Color.js";
2+
import {nameToCssVariable} from '../../util/colors';
3+
import {getColorConverter, getContrastColor} from "../../util/Color.js";
44
import {useThemeEditContext} from "../../hooks/context/themeEditContextHook.jsx";
55
import {useThemeStorage} from "../../hooks/context/themeContextHook.jsx";
66

Plan/react/dashboard/src/hooks/context/colorEditContextHook.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createContext, useContext, useState} from "react";
1+
import {createContext, useContext, useMemo, useState} from "react";
22
import {hsvToHex, randomHSVColor} from "../../util/colors.js";
33

44
const ColorEditContext = createContext({});
@@ -51,7 +51,8 @@ export const ColorEditContextProvider = ({colors, saveFunction, deleteFunction,
5151

5252
const alreadyExists = previous !== name && !!colors[name];
5353

54-
return (<ColorEditContext.Provider value={{
54+
const sharedState = useMemo(() => {
55+
return {
5556
alreadyExists,
5657
name,
5758
color,
@@ -65,7 +66,9 @@ export const ColorEditContextProvider = ({colors, saveFunction, deleteFunction,
6566
discardEdit,
6667
editNewColor,
6768
deleteColor
68-
}}>
69+
}
70+
}, [alreadyExists, name, color, deleting, open]);
71+
return (<ColorEditContext.Provider value={sharedState}>
6972
{children}
7073
</ColorEditContext.Provider>
7174
)

Plan/react/dashboard/src/hooks/context/minHeightContextHook.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {createContext, useCallback, useContext, useState} from "react";
1+
import React, {createContext, useCallback, useContext, useMemo, useState} from "react";
22

33
const MinHeightContext = createContext();
44

@@ -26,20 +26,22 @@ export const MinHeightProvider = ({children}) => {
2626
setMinHeightRules(rules => {
2727
const existingRule = rules[selector];
2828
const existingHeight = existingRule?.minHeight;
29-
const existingNightMode = existingRule?.nightMode;
3029

3130
// Change the height if:
3231
// - It's taller than existing one
33-
// - or if the height of the currently registered one changed (check if nightMode is same)
32+
// - or if the height of the currently registered one changed
3433
const shouldUpdate = !existingHeight || minHeight > existingHeight;
3534

3635
if (!shouldUpdate) return rules;
3736
return {...rules, [selector]: {minHeight, nightMode, count}};
3837
});
3938
}, []);
4039

40+
const value = useMemo(() => {
41+
return {minHeightRules, registerMinHeight, unregisterMinHeight}
42+
}, [minHeightRules]);
4143
return (
42-
<MinHeightContext.Provider value={{minHeightRules, registerMinHeight, unregisterMinHeight}}>
44+
<MinHeightContext.Provider value={value}>
4345
<style>
4446
{Object.entries(minHeightRules)
4547
.map(([selector, opt]) => `.${selector}{min-height:${opt.minHeight}px;}`)

0 commit comments

Comments
 (0)