Skip to content
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

Merged
merged 9 commits into from
Feb 25, 2023
Merged

Feature: Clone existing monitor #2489

merged 9 commits into from
Feb 25, 2023

Conversation

mathiash98
Copy link
Contributor

@mathiash98 mathiash98 commented Dec 27, 2022

  • I have read and understand the pull request rules.

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:

  1. Click on an existing monitor
  2. Click clone -> User is redirected to /clone/ExistingMonitorId
  3. Change fields
  4. Click save -> User is redirected to /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.

  • User interface (UI)
  • New feature (non-breaking change which adds functionality)
  • Translation update
  • This change might require a documentation update

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and tested it
  • I have commented my code, particularly in hard-to-understand areas
    (including JSDoc for methods)
  • My changes generate no new warnings

Demo

Uptime.Kuma.Clone.Feature.mov

Closes #565
Closes #2319

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.
Does not work properly but is still useful
src/pages/Details.vue Outdated Show resolved Hide resolved
Co-authored-by: Adam Stachowicz <saibamenppl@gmail.com>
@louislam louislam added this to the 1.21.0 milestone Jan 3, 2023
@@ -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) {
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor

@shynekomaid shynekomaid Jan 19, 2023

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Comment on lines +623 to +629
let name = "Add New Monitor";
if (this.isClone) {
name = "Clone Monitor";
} else if (this.isEdit) {
name = "Edit";
}
return this.$t(name);
Copy link
Contributor

@shynekomaid shynekomaid Jan 19, 2023

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

Copy link
Contributor Author

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

Copy link
Contributor

@shynekomaid shynekomaid left a 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

@mathiash98
Copy link
Contributor Author

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.

@louislam
Copy link
Owner

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.

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
Copy link
Owner

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.

@louislam louislam merged commit 487eae7 into louislam:master Feb 25, 2023
@mathiash98 mathiash98 deleted the mathiash98/clone-monitor branch February 26, 2023 22:25
@@ -33,7 +33,7 @@ tsconfig.json
/ecosystem.config.js
/extra/healthcheck.exe
/extra/healthcheck

extra/exe-builder
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style is relevant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to Duplicate Monitors (UI Improvement) Possibility to copy a monitor
4 participants