mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
feat(ui): prefer silence author from the API response over local storage
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -180,6 +180,7 @@ class AlertStore {
|
||||
valueMapping: {}
|
||||
},
|
||||
silenceForm: {
|
||||
author: "",
|
||||
strip: {
|
||||
labels: []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user