diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupCollapseConfiguration.js b/ui/src/Components/MainModal/Configuration/AlertGroupCollapseConfiguration.js
index 4c743a187..40feaf823 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupCollapseConfiguration.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupCollapseConfiguration.js
@@ -1,76 +1,54 @@
-import React, { Component } from "react";
+import React from "react";
import PropTypes from "prop-types";
-import { action } from "mobx";
-import { observer } from "mobx-react";
+import { useObserver } from "mobx-react";
import Select from "react-select";
import { Settings } from "Stores/Settings";
import { ThemeContext } from "Components/Theme";
-const AlertGroupCollapseConfiguration = observer(
- class AlertGroupCollapseConfiguration extends Component {
- static propTypes = {
- settingsStore: PropTypes.instanceOf(Settings).isRequired,
- };
- static contextType = ThemeContext;
-
- constructor(props) {
- super(props);
-
- this.validateConfig();
- }
-
- valueToOption = (val) => {
- const { settingsStore } = this.props;
-
- return {
- label: settingsStore.alertGroupConfig.options[val].label,
- value: val,
- };
- };
-
- validateConfig = action(() => {
- const { settingsStore } = this.props;
-
- if (
- !Object.values(settingsStore.alertGroupConfig.options)
- .map((o) => o.value)
- .includes(settingsStore.alertGroupConfig.config.defaultCollapseState)
- ) {
- settingsStore.alertGroupConfig.config.defaultCollapseState =
- settingsStore.alertGroupConfig.options.collapsedOnMobile.value;
- }
- });
-
- onCollapseChange = action((newValue, actionMeta) => {
- const { settingsStore } = this.props;
-
- settingsStore.alertGroupConfig.config.defaultCollapseState =
- newValue.value;
- });
-
- render() {
- const { settingsStore } = this.props;
-
- return (
-
-
-
- );
- }
+const AlertGroupCollapseConfiguration = ({ settingsStore }) => {
+ if (
+ !Object.values(settingsStore.alertGroupConfig.options)
+ .map((o) => o.value)
+ .includes(settingsStore.alertGroupConfig.config.defaultCollapseState)
+ ) {
+ settingsStore.alertGroupConfig.config.defaultCollapseState =
+ settingsStore.alertGroupConfig.options.collapsedOnMobile.value;
}
-);
+
+ const valueToOption = (val) => {
+ return {
+ label: settingsStore.alertGroupConfig.options[val].label,
+ value: val,
+ };
+ };
+
+ const onCollapseChange = (newValue, actionMeta) => {
+ settingsStore.alertGroupConfig.config.defaultCollapseState = newValue.value;
+ };
+
+ const context = React.useContext(ThemeContext);
+
+ return useObserver(() => (
+
+
+
+ ));
+};
+AlertGroupCollapseConfiguration.propTypes = {
+ settingsStore: PropTypes.instanceOf(Settings).isRequired,
+};
export { AlertGroupCollapseConfiguration };
diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupCollapseConfiguration.test.js b/ui/src/Components/MainModal/Configuration/AlertGroupCollapseConfiguration.test.js
index 0c0dae5b1..93d78c991 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupCollapseConfiguration.test.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupCollapseConfiguration.test.js
@@ -4,28 +4,23 @@ import { mount } from "enzyme";
import toDiffableHtml from "diffable-html";
+import { MockThemeContext } from "__mocks__/Theme";
import { Settings } from "Stores/Settings";
-import { ThemeContext } from "Components/Theme";
-import {
- ReactSelectColors,
- ReactSelectStyles,
-} from "Components/Theme/ReactSelect";
import { AlertGroupCollapseConfiguration } from "./AlertGroupCollapseConfiguration";
let settingsStore;
+
+beforeAll(() => {
+ jest.spyOn(React, "useContext").mockImplementation(() => MockThemeContext);
+});
+
beforeEach(() => {
settingsStore = new Settings();
});
const FakeConfiguration = () => {
return mount(
-
-
-
+
);
};
diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupConfiguration.js b/ui/src/Components/MainModal/Configuration/AlertGroupConfiguration.js
index 09261eff4..a871da35a 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupConfiguration.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupConfiguration.js
@@ -1,56 +1,41 @@
-import React, { Component } from "react";
+import React from "react";
import PropTypes from "prop-types";
-import { observable, action, toJS } from "mobx";
-import { observer } from "mobx-react";
+import { useObserver, useLocalStore } from "mobx-react";
import InputRange from "react-input-range";
import { Settings } from "Stores/Settings";
-const AlertGroupConfiguration = observer(
- class AlertGroupConfiguration extends Component {
- static propTypes = {
- settingsStore: PropTypes.instanceOf(Settings).isRequired,
- };
+const AlertGroupConfiguration = ({ settingsStore }) => {
+ const config = useLocalStore(() => ({
+ defaultRenderCount:
+ settingsStore.alertGroupConfig.config.defaultRenderCount,
+ setDefaultRenderCount(val) {
+ this.defaultRenderCount = val;
+ },
+ }));
- constructor(props) {
- super(props);
+ const onChangeComplete = (value) => {
+ settingsStore.alertGroupConfig.update({ defaultRenderCount: value });
+ };
- this.config = observable({
- defaultRenderCount: toJS(
- props.settingsStore.alertGroupConfig.config.defaultRenderCount
- ),
- });
- }
-
- onChange = action((value) => {
- this.config.defaultRenderCount = value;
- });
-
- onChangeComplete = action((value) => {
- const { settingsStore } = this.props;
-
- settingsStore.alertGroupConfig.update({ defaultRenderCount: value });
- });
-
- render() {
- return (
-
-
-
- );
- }
- }
-);
+ return useObserver(() => (
+
+
+
+ ));
+};
+AlertGroupConfiguration.propTypes = {
+ settingsStore: PropTypes.instanceOf(Settings).isRequired,
+};
export { AlertGroupConfiguration };
diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupConfiguration.test.js b/ui/src/Components/MainModal/Configuration/AlertGroupConfiguration.test.js
index cd9832529..c65eb02b9 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupConfiguration.test.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupConfiguration.test.js
@@ -8,6 +8,7 @@ import { Settings } from "Stores/Settings";
import { AlertGroupConfiguration } from "./AlertGroupConfiguration";
let settingsStore;
+
beforeEach(() => {
settingsStore = new Settings();
});
@@ -22,16 +23,22 @@ describe("", () => {
expect(toDiffableHtml(tree.html())).toMatchSnapshot();
});
- it("call to onChange() updates internal state", () => {
- const tree = FakeConfiguration();
- tree.instance().onChange(9);
- expect(tree.instance().config.defaultRenderCount).toBe(9);
- });
-
it("settings are updated on completed change", () => {
const tree = FakeConfiguration();
- tree.instance().onChangeComplete(8);
- expect(settingsStore.alertGroupConfig.config.defaultRenderCount).toBe(8);
+ expect(settingsStore.alertGroupConfig.config.defaultRenderCount).toBe(5);
+
+ const slider = tree.find(`Slider [onKeyDown]`).first();
+
+ slider.simulate("keyDown", { keyCode: 37 });
+ slider.simulate("keyUp", { keyCode: 37 });
+
+ expect(settingsStore.alertGroupConfig.config.defaultRenderCount).toBe(4);
+
+ slider.simulate("keyDown", { keyCode: 39 });
+ slider.simulate("keyUp", { keyCode: 39 });
+ slider.simulate("keyDown", { keyCode: 39 });
+ slider.simulate("keyUp", { keyCode: 39 });
+ expect(settingsStore.alertGroupConfig.config.defaultRenderCount).toBe(6);
});
it("custom interval value is rendered correctly", () => {
diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupSortConfiguration.js b/ui/src/Components/MainModal/Configuration/AlertGroupSortConfiguration.js
index dbc92eab0..9aa786a2d 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupSortConfiguration.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupSortConfiguration.js
@@ -1,8 +1,7 @@
-import React, { Component } from "react";
+import React from "react";
import PropTypes from "prop-types";
-import { action } from "mobx";
-import { observer } from "mobx-react";
+import { useObserver } from "mobx-react";
import Select from "react-select";
@@ -10,108 +9,84 @@ import { Settings } from "Stores/Settings";
import { ThemeContext } from "Components/Theme";
import { SortLabelName } from "./SortLabelName";
-const AlertGroupSortConfiguration = observer(
- class AlertGroupSortConfiguration extends Component {
- static propTypes = {
- settingsStore: PropTypes.instanceOf(Settings).isRequired,
- };
- static contextType = ThemeContext;
-
- constructor(props) {
- super(props);
-
- this.validateConfig();
- }
-
- onSortOrderChange = action((newValue, actionMeta) => {
- const { settingsStore } = this.props;
-
- settingsStore.gridConfig.config.sortOrder = newValue.value;
- });
-
- onSortReverseChange = action((event) => {
- const { settingsStore } = this.props;
-
- settingsStore.gridConfig.config.reverseSort = event.target.checked;
- });
-
- valueToOption = (val) => {
- const { settingsStore } = this.props;
-
- return { label: settingsStore.gridConfig.options[val].label, value: val };
- };
-
- validateConfig = action(() => {
- const { settingsStore } = this.props;
-
- if (
- !Object.values(settingsStore.gridConfig.options)
- .map((o) => o.value)
- .includes(settingsStore.gridConfig.config.sortOrder)
- ) {
- settingsStore.gridConfig.config.sortOrder =
- settingsStore.gridConfig.options.default.value;
- }
- });
-
- render() {
- const { settingsStore } = this.props;
-
- const hideReverse =
- settingsStore.gridConfig.config.sortOrder ===
- settingsStore.gridConfig.options.default.value ||
- settingsStore.gridConfig.config.sortOrder ===
- settingsStore.gridConfig.options.disabled.value;
-
- return (
-
-
-
-
-
- {settingsStore.gridConfig.config.sortOrder ===
- settingsStore.gridConfig.options.label.value ? (
-
-
-
- ) : null}
- {hideReverse ? null : (
-
-
-
-
-
-
- )}
-
-
- );
- }
+const AlertGroupSortConfiguration = ({ settingsStore }) => {
+ if (
+ !Object.values(settingsStore.gridConfig.options)
+ .map((o) => o.value)
+ .includes(settingsStore.gridConfig.config.sortOrder)
+ ) {
+ settingsStore.gridConfig.config.sortOrder =
+ settingsStore.gridConfig.options.default.value;
}
-);
+
+ const onSortOrderChange = (newValue, actionMeta) => {
+ settingsStore.gridConfig.config.sortOrder = newValue.value;
+ };
+
+ const onSortReverseChange = (event) => {
+ settingsStore.gridConfig.config.reverseSort = event.target.checked;
+ };
+
+ const valueToOption = (val) => {
+ return { label: settingsStore.gridConfig.options[val].label, value: val };
+ };
+
+ const hideReverse =
+ settingsStore.gridConfig.config.sortOrder ===
+ settingsStore.gridConfig.options.default.value ||
+ settingsStore.gridConfig.config.sortOrder ===
+ settingsStore.gridConfig.options.disabled.value;
+
+ const context = React.useContext(ThemeContext);
+
+ return useObserver(() => (
+
+
+
+
+
+ {settingsStore.gridConfig.config.sortOrder ===
+ settingsStore.gridConfig.options.label.value ? (
+
+
+
+ ) : null}
+ {hideReverse ? null : (
+
+
+
+
+
+
+ )}
+
+
+ ));
+};
+AlertGroupSortConfiguration.propTypes = {
+ settingsStore: PropTypes.instanceOf(Settings).isRequired,
+};
export { AlertGroupSortConfiguration };
diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupSortConfiguration.test.js b/ui/src/Components/MainModal/Configuration/AlertGroupSortConfiguration.test.js
index 8db7b864c..5412229f9 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupSortConfiguration.test.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupSortConfiguration.test.js
@@ -75,10 +75,12 @@ describe("", () => {
settingsStore.gridConfig.options.label.value
);
const tree = FakeConfiguration();
- tree.instance().onSortOrderChange({
- label: settingsStore.gridConfig.options.startsAt.label,
- value: settingsStore.gridConfig.options.startsAt.value,
- });
+
+ tree
+ .find("input#react-select-configuration-sort-order-input")
+ .simulate("change", { target: { value: " " } });
+ tree.find("div.react-select__option").at(2).simulate("click");
+
setTimeout(() => {
expect(settingsStore.gridConfig.config.sortOrder).toBe(
settingsStore.gridConfig.options.startsAt.value
diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupTitleBarColor.js b/ui/src/Components/MainModal/Configuration/AlertGroupTitleBarColor.js
index 13a58f1e4..e5018587d 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupTitleBarColor.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupTitleBarColor.js
@@ -1,52 +1,42 @@
-import React, { Component } from "react";
+import React from "react";
import PropTypes from "prop-types";
-import { action } from "mobx";
-import { observer } from "mobx-react";
+import { useObserver } from "mobx-react";
import { Settings } from "Stores/Settings";
-const AlertGroupTitleBarColor = observer(
- class AlertGroupTitleBarColor extends Component {
- static propTypes = {
- settingsStore: PropTypes.instanceOf(Settings).isRequired,
- };
+const AlertGroupTitleBarColor = ({ settingsStore }) => {
+ const onChange = (event) => {
+ settingsStore.alertGroupConfig.config.colorTitleBar = event.target.checked;
+ };
- onChange = action((event) => {
- const { settingsStore } = this.props;
- settingsStore.alertGroupConfig.config.colorTitleBar =
- event.target.checked;
- });
-
- render() {
- const { settingsStore } = this.props;
-
- return (
-
-
-
-
-
-
-
-
- );
- }
- }
-);
+ return useObserver(() => (
+
+
+
+
+
+
+
+
+ ));
+};
+AlertGroupTitleBarColor.propTypes = {
+ settingsStore: PropTypes.instanceOf(Settings).isRequired,
+};
export { AlertGroupTitleBarColor };
diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.js b/ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.js
index de73e0aed..179579769 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.js
@@ -1,8 +1,7 @@
-import React, { Component } from "react";
+import React from "react";
import PropTypes from "prop-types";
-import { observable, action, toJS } from "mobx";
-import { observer } from "mobx-react";
+import { useObserver, useLocalStore } from "mobx-react";
import debounce from "lodash/debounce";
@@ -10,50 +9,34 @@ import InputRange from "react-input-range";
import { Settings } from "Stores/Settings";
-const AlertGroupWidthConfiguration = observer(
- class AlertGroupWidthConfiguration extends Component {
- static propTypes = {
- settingsStore: PropTypes.instanceOf(Settings).isRequired,
- };
+const AlertGroupWidthConfiguration = ({ settingsStore }) => {
+ const config = useLocalStore(() => ({
+ groupWidth: settingsStore.gridConfig.config.groupWidth,
+ setGroupWidth(val) {
+ this.groupWidth = val;
+ },
+ }));
- constructor(props) {
- super(props);
+ const onChangeComplete = debounce((value) => {
+ settingsStore.gridConfig.config.groupWidth = value;
+ }, 200);
- this.config = observable({
- groupWidth: toJS(props.settingsStore.gridConfig.config.groupWidth),
- });
- }
-
- onChange = action((value) => {
- this.config.groupWidth = value;
- });
-
- onChangeComplete = debounce(
- action((value) => {
- const { settingsStore } = this.props;
-
- settingsStore.gridConfig.config.groupWidth = value;
- }),
- 200
- );
-
- render() {
- return (
-
-
-
- );
- }
- }
-);
+ return useObserver(() => (
+
+
+
+ ));
+};
+AlertGroupWidthConfiguration.propTypes = {
+ settingsStore: PropTypes.instanceOf(Settings).isRequired,
+};
export { AlertGroupWidthConfiguration };
diff --git a/ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.test.js b/ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.test.js
index a8f85d773..c4a10dce7 100644
--- a/ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.test.js
+++ b/ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.test.js
@@ -22,16 +22,23 @@ describe("", () => {
expect(toDiffableHtml(tree.html())).toMatchSnapshot();
});
- it("call to onChange() updates internal state", () => {
- const tree = FakeConfiguration();
- tree.instance().onChange(500);
- expect(tree.instance().config.groupWidth).toBe(500);
- });
-
it("settings are updated on completed change", () => {
const tree = FakeConfiguration();
- tree.instance().onChangeComplete(555);
- expect(settingsStore.gridConfig.config.groupWidth).toBe(555);
+ expect(settingsStore.gridConfig.config.groupWidth).toBe(420);
+
+ const slider = tree.find(`Slider [onKeyDown]`).first();
+
+ slider.simulate("keyDown", { keyCode: 37 });
+ slider.simulate("keyUp", { keyCode: 37 });
+
+ expect(settingsStore.gridConfig.config.groupWidth).toBe(400);
+
+ slider.simulate("keyDown", { keyCode: 39 });
+ slider.simulate("keyUp", { keyCode: 39 });
+ slider.simulate("keyDown", { keyCode: 39 });
+ slider.simulate("keyUp", { keyCode: 39 });
+
+ expect(settingsStore.gridConfig.config.groupWidth).toBe(440);
});
it("custom interval value is rendered correctly", () => {
diff --git a/ui/src/Components/MainModal/Configuration/FetchConfiguration.js b/ui/src/Components/MainModal/Configuration/FetchConfiguration.js
index 13d375c1d..5730e1e7e 100644
--- a/ui/src/Components/MainModal/Configuration/FetchConfiguration.js
+++ b/ui/src/Components/MainModal/Configuration/FetchConfiguration.js
@@ -1,58 +1,41 @@
-import React, { Component } from "react";
+import React from "react";
import PropTypes from "prop-types";
-import { observable, action, toJS } from "mobx";
-import { observer } from "mobx-react";
+import { useObserver, useLocalStore } from "mobx-react";
import InputRange from "react-input-range";
import { Settings } from "Stores/Settings";
-const FetchConfiguration = observer(
- class FetchConfiguration extends Component {
- static propTypes = {
- settingsStore: PropTypes.instanceOf(Settings).isRequired,
- };
+const FetchConfiguration = ({ settingsStore }) => {
+ const config = useLocalStore(() => ({
+ fetchInterval: settingsStore.fetchConfig.config.interval,
+ setFetchInterval(val) {
+ this.fetchInterval = val;
+ },
+ }));
- constructor(props) {
- super(props);
+ const onChangeComplete = (value) => {
+ settingsStore.fetchConfig.setInterval(value);
+ };
- this.config = observable({
- fetchInterval: toJS(props.settingsStore.fetchConfig.config.interval),
- });
- }
-
- onChange = action((value) => {
- this.config.fetchInterval = value;
- });
-
- onChangeComplete = action((value) => {
- const { settingsStore } = this.props;
-
- settingsStore.fetchConfig.setInterval(value);
- });
-
- formatLabel(value) {
- return `${value}s`;
- }
-
- render() {
- return (
-
-
-
- );
- }
- }
-);
+ return useObserver(() => (
+
+ `${value}s`}
+ onChange={config.setFetchInterval}
+ onChangeComplete={onChangeComplete}
+ />
+
+ ));
+};
+FetchConfiguration.propTypes = {
+ settingsStore: PropTypes.instanceOf(Settings).isRequired,
+};
export { FetchConfiguration };
diff --git a/ui/src/Components/MainModal/Configuration/FetchConfiguration.test.js b/ui/src/Components/MainModal/Configuration/FetchConfiguration.test.js
index 9c9d87f03..da6e9331e 100644
--- a/ui/src/Components/MainModal/Configuration/FetchConfiguration.test.js
+++ b/ui/src/Components/MainModal/Configuration/FetchConfiguration.test.js
@@ -22,16 +22,23 @@ describe("", () => {
expect(toDiffableHtml(tree.html())).toMatchSnapshot();
});
- it("call to onChange() updates internal state", () => {
- const tree = FakeConfiguration();
- tree.instance().onChange(55);
- expect(tree.instance().config.fetchInterval).toBe(55);
- });
-
it("settings are updated on completed change", () => {
const tree = FakeConfiguration();
- tree.instance().onChangeComplete(123);
- expect(settingsStore.fetchConfig.config.interval).toBe(123);
+ expect(settingsStore.fetchConfig.config.interval).toBe(30);
+
+ const slider = tree.find(`Slider [onKeyDown]`).first();
+
+ slider.simulate("keyDown", { keyCode: 37 });
+ slider.simulate("keyUp", { keyCode: 37 });
+
+ expect(settingsStore.fetchConfig.config.interval).toBe(20);
+
+ slider.simulate("keyDown", { keyCode: 39 });
+ slider.simulate("keyUp", { keyCode: 39 });
+ slider.simulate("keyDown", { keyCode: 39 });
+ slider.simulate("keyUp", { keyCode: 39 });
+
+ expect(settingsStore.fetchConfig.config.interval).toBe(40);
});
it("custom interval value is rendered correctly", () => {
diff --git a/ui/src/Components/MainModal/Configuration/FilterBarConfiguration.js b/ui/src/Components/MainModal/Configuration/FilterBarConfiguration.js
index 5e7def089..3092759cd 100644
--- a/ui/src/Components/MainModal/Configuration/FilterBarConfiguration.js
+++ b/ui/src/Components/MainModal/Configuration/FilterBarConfiguration.js
@@ -1,49 +1,39 @@
-import React, { Component } from "react";
+import React from "react";
import PropTypes from "prop-types";
-import { action } from "mobx";
-import { observer } from "mobx-react";
+import { useObserver } from "mobx-react";
import { Settings } from "Stores/Settings";
-const FilterBarConfiguration = observer(
- class FilterBarConfiguration extends Component {
- static propTypes = {
- settingsStore: PropTypes.instanceOf(Settings).isRequired,
- };
-
- onAutohideChange = action((event) => {
- const { settingsStore } = this.props;
- settingsStore.filterBarConfig.config.autohide = event.target.checked;
- });
-
- render() {
- const { settingsStore } = this.props;
-
- return (
-
-
-
-
-
-
-
-
- );
- }
- }
-);
+const FilterBarConfiguration = ({ settingsStore }) => {
+ const onAutohideChange = (event) => {
+ settingsStore.filterBarConfig.config.autohide = event.target.checked;
+ };
+ return useObserver(() => (
+
+
+
+
+
+
+
+
+ ));
+};
+FilterBarConfiguration.propTypes = {
+ settingsStore: PropTypes.instanceOf(Settings).isRequired,
+};
export { FilterBarConfiguration };
diff --git a/ui/src/Components/MainModal/Configuration/ThemeConfiguration.js b/ui/src/Components/MainModal/Configuration/ThemeConfiguration.js
index cc6514591..4e3ac51ba 100644
--- a/ui/src/Components/MainModal/Configuration/ThemeConfiguration.js
+++ b/ui/src/Components/MainModal/Configuration/ThemeConfiguration.js
@@ -1,75 +1,52 @@
-import React, { Component } from "react";
+import React from "react";
import PropTypes from "prop-types";
-import { action } from "mobx";
-import { observer } from "mobx-react";
+import { useObserver } from "mobx-react";
import Select from "react-select";
import { Settings } from "Stores/Settings";
import { ThemeContext } from "Components/Theme";
-const ThemeConfiguration = observer(
- class ThemeConfiguration extends Component {
- static propTypes = {
- settingsStore: PropTypes.instanceOf(Settings).isRequired,
- };
- static contextType = ThemeContext;
-
- constructor(props) {
- super(props);
-
- this.validateConfig();
- }
-
- valueToOption = (val) => {
- const { settingsStore } = this.props;
-
- return {
- label: settingsStore.themeConfig.options[val].label,
- value: val,
- };
- };
-
- validateConfig = action(() => {
- const { settingsStore } = this.props;
-
- if (
- !Object.values(settingsStore.themeConfig.options)
- .map((o) => o.value)
- .includes(settingsStore.themeConfig.config.theme)
- ) {
- settingsStore.themeConfig.config.theme =
- settingsStore.themeConfig.options.auto.value;
- }
- });
-
- onCollapseChange = action((newValue, actionMeta) => {
- const { settingsStore } = this.props;
-
- settingsStore.themeConfig.config.theme = newValue.value;
- });
-
- render() {
- const { settingsStore } = this.props;
-
- return (
-
-
-
- );
- }
+const ThemeConfiguration = ({ settingsStore }) => {
+ if (
+ !Object.values(settingsStore.themeConfig.options)
+ .map((o) => o.value)
+ .includes(settingsStore.themeConfig.config.theme)
+ ) {
+ settingsStore.themeConfig.config.theme =
+ settingsStore.themeConfig.options.auto.value;
}
-);
+
+ const valueToOption = (val) => {
+ return {
+ label: settingsStore.themeConfig.options[val].label,
+ value: val,
+ };
+ };
+
+ const onCollapseChange = (newValue, actionMeta) => {
+ settingsStore.themeConfig.config.theme = newValue.value;
+ };
+
+ const context = React.useContext(ThemeContext);
+
+ return useObserver(() => (
+
+
+
+ ));
+};
+ThemeConfiguration.propTypes = {
+ settingsStore: PropTypes.instanceOf(Settings).isRequired,
+};
export { ThemeConfiguration };
diff --git a/ui/src/Components/MainModal/Configuration/ThemeConfiguration.test.js b/ui/src/Components/MainModal/Configuration/ThemeConfiguration.test.js
index ac1bb6253..9132c5643 100644
--- a/ui/src/Components/MainModal/Configuration/ThemeConfiguration.test.js
+++ b/ui/src/Components/MainModal/Configuration/ThemeConfiguration.test.js
@@ -4,29 +4,22 @@ import { mount } from "enzyme";
import toDiffableHtml from "diffable-html";
+import { MockThemeContext } from "__mocks__/Theme";
import { Settings } from "Stores/Settings";
-import { ThemeContext } from "Components/Theme";
-import {
- ReactSelectColors,
- ReactSelectStyles,
-} from "Components/Theme/ReactSelect";
import { ThemeConfiguration } from "./ThemeConfiguration";
let settingsStore;
+
+beforeAll(() => {
+ jest.spyOn(React, "useContext").mockImplementation(() => MockThemeContext);
+});
+
beforeEach(() => {
settingsStore = new Settings();
});
const FakeConfiguration = () => {
- return mount(
-
-
-
- );
+ return mount();
};
describe("", () => {
diff --git a/ui/src/Components/MainModal/Configuration/__snapshots__/AlertGroupCollapseConfiguration.test.js.snap b/ui/src/Components/MainModal/Configuration/__snapshots__/AlertGroupCollapseConfiguration.test.js.snap
index a8524df45..d8199fe48 100644
--- a/ui/src/Components/MainModal/Configuration/__snapshots__/AlertGroupCollapseConfiguration.test.js.snap
+++ b/ui/src/Components/MainModal/Configuration/__snapshots__/AlertGroupCollapseConfiguration.test.js.snap
@@ -4,12 +4,12 @@ exports[` matches snapshot with default value
"