openstatusHQ / openstatus

🏓 The open-source synthetic monitoring platform 🏓
https://openstatus.dev
GNU Affero General Public License v3.0
5.91k stars 356 forks source link

Cloning monitors #919

Closed mxkaske closed 1 month ago

mxkaske commented 1 month ago

Description

We should be able to 'create' or 'clone' a monitor to take all the settings with us (e.g. timeout, assertions, status page relationship, monitor tag relationship,...)

Include a new Dropdown Item

CleanShot 2024-07-08 at 20 38 48@2x

Ipriyankrajai commented 1 month ago

Hey @mxkaske , I would like to work on this.

Ipriyankrajai commented 1 month ago

Hello @mxkaske,

When the user clicks on the clone action, should I redirect them to the /monitors/new page and preload the values?

mxkaske commented 1 month ago

I like the idea but if we would like to preload the values but not save the cloned monitor some issue we will face is:

    if (defaultValues) {
      await api.monitor.update.mutate(props);
    } else {
      await api.monitor.create.mutate(props);
    }

Probably, a simple if (defaultValues.id) ... could be it.

Otherwise, we could clone (+ maybe set active: false to avoid to test the endpoint immediately), save the monitor by default and redirect the user to /monitors/[id]/edit to be able to edit it right away.

What are your thoughts?

Ipriyankrajai commented 1 month ago

I prefer the second approach where we first create the monitor and then redirect the user to /monitors/[id]/edit.

mxkaske commented 1 month ago

Perfect! What we can do is deactivating the monitor onClone and add a ?active=true search param to override the defaultValue to be set the active value back to true.

    <MonitorForm
      defaultValues={{
        ...monitor,
        active: searchParams.get("active") || monitor.active
      }}
      {...}
    />

you might need to use zod for validation.