Repository: louislam/uptime-kuma
File: src/pages/EditMonitor.vue (Vue)

Code before:
                        await this.$refs.tagsManager.submit(res.monitorID);

                        toast.success(res.msg);
                        this.processing = false;
                        this.$root.getMonitorList();
                        this.$router.push("/dashboard/" + res.monitorID);
                    } else {
                        toast.error(res.msg);
                        this.processing = false;
                    }

                });
            } else {
                await this.$refs.tagsManager.submit(this.monitor.id);

                this.$root.getSocket().emit("editMonitor", this.monitor, (res) => {
                    this.processing = false;
                    this.$root.toastRes(res);
                    this.init();
                });
            }
        },

        /**
         * Added a Notification Event
         * Enable it if the notification is added in EditMonitor.vue
         * @param {number} id ID of notification to add
         */
        addedNotification(id) {
            this.monitor.notificationIDList[id] = true;
        },

        /**
         * Added a Proxy Event
         * Enable it if the proxy is added in EditMonitor.vue
         * @param {number} id ID of proxy to add
         */
        addedProxy(id) {
            this.monitor.proxyId = id;
        },

        // Added a Docker Host Event
        // Enable it if the Docker Host is added in EditMonitor.vue
        addedDockerHost(id) {
            this.monitor.docker_host = id;
        }
    },
};
</script>

<style lang="scss" scoped>

Review comment (refactor):
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`

Code after:
                    dns_resolve_server: "1.1.1.1",
                    docker_container: "",
                    docker_host: null,
                    proxyId: null,
                    mqttUsername: "",
                    mqttPassword: "",
                    mqttTopic: "",
                    mqttSuccessMessage: "",
                    authMethod: null,
                    httpBodyEncoding: "json"
                };

                if (this.$root.proxyList && !this.monitor.proxyId) {
                    const proxy = this.$root.proxyList.find(proxy => proxy.default);

                    if (proxy) {
                        this.monitor.proxyId = proxy.id;
                    }
                }

                for (let i = 0; i < this.$root.notificationList.length; i++) {
                    if (this.$root.notificationList[i].isDefault === true) {
                        this.monitor.notificationIDList[this.$root.notificationList[i].id] = true;
                    }
                }
            } else if (this.isEdit || this.isClone) {
                this.$root.getSocket().emit("getMonitor", this.$route.params.id, (res) => {
                    if (res.ok) {
                        this.monitor = res.monitor;

                        if (this.isClone) {
                            /*
                         * Cloning a monitor will include properties that can not be posted to backend
                         * as they are not valid columns in the SQLite table.
                         */
                            this.monitor.id = undefined; // Remove id when cloning as we want a new id
                            this.monitor.includeSensitiveData = undefined;
                            this.monitor.maintenance = undefined;
                            this.monitor.name = this.$t("cloneOf", [ this.monitor.name ]);
                            this.monitor.tags = undefined; // FIXME: Cloning tags does not work yet
                        }

                        // Handling for monitors that are created before 1.7.0
                        if (this.monitor.retryInterval === 0) {
                            this.monitor.retryInterval = this.monitor.interval;
                        }
                    } else {
                        toast.error(res.msg);
                    }
                });
            }