2021-06-09 00:59:39 +02:00
|
|
|
import { useState, useEffect, ChangeEvent, FormEvent } from 'react';
|
2021-06-13 23:21:35 +02:00
|
|
|
|
|
|
|
// Redux
|
2021-06-09 00:59:39 +02:00
|
|
|
import { connect } from 'react-redux';
|
2021-08-06 10:36:05 +02:00
|
|
|
import {
|
|
|
|
createNotification,
|
|
|
|
updateConfig,
|
|
|
|
sortApps,
|
2021-09-06 12:24:01 +02:00
|
|
|
sortCategories,
|
2021-08-06 10:36:05 +02:00
|
|
|
} from '../../../store/actions';
|
2021-06-13 23:21:35 +02:00
|
|
|
|
|
|
|
// Typescript
|
2021-08-06 10:36:05 +02:00
|
|
|
import {
|
2021-10-22 13:31:02 +02:00
|
|
|
Config,
|
2021-08-06 10:36:05 +02:00
|
|
|
GlobalState,
|
|
|
|
NewNotification,
|
2021-10-22 13:31:02 +02:00
|
|
|
OtherSettingsForm,
|
2021-08-06 10:36:05 +02:00
|
|
|
} from '../../../interfaces';
|
2021-06-09 00:59:39 +02:00
|
|
|
|
2021-06-13 23:21:35 +02:00
|
|
|
// UI
|
2021-06-09 00:59:39 +02:00
|
|
|
import InputGroup from '../../UI/Forms/InputGroup/InputGroup';
|
|
|
|
import Button from '../../UI/Buttons/Button/Button';
|
2021-10-11 13:03:31 +02:00
|
|
|
import SettingsHeadline from '../../UI/Headlines/SettingsHeadline/SettingsHeadline';
|
2021-06-24 10:54:48 +02:00
|
|
|
|
2021-06-13 23:21:35 +02:00
|
|
|
// Utils
|
2021-10-22 13:31:02 +02:00
|
|
|
import { otherSettingsTemplate, inputHandler } from '../../../utility';
|
2021-06-09 00:59:39 +02:00
|
|
|
|
|
|
|
interface ComponentProps {
|
|
|
|
createNotification: (notification: NewNotification) => void;
|
2021-10-22 13:31:02 +02:00
|
|
|
updateConfig: (formData: OtherSettingsForm) => void;
|
2021-06-18 10:38:05 +02:00
|
|
|
sortApps: () => void;
|
2021-06-18 13:42:55 +02:00
|
|
|
sortCategories: () => void;
|
2021-06-13 23:21:35 +02:00
|
|
|
loading: boolean;
|
2021-10-22 13:31:02 +02:00
|
|
|
config: Config;
|
2021-06-09 00:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const OtherSettings = (props: ComponentProps): JSX.Element => {
|
2021-10-22 13:31:02 +02:00
|
|
|
const { config } = props;
|
|
|
|
|
2021-06-13 23:21:35 +02:00
|
|
|
// Initial state
|
2021-10-22 13:31:02 +02:00
|
|
|
const [formData, setFormData] = useState<OtherSettingsForm>(
|
|
|
|
otherSettingsTemplate
|
|
|
|
);
|
2021-06-09 00:59:39 +02:00
|
|
|
|
2021-06-13 23:21:35 +02:00
|
|
|
// Get config
|
2021-06-09 00:59:39 +02:00
|
|
|
useEffect(() => {
|
2021-06-13 23:21:35 +02:00
|
|
|
setFormData({
|
2021-10-22 13:31:02 +02:00
|
|
|
...config,
|
2021-08-06 10:36:05 +02:00
|
|
|
});
|
2021-06-13 23:21:35 +02:00
|
|
|
}, [props.loading]);
|
|
|
|
|
|
|
|
// Form handler
|
|
|
|
const formSubmitHandler = async (e: FormEvent) => {
|
2021-06-09 00:59:39 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
2021-06-13 23:21:35 +02:00
|
|
|
// Save settings
|
|
|
|
await props.updateConfig(formData);
|
2021-06-09 00:59:39 +02:00
|
|
|
|
2021-06-18 10:38:05 +02:00
|
|
|
// Update local page title
|
2021-06-09 00:59:39 +02:00
|
|
|
document.title = formData.customTitle;
|
2021-06-18 10:38:05 +02:00
|
|
|
|
2021-06-18 13:42:55 +02:00
|
|
|
// Sort apps and categories with new settings
|
2021-06-18 10:38:05 +02:00
|
|
|
props.sortApps();
|
2021-06-18 13:42:55 +02:00
|
|
|
props.sortCategories();
|
2021-08-06 10:36:05 +02:00
|
|
|
};
|
2021-06-09 00:59:39 +02:00
|
|
|
|
2021-06-13 23:21:35 +02:00
|
|
|
// Input handler
|
2021-08-06 10:36:05 +02:00
|
|
|
const inputChangeHandler = (
|
|
|
|
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
|
2021-10-22 13:31:02 +02:00
|
|
|
options?: { isNumber?: boolean; isBool?: boolean }
|
2021-08-06 10:36:05 +02:00
|
|
|
) => {
|
2021-10-22 13:31:02 +02:00
|
|
|
inputHandler<OtherSettingsForm>({
|
|
|
|
e,
|
|
|
|
options,
|
|
|
|
setStateHandler: setFormData,
|
|
|
|
state: formData,
|
2021-08-06 10:36:05 +02:00
|
|
|
});
|
|
|
|
};
|
2021-06-09 00:59:39 +02:00
|
|
|
|
|
|
|
return (
|
2021-09-06 12:24:01 +02:00
|
|
|
<form onSubmit={(e) => formSubmitHandler(e)}>
|
2021-06-24 10:54:48 +02:00
|
|
|
{/* OTHER OPTIONS */}
|
2021-10-11 13:03:31 +02:00
|
|
|
<SettingsHeadline text="Miscellaneous" />
|
2021-06-09 00:59:39 +02:00
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="customTitle">Custom page title</label>
|
2021-06-09 00:59:39 +02:00
|
|
|
<input
|
2021-09-06 12:24:01 +02:00
|
|
|
type="text"
|
|
|
|
id="customTitle"
|
|
|
|
name="customTitle"
|
|
|
|
placeholder="Flame"
|
2021-06-09 00:59:39 +02:00
|
|
|
value={formData.customTitle}
|
2021-09-06 12:24:01 +02:00
|
|
|
onChange={(e) => inputChangeHandler(e)}
|
2021-06-09 00:59:39 +02:00
|
|
|
/>
|
|
|
|
</InputGroup>
|
2021-10-22 15:51:11 +02:00
|
|
|
<InputGroup>
|
|
|
|
<label htmlFor="useAmericanDate">Date formatting</label>
|
|
|
|
<select
|
|
|
|
id="useAmericanDate"
|
|
|
|
name="useAmericanDate"
|
|
|
|
value={formData.useAmericanDate ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
|
|
|
>
|
|
|
|
<option value={1}>Friday, October 22 2021</option>
|
|
|
|
<option value={0}>Friday, 22 October 2021</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
2021-06-24 10:54:48 +02:00
|
|
|
|
|
|
|
{/* BEAHVIOR OPTIONS */}
|
2021-10-11 13:03:31 +02:00
|
|
|
<SettingsHeadline text="App Behavior" />
|
2021-06-09 10:58:45 +02:00
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="pinAppsByDefault">
|
2021-08-06 10:36:05 +02:00
|
|
|
Pin new applications by default
|
|
|
|
</label>
|
2021-06-09 10:58:45 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="pinAppsByDefault"
|
|
|
|
name="pinAppsByDefault"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.pinAppsByDefault ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-06-09 10:58:45 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="pinCategoriesByDefault">
|
2021-08-06 10:36:05 +02:00
|
|
|
Pin new categories by default
|
|
|
|
</label>
|
2021-06-09 10:58:45 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="pinCategoriesByDefault"
|
|
|
|
name="pinCategoriesByDefault"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.pinCategoriesByDefault ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-06-09 10:58:45 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
2021-06-18 10:38:05 +02:00
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="useOrdering">Sorting type</label>
|
2021-06-18 10:38:05 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="useOrdering"
|
|
|
|
name="useOrdering"
|
2021-06-18 10:38:05 +02:00
|
|
|
value={formData.useOrdering}
|
2021-09-06 12:24:01 +02:00
|
|
|
onChange={(e) => inputChangeHandler(e)}
|
2021-06-18 10:38:05 +02:00
|
|
|
>
|
2021-09-06 12:24:01 +02:00
|
|
|
<option value="createdAt">By creation date</option>
|
|
|
|
<option value="name">Alphabetical order</option>
|
|
|
|
<option value="orderId">Custom order</option>
|
2021-06-18 10:38:05 +02:00
|
|
|
</select>
|
|
|
|
</InputGroup>
|
2021-06-25 11:24:29 +02:00
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="appsSameTab">Open applications in the same tab</label>
|
2021-06-25 11:24:29 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="appsSameTab"
|
|
|
|
name="appsSameTab"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.appsSameTab ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-06-25 11:24:29 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="bookmarksSameTab">Open bookmarks in the same tab</label>
|
2021-06-25 11:24:29 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="bookmarksSameTab"
|
|
|
|
name="bookmarksSameTab"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.bookmarksSameTab ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-06-23 14:15:14 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
2021-07-16 11:55:26 +02:00
|
|
|
|
2021-06-24 10:54:48 +02:00
|
|
|
{/* MODULES OPTIONS */}
|
2021-10-11 13:03:31 +02:00
|
|
|
<SettingsHeadline text="Modules" />
|
2021-06-24 10:54:48 +02:00
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="hideHeader">Hide greeting and date</label>
|
2021-06-24 10:54:48 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="hideHeader"
|
|
|
|
name="hideHeader"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.hideHeader ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-06-24 10:54:48 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="hideApps">Hide applications</label>
|
2021-06-24 10:54:48 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="hideApps"
|
|
|
|
name="hideApps"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.hideApps ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-06-24 10:54:48 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="hideCategories">Hide categories</label>
|
2021-06-24 10:54:48 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="hideCategories"
|
|
|
|
name="hideCategories"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.hideCategories ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-06-24 10:54:48 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
2021-08-06 10:36:05 +02:00
|
|
|
|
|
|
|
{/* DOCKER SETTINGS */}
|
2021-10-11 13:03:31 +02:00
|
|
|
<SettingsHeadline text="Docker" />
|
2021-10-06 22:17:43 +02:00
|
|
|
<InputGroup>
|
|
|
|
<label htmlFor="dockerHost">Docker Host</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="dockerHost"
|
|
|
|
name="dockerHost"
|
|
|
|
placeholder="dockerHost:port"
|
|
|
|
value={formData.dockerHost}
|
|
|
|
onChange={(e) => inputChangeHandler(e)}
|
|
|
|
/>
|
|
|
|
</InputGroup>
|
2021-08-04 22:19:35 +02:00
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="dockerApps">Use Docker API</label>
|
2021-08-04 22:19:35 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="dockerApps"
|
|
|
|
name="dockerApps"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.dockerApps ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-08-04 22:19:35 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="unpinStoppedApps">
|
2021-08-06 10:36:05 +02:00
|
|
|
Unpin stopped containers / other apps
|
|
|
|
</label>
|
2021-08-04 22:19:35 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="unpinStoppedApps"
|
|
|
|
name="unpinStoppedApps"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.unpinStoppedApps ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-08-04 22:19:35 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
2021-08-17 10:32:15 +02:00
|
|
|
|
|
|
|
{/* KUBERNETES SETTINGS */}
|
2021-10-11 13:03:31 +02:00
|
|
|
<SettingsHeadline text="Kubernetes" />
|
2021-08-17 10:32:15 +02:00
|
|
|
<InputGroup>
|
2021-09-06 12:24:01 +02:00
|
|
|
<label htmlFor="kubernetesApps">Use Kubernetes Ingress API</label>
|
2021-08-17 10:32:15 +02:00
|
|
|
<select
|
2021-09-06 12:24:01 +02:00
|
|
|
id="kubernetesApps"
|
|
|
|
name="kubernetesApps"
|
2021-10-22 13:31:02 +02:00
|
|
|
value={formData.kubernetesApps ? 1 : 0}
|
|
|
|
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
2021-08-17 10:32:15 +02:00
|
|
|
>
|
|
|
|
<option value={1}>True</option>
|
|
|
|
<option value={0}>False</option>
|
|
|
|
</select>
|
|
|
|
</InputGroup>
|
2021-08-06 10:36:05 +02:00
|
|
|
<Button>Save changes</Button>
|
2021-06-09 00:59:39 +02:00
|
|
|
</form>
|
2021-08-06 10:36:05 +02:00
|
|
|
);
|
|
|
|
};
|
2021-06-09 00:59:39 +02:00
|
|
|
|
2021-06-13 23:21:35 +02:00
|
|
|
const mapStateToProps = (state: GlobalState) => {
|
|
|
|
return {
|
2021-09-06 12:24:01 +02:00
|
|
|
loading: state.config.loading,
|
2021-10-22 13:31:02 +02:00
|
|
|
config: state.config.config,
|
2021-08-06 10:36:05 +02:00
|
|
|
};
|
|
|
|
};
|
2021-06-13 23:21:35 +02:00
|
|
|
|
2021-06-18 13:42:55 +02:00
|
|
|
const actions = {
|
|
|
|
createNotification,
|
|
|
|
updateConfig,
|
|
|
|
sortApps,
|
2021-09-06 12:24:01 +02:00
|
|
|
sortCategories,
|
2021-08-06 10:36:05 +02:00
|
|
|
};
|
2021-06-18 13:42:55 +02:00
|
|
|
|
2021-08-06 10:36:05 +02:00
|
|
|
export default connect(mapStateToProps, actions)(OtherSettings);
|