Skip to content

Commit

Permalink
Try to make testing Settings deterministic and remove warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ocielliottc committed Oct 24, 2024
1 parent e3ae7c5 commit e26b485
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions web-ui/src/components/settings/types/boolean.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { createLabelId } from '../../../helpers/strings.js';
*/
const SettingsBoolean = ({ name, description, value, handleChange }) => {
const labelId = createLabelId(name);

const checked =
typeof(value) === 'boolean' ? value : value.toLowerCase() == "true";
return (
<div className="settings-type">
<label htmlFor={labelId}>
Expand All @@ -28,7 +29,7 @@ const SettingsBoolean = ({ name, description, value, handleChange }) => {
id={labelId}
className="settings-control"
type="checkbox"
checked={value}
checked={checked}
onChange={handleChange}
/>
</div>
Expand Down
15 changes: 12 additions & 3 deletions web-ui/src/pages/SettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ const SettingsPage = () => {
if (allOptions) {
// Sort the options by category, store them, and upate the state.
setSettingsControls(
allOptions.sort((l, r) => l.category.localeCompare(r.category)));
allOptions.sort((l, r) => {
if (l.category === r.category) {
return l.name.localeCompare(r.name);
} else {
return l.category.localeCompare(r.category);
}
})
);
}
};
if (csrf) {
Expand Down Expand Up @@ -124,7 +131,7 @@ const SettingsPage = () => {
for(let key of Object.keys(handlers)) {
const setting = handlers[key].setting;
// The settings controller does not allow blank values.
if (setting && setting.value) {
if (setting?.name && `${setting.value}` != "") {
let res;
if (setting.id) {
res = await putOption({ name: setting.name,
Expand All @@ -133,7 +140,7 @@ const SettingsPage = () => {
res = await postOption({ name: setting.name,
value: setting.value }, csrf);
if (res?.payload?.data) {
setting.exists = true;
setting.id = res.payload.data.id;
}
}
if (res?.error) {
Expand All @@ -147,6 +154,8 @@ const SettingsPage = () => {
if (res?.payload?.data) {
saved++;
}
} else {
console.warn(`WARNING: ${setting.name} not sent to the server`);
}
}

Expand Down

0 comments on commit e26b485

Please sign in to comment.