Update config editor (#37)
* Update config-editor.tsx * Fix minor grammar error * Fix minor grammar error --------- Co-authored-by: Kas-tle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
1 parent
6926df9337
commit
97dd0dab0a
1 file changed
+52
-13
@@ -53,7 +53,9 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
let currentSection = '';
|
let currentSection = '';
|
||||||
let currentComment = '';
|
let currentComment = '';
|
||||||
|
|
||||||
const newConfig = {};
|
const newConfig = {"": {}};
|
||||||
|
|
||||||
|
let ignore = false;
|
||||||
|
|
||||||
// Parse each line of the config
|
// Parse each line of the config
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
@@ -72,7 +74,7 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
|
|
||||||
const commented = line.startsWith('#');
|
const commented = line.startsWith('#');
|
||||||
|
|
||||||
const match = line.match(keyReg)
|
const match = line.match(keyReg);
|
||||||
if (match === null) {
|
if (match === null) {
|
||||||
// Check if we are in a comment
|
// Check if we are in a comment
|
||||||
if (commented) {
|
if (commented) {
|
||||||
@@ -84,12 +86,26 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
// Check if we are in a new section
|
// Check if we are in a new section
|
||||||
if (line.endsWith(':')) {
|
if (line.endsWith(':')) {
|
||||||
currentSection = line.replace(':', '');
|
currentSection = line.replace(':', '');
|
||||||
|
|
||||||
|
// Ignore user auths section
|
||||||
|
if (currentSection === 'saved-user-logins') {
|
||||||
|
ignore = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ignore = false;
|
||||||
|
if (commented) {
|
||||||
|
currentComment += '<strong>Note: This option is commented out by default. It will be automatically uncommented if modified.</strong>' + '<br>';
|
||||||
|
}
|
||||||
|
|
||||||
|
currentComment = currentComment.replace(URL_REGEX, function ($0) {
|
||||||
|
return '<a href="' + $0 + '">' + $0 + '</a>';
|
||||||
|
})
|
||||||
|
newConfig[currentSection] = {sectionDesc0: currentComment};
|
||||||
currentComment = '';
|
currentComment = '';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore user auths section
|
if (ignore) {
|
||||||
if (currentSection === 'saved-user-logins') {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,11 +124,14 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (commented) {
|
if (commented) {
|
||||||
currentComment += '<strong>Note: This option is commented on, and if you change it, it will be automatically uncommented.</strong>' + '<br>';
|
currentComment += '<strong>Note: This option is commented out by default. It will be automatically uncommented if modified.</strong>' + '<br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentComment = currentComment.replace(URL_REGEX, function ($0) {
|
||||||
|
return '<a href="' + $0 + '">' + $0 + '</a>';
|
||||||
|
})
|
||||||
|
|
||||||
// Add the config option to the config object
|
// Add the config option to the config object
|
||||||
newConfig[currentSection] = newConfig[currentSection] || {};
|
|
||||||
newConfig[currentSection][splitLine[0]] = {
|
newConfig[currentSection][splitLine[0]] = {
|
||||||
desc: currentComment,
|
desc: currentComment,
|
||||||
value: val,
|
value: val,
|
||||||
@@ -132,6 +151,16 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
<div className={styles.cardBody}>
|
<div className={styles.cardBody}>
|
||||||
{Object.keys(config[configKey]).map(configOption => {
|
{Object.keys(config[configKey]).map(configOption => {
|
||||||
const configOptionInfo = config[configKey][configOption];
|
const configOptionInfo = config[configKey][configOption];
|
||||||
|
if (configOption == "sectionDesc0") {
|
||||||
|
if (configOptionInfo === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className={styles.configOption}>
|
||||||
|
<p dangerouslySetInnerHTML={{__html: configOptionInfo}}/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
const configOptionKey = configKey === '' ? configOption : `${configKey}.${configOption}`;
|
const configOptionKey = configKey === '' ? configOption : `${configKey}.${configOption}`;
|
||||||
const showOptionName = configOption.replace('#', '').trim()
|
const showOptionName = configOption.replace('#', '').trim()
|
||||||
return (
|
return (
|
||||||
@@ -147,6 +176,8 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const URL_REGEX = /https?:\/\/(([0-9a-z.]+\.[a-z]+)|(([0-9]{1,3}\.){3}[0-9]{1,3}))(:[0-9]+)?(\/[0-9a-z%\/.\-_]*)?(\?[0-9a-z=&%_\-]*)?(#[0-9a-z=&%_\-]*)?/ig;
|
||||||
|
|
||||||
const handleExport = () => {
|
const handleExport = () => {
|
||||||
let newConfig = config;
|
let newConfig = config;
|
||||||
const lines = newConfig.split('\n');
|
const lines = newConfig.split('\n');
|
||||||
@@ -188,7 +219,8 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
// Handle all the dropdowns
|
// Handle all the dropdowns
|
||||||
case 'remote.auth-type':
|
case 'remote.auth-type':
|
||||||
return (
|
return (
|
||||||
<select key={name} className={styles.formInput} id={name} defaultValue={value} onChange={handleChange}>
|
<select key={name} className={styles.formInput} id={name} defaultValue={value}
|
||||||
|
onChange={handleChange}>
|
||||||
<option value='offline'>offline</option>
|
<option value='offline'>offline</option>
|
||||||
<option value='online'>online</option>
|
<option value='online'>online</option>
|
||||||
<option value='floodgate'>floodgate</option>
|
<option value='floodgate'>floodgate</option>
|
||||||
@@ -196,7 +228,8 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
);
|
);
|
||||||
case 'show-cooldown':
|
case 'show-cooldown':
|
||||||
return (
|
return (
|
||||||
<select key={name} className={styles.formInput} id={name} defaultValue={value} onChange={handleChange}>
|
<select key={name} className={styles.formInput} id={name} defaultValue={value}
|
||||||
|
onChange={handleChange}>
|
||||||
<option value='title'>title</option>
|
<option value='title'>title</option>
|
||||||
<option value='actionbar'>actionbar</option>
|
<option value='actionbar'>actionbar</option>
|
||||||
<option value='false'>false</option>
|
<option value='false'>false</option>
|
||||||
@@ -204,16 +237,19 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
);
|
);
|
||||||
case 'emote-offhand-workaround':
|
case 'emote-offhand-workaround':
|
||||||
return (
|
return (
|
||||||
<select key={name} className={styles.formInput} id={name} defaultValue={value} onChange={handleChange}>
|
<select key={name} className={styles.formInput} id={name} defaultValue={value}
|
||||||
|
onChange={handleChange}>
|
||||||
<option value='disabled'>disabled</option>
|
<option value='disabled'>disabled</option>
|
||||||
<option value='no-emotes'>no-emotes</option>
|
<option value='no-emotes'>no-emotes</option>
|
||||||
<option value='emotes-and-offhand'>emotes-and-offhand</option>
|
<option value='emotes-and-offhand'>emotes-and-offhand</option>
|
||||||
</select>
|
</select>
|
||||||
);
|
);
|
||||||
case 'config-version':
|
case 'config-version':
|
||||||
return <input key={name} className={styles.formInput} type='text' disabled defaultValue={value.replace(/"/g, '')} />;
|
return <input key={name} className={styles.formInput} type='text' disabled
|
||||||
|
defaultValue={value.replace(/"/g, '')}/>;
|
||||||
case 'metrics.uuid':
|
case 'metrics.uuid':
|
||||||
return <input key={name} className={styles.formInput} id={name} type='text' disabled defaultValue={value === 'generateduuid' ? crypto.randomUUID() : value} />;
|
return <input key={name} className={styles.formInput} id={name} type='text' disabled
|
||||||
|
defaultValue={value === 'generateduuid' ? crypto.randomUUID() : value}/>;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Handle all the other inputs
|
// Handle all the other inputs
|
||||||
@@ -251,13 +287,16 @@ const ConfigEditorPage: React.FC = () => {
|
|||||||
a.click()
|
a.click()
|
||||||
document.body.removeChild(a)
|
document.body.removeChild(a)
|
||||||
|
|
||||||
setTimeout(() => { URL.revokeObjectURL(a.href) }, 1500)
|
setTimeout(() => {
|
||||||
|
URL.revokeObjectURL(a.href)
|
||||||
|
}, 1500)
|
||||||
}
|
}
|
||||||
|
|
||||||
const NoConfigSection = () => (
|
const NoConfigSection = () => (
|
||||||
<>
|
<>
|
||||||
<h1><Translate id='pages.configeditor.noconfigselected.heading'>No config selected.</Translate></h1>
|
<h1><Translate id='pages.configeditor.noconfigselected.heading'>No config selected.</Translate></h1>
|
||||||
<h3 className={styles.fontNormal}><Translate id='pages.configeditor.noconfigselected.subheading'>Upload a file or get started with the default config!</Translate></h3>
|
<h3 className={styles.fontNormal}><Translate id='pages.configeditor.noconfigselected.subheading'>Upload a
|
||||||
|
file or get started with the default config!</Translate></h3>
|
||||||
|
|
||||||
<div className={styles.buttonsContainer}>
|
<div className={styles.buttonsContainer}>
|
||||||
<button className={styles.button} onClick={loadDefault}>
|
<button className={styles.button} onClick={loadDefault}>
|
||||||
|
|||||||
Reference in new issue
Block a user