feat(ui): prefer silence author from the API response over local storage

This commit is contained in:
Łukasz Mierzwa
2019-07-12 21:12:00 +01:00
parent 1a98e01622
commit 36617b2f49
3 changed files with 33 additions and 2 deletions

View File

@@ -78,7 +78,7 @@ const SilenceForm = observer(
);
componentDidMount() {
const { silenceFormStore, settingsStore } = this.props;
const { silenceFormStore } = this.props;
// reset startsAt & endsAt on every mount, unless we're editing a silence
if (silenceFormStore.data.silenceID === null) {
@@ -91,11 +91,22 @@ const SilenceForm = observer(
silenceFormStore.data.addEmptyMatcher();
}
this.populateAuthor();
}
populateAuthor = action(() => {
const { alertStore, silenceFormStore, settingsStore } = this.props;
if (alertStore.settings.values.silenceForm.author !== "") {
settingsStore.silenceFormConfig.config.author =
alertStore.settings.values.silenceForm.author;
}
if (silenceFormStore.data.author === "") {
silenceFormStore.data.author =
settingsStore.silenceFormConfig.config.author;
}
}
});
addMore = action(event => {
const { silenceFormStore } = this.props;

View File

@@ -132,6 +132,25 @@ describe("<SilenceForm /> inputs", () => {
expect(silenceFormStore.data.author).toBe("foo@example.com");
});
it("default author value comes from the API response if present", () => {
alertStore.settings.values.silenceForm.author = "bar@example.com";
settingsStore.silenceFormConfig.config.author = "foo@example.com";
const tree = MountedSilenceForm();
const input = tree.find("input[placeholder='Author']");
expect(input.props().value).toBe("bar@example.com");
});
it("author value from the API response is saved to the Settings store", () => {
alertStore.settings.values.silenceForm.author = "bar@example.com";
settingsStore.silenceFormConfig.config.author = "";
const tree = MountedSilenceForm();
const input = tree.find("input[placeholder='Author']");
expect(input.props().value).toBe("bar@example.com");
expect(settingsStore.silenceFormConfig.config.author).toBe(
"bar@example.com"
);
});
it("default author value is empty if nothing is stored in Settings", () => {
settingsStore.silenceFormConfig.config.author = "";
const tree = MountedSilenceForm();

View File

@@ -180,6 +180,7 @@ class AlertStore {
valueMapping: {}
},
silenceForm: {
author: "",
strip: {
labels: []
}