-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Clone existing monitor #2489
Feature: Clone existing monitor #2489
Conversation
Does not work properly but is still useful
Co-authored-by: Adam Stachowicz <saibamenppl@gmail.com>
@@ -804,11 +814,22 @@ message HealthCheckResponse { | |||
this.monitor.notificationIDList[this.$root.notificationList[i].id] = true; | |||
} | |||
} | |||
} else if (this.isEdit) { | |||
} else if (this.isEdit || this.isClone) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this.isEdit
, this.isClone
should be separated for better readability, as there is a check inside this.isEdit
for this.isClone
. Yes, some code will be duplicated, but it will make it easier and more convenient to change the logic of this.isClone
regardless of the logic of this.isEdit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would disagree
@@ -866,7 +887,7 @@ message HealthCheckResponse { | |||
this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4); | |||
} | |||
|
|||
if (this.isAdd) { | |||
if (this.isAdd || this.isClone) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would split it into two conditions so that it would be easier to make changes to either case in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in general I would suggest a redo on the switchcases, it's not clear or obvious that the logic for editMonitor
is in the other branch (in else scope) until you read the whole thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would disagree. There is a lot of things that could be improved in this repo, but duplicating code does not make it better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make another PR for making it more clear that editMonitor
is in the else bracket. Unrelated to this PR
let name = "Add New Monitor"; | ||
if (this.isClone) { | ||
name = "Clone Monitor"; | ||
} else if (this.isEdit) { | ||
name = "Edit"; | ||
} | ||
return this.$t(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do as:
let name;
if (this.isClone) {
name = "Clone Monitor";
} else if (this.isAdd) {
name = "Edit";
} else if (this.isEdit) {
name = "Add New Monitor";
} else {
name = "Wrong Monitor Action";
}
return this.$t(name);
And I would add in en.js: Wrong Monitor Action
Also, it's not quite clear to me why the Edit Monitor translation key wouldn't be added, so that when you change the Edit key for other purposes, you don't risk making this one case incomprehensible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed the name value for isAdd and isEdit?
Adding translations would be good yes, I just did as little as possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All in all good, but not without faults
I will probably not do any more work on this, at least not the coming weeks. Please pick it up and do whatever changes you would like to do. |
Just have a quick look. I think @mathiash98's code is reasonable. @tminei's opinions are good too, but sometimes rewriting it requires to test everything again. It may be not worth the time. So as long as it is working, I will still merge it. The coding practice is not very important in this case. I have planned to merge this pr in 1.21.0, I will come back later. |
…nitor # Conflicts: # src/languages/en.js # src/pages/EditMonitor.vue
this.monitor.id = undefined; // Remove id when cloning as we want a new id | ||
this.monitor.includeSensitiveData = undefined; | ||
this.monitor.maintenance = undefined; | ||
this.monitor.tags = undefined; // FIXME: Cloning tags does not work yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed that, maybe fix it in another pr.
@@ -33,7 +33,7 @@ tsconfig.json | |||
/ecosystem.config.js | |||
/extra/healthcheck.exe | |||
/extra/healthcheck | |||
|
|||
extra/exe-builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not "/extra/exe-builder" like aboves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it does not matter, but nice to have for following style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style is relevant
Description
Adds the feature of cloning existing monitor, I have briefly tested it with ping and https and ensured that all properties was cloned including notifications.
Flow:
/clone/ExistingMonitorId
/dashboard/NewMonitorId
Note: Tags will not be copied when cloning a monitor. The TagsManager component is a bit complicated and I did not want to spend that much more time on it.
Fixes #565
Fixes #2319
Type of change
Please delete any options that are not relevant.
Checklist
(including JSDoc for methods)
Demo
Uptime.Kuma.Clone.Feature.mov