Skip to content

Commit e26b485

Browse files
committed
Try to make testing Settings deterministic and remove warnings.
1 parent e3ae7c5 commit e26b485

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

web-ui/src/components/settings/types/boolean.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { createLabelId } from '../../../helpers/strings.js';
1515
*/
1616
const SettingsBoolean = ({ name, description, value, handleChange }) => {
1717
const labelId = createLabelId(name);
18-
18+
const checked =
19+
typeof(value) === 'boolean' ? value : value.toLowerCase() == "true";
1920
return (
2021
<div className="settings-type">
2122
<label htmlFor={labelId}>
@@ -28,7 +29,7 @@ const SettingsBoolean = ({ name, description, value, handleChange }) => {
2829
id={labelId}
2930
className="settings-control"
3031
type="checkbox"
31-
checked={value}
32+
checked={checked}
3233
onChange={handleChange}
3334
/>
3435
</div>

web-ui/src/pages/SettingsPage.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ const SettingsPage = () => {
4646
if (allOptions) {
4747
// Sort the options by category, store them, and upate the state.
4848
setSettingsControls(
49-
allOptions.sort((l, r) => l.category.localeCompare(r.category)));
49+
allOptions.sort((l, r) => {
50+
if (l.category === r.category) {
51+
return l.name.localeCompare(r.name);
52+
} else {
53+
return l.category.localeCompare(r.category);
54+
}
55+
})
56+
);
5057
}
5158
};
5259
if (csrf) {
@@ -124,7 +131,7 @@ const SettingsPage = () => {
124131
for(let key of Object.keys(handlers)) {
125132
const setting = handlers[key].setting;
126133
// The settings controller does not allow blank values.
127-
if (setting && setting.value) {
134+
if (setting?.name && `${setting.value}` != "") {
128135
let res;
129136
if (setting.id) {
130137
res = await putOption({ name: setting.name,
@@ -133,7 +140,7 @@ const SettingsPage = () => {
133140
res = await postOption({ name: setting.name,
134141
value: setting.value }, csrf);
135142
if (res?.payload?.data) {
136-
setting.exists = true;
143+
setting.id = res.payload.data.id;
137144
}
138145
}
139146
if (res?.error) {
@@ -147,6 +154,8 @@ const SettingsPage = () => {
147154
if (res?.payload?.data) {
148155
saved++;
149156
}
157+
} else {
158+
console.warn(`WARNING: ${setting.name} not sent to the server`);
150159
}
151160
}
152161

0 commit comments

Comments
 (0)