Unverified Commit e5ab0d80 authored by Martin R. Kraft's avatar Martin R. Kraft Committed by GitHub

MM-10911: Transforms MiB input to config bytes; config bytes to display MiB. (#1331)

* MM-10911: Transforms MiB input to config bytes (and vice versa).

* MM-10911: Defines MEBIBYTE constant.

* MM-10911: Adds test for onConfigLoad.
parent 336123e0
......@@ -22,6 +22,7 @@ import * as DefinitionConstants from './admin_definition_constants';
const FILE_STORAGE_DRIVER_LOCAL = 'local';
const FILE_STORAGE_DRIVER_S3 = 'amazons3';
const MEBIBYTE = Math.pow(1024, 2);
// admin_definitions data structure define the autogenerated admin_console
// section. It defines the structure of the menu based on sections, subsections
......@@ -1396,6 +1397,8 @@ export default {
help_text_default: 'Maximum file size for message attachments in megabytes. Caution: Verify server memory can support your setting choice. Large file sizes increase the risk of server crashes and failed uploads due to network interruptions.',
placeholder: 'admin.image.maxFileSizeExample',
placeholder_default: '50',
onConfigLoad: (configVal) => configVal / MEBIBYTE,
onConfigSave: (displayVal) => displayVal * MEBIBYTE,
},
{
type: Constants.SettingsTypes.TYPE_DROPDOWN,
......
......@@ -59,7 +59,13 @@ export default class SchemaAdminSettings extends AdminSettings {
return;
}
this.setConfigValue(config, setting.key, this.getSettingValue(setting));
let value = this.getSettingValue(setting);
if (setting.onConfigSave) {
value = setting.onConfigSave(value);
}
this.setConfigValue(config, setting.key, value);
});
}
......@@ -76,7 +82,11 @@ export default class SchemaAdminSettings extends AdminSettings {
return;
}
const value = this.getConfigValue(config, setting.key);
let value = this.getConfigValue(config, setting.key);
if (setting.onConfigLoad) {
value = setting.onConfigLoad(value);
}
state[setting.key] = value == null ? setting.default : value;
});
......
......@@ -15,6 +15,7 @@ exports[`components/admin_console/SchemaAdminSettings should match snapshot with
"settinge": "Q6DHXrFLOIS5sOI5JNF4PyDLqWm7vh23",
"settingf": "3xz3r6n7dtbbmgref3yw4zg7sr",
"settingg": 7,
"settingh": 100,
},
}
}
......@@ -227,6 +228,25 @@ exports[`components/admin_console/SchemaAdminSettings should match snapshot with
type="number"
value={7}
/>
<TextSetting
disabled={false}
helpText={
<FormattedMessage
defaultMessage="This is some help text for the number field."
id="help-text-h"
values={Object {}}
/>
}
id="SecondSettings.settingh"
key="Config_text_SecondSettings.settingh"
label="Setting Eight"
maxLength={null}
onChange={[Function]}
placeholder="e.g. some setting"
setByEnv={false}
type="number"
value={10}
/>
<div
className="banner undefined"
key="Config_bool_undefined"
......
......@@ -103,6 +103,19 @@ describe('components/admin_console/SchemaAdminSettings', () => {
placeholder: 'placeholder-g',
placeholder_default: 'e.g. some setting',
},
{
key: 'SecondSettings.settingh',
label: 'label-h',
label_default: 'Setting Eight',
type: 'number',
default: 'setting_default',
help_text: 'help-text-h',
help_text_default: 'This is some help text for the number field.',
placeholder: 'placeholder-h',
placeholder_default: 'e.g. some setting',
onConfigLoad: (configVal) => configVal / 10,
onConfigSave: (displayVal) => displayVal * 10,
},
{
label: 'label-h',
label_default: 'Setting Eight',
......@@ -191,6 +204,7 @@ describe('components/admin_console/SchemaAdminSettings', () => {
settinge: 'Q6DHXrFLOIS5sOI5JNF4PyDLqWm7vh23',
settingf: '3xz3r6n7dtbbmgref3yw4zg7sr',
settingg: 7,
settingh: 100,
},
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment