{
  "$schema": "./.schemas/page.schema.json",
  "title": "Project",
  "icon": "ladybug",
  "sidebar": false,
  "params": {
    "id": {
      "example": "4508123456789012",
      "pattern": "[0-9]{1,20}"
    }
  },
  "title_from": {
    "ref": "p",
    "value": "project.name"
  },
  "sources": {
    "p": {
      "url": "https://sentry.io",
      "secret": "sentry",
      "every": "1m",
      "requests": {
        "project": "/api/0/projects/tidewater-apps/{param.id}/",
        "esc": "/api/0/organizations/tidewater-apps/issues/?query=is:unresolved+is:escalating&statsPeriod=24h&groupStatsPeriod=&sort=freq&collapse=lifetime&collapse=filtered&collapse=unhandled&project={param.id}&limit=25",
        "reg": "/api/0/organizations/tidewater-apps/issues/?query=is:unresolved+is:regressed&statsPeriod=24h&groupStatsPeriod=&sort=freq&collapse=lifetime&collapse=filtered&collapse=unhandled&project={param.id}&limit=25",
        "new": "/api/0/organizations/tidewater-apps/issues/?query=is:unresolved+is:new&statsPeriod=24h&groupStatsPeriod=&sort=freq&collapse=lifetime&collapse=filtered&collapse=unhandled&project={param.id}&limit=25",
        "ongoing": "/api/0/organizations/tidewater-apps/issues/?query=is:unresolved+is:ongoing&statsPeriod=24h&groupStatsPeriod=&sort=freq&collapse=lifetime&collapse=filtered&collapse=unhandled&project={param.id}&limit=60",
        "hours": "/api/0/organizations/tidewater-apps/stats_v2/?field=sum(quantity)&category=error&outcome=accepted&groupBy=outcome&statsPeriod=24h&interval=1h&project={param.id}"
      },
      "derive": [
        {
          "name": "rows",
          "value": {
            "each": [
              "esc",
              "reg",
              "new",
              "ongoing"
            ],
            "limit": 60,
            "fields": {
              "id": "id",
              "shortId": "shortId",
              "title": "title",
              "culprit": "culprit",
              "level": "level",
              "substatus": "substatus",
              "lastSeen": "lastSeen",
              "project": "project.slug",
              "events": {
                "path": "count",
                "match": "^([0-9]+)$"
              }
            }
          }
        },
        {
          "name": "n_esc",
          "value": {
            "count": "esc",
            "default": 0
          }
        },
        {
          "name": "n_reg",
          "value": {
            "count": "reg",
            "default": 0
          }
        },
        {
          "name": "n_new",
          "value": {
            "count": "new",
            "default": 0
          }
        },
        {
          "name": "n_ongoing",
          "value": {
            "count": "ongoing",
            "default": 0
          }
        },
        {
          "name": "n_all",
          "value": {
            "add": [
              "n_esc",
              "n_reg",
              "n_new",
              "n_ongoing"
            ]
          }
        },
        {
          "name": "n_hot",
          "value": {
            "add": [
              "n_esc",
              "n_reg"
            ]
          }
        },
        {
          "name": "cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "n_esc",
                  "gte": 25
                },
                {
                  "path": "n_reg",
                  "gte": 25
                },
                {
                  "path": "n_new",
                  "gte": 25
                },
                {
                  "path": "n_ongoing",
                  "gte": 60
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "hot_cut",
          "value": {
            "if": {
              "any": [
                {
                  "path": "n_esc",
                  "gte": 25
                },
                {
                  "path": "n_reg",
                  "gte": 25
                }
              ]
            },
            "then": {
              "template": "yes"
            },
            "else": {
              "template": "no"
            }
          }
        },
        {
          "name": "errors_total",
          "value": {
            "path": "hours.groups[0].totals[\"sum(quantity)\"]",
            "default": 0
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "about",
      "type": "facts",
      "label": "Last 24 hours",
      "items": [
        {
          "key": "Issues",
          "value": "—"
        },
        {
          "key": "Errors",
          "value": "—"
        },
        {
          "key": "Latest release",
          "value": "—"
        }
      ],
      "source": {
        "ref": "p",
        "map": {
          "items[0].value": {
            "if": {
              "path": "cut",
              "equals": "yes"
            },
            "then": {
              "if": {
                "path": "n_new",
                "gt": 0
              },
              "then": {
                "template": "At least {n_all} unresolved · {n_new} new"
              },
              "else": {
                "template": "At least {n_all} unresolved"
              }
            },
            "else": {
              "if": {
                "path": "n_all",
                "equals": 0
              },
              "then": {
                "template": "None unresolved"
              },
              "else": {
                "if": {
                  "path": "n_new",
                  "gt": 0
                },
                "then": {
                  "template": "{n_all} unresolved · {n_new} new"
                },
                "else": {
                  "template": "{n_all} unresolved"
                }
              }
            }
          },
          "items[1].value": {
            "if": {
              "path": "errors_total",
              "equals": 1
            },
            "then": {
              "template": "1"
            },
            "else": {
              "template": "{errors_total}"
            }
          },
          "items[2].value": {
            "if": {
              "path": "project.latestRelease.version",
              "exists": true
            },
            "then": {
              "template": "{project.latestRelease.version|clip:60}"
            },
            "else": {
              "template": "None yet"
            }
          }
        }
      }
    },
    {
      "id": "errors",
      "type": "sparkline",
      "label": "Errors",
      "unit": "an hour",
      "change": false,
      "points": [],
      "source": {
        "ref": "p",
        "when": {
          "value": {
            "count": "hours.groups[0].series[\"sum(quantity)\"]",
            "default": 0
          },
          "gte": 2
        },
        "map": {
          "points": {
            "each": "hours.groups[0].series[\"sum(quantity)\"]",
            "value": "$"
          },
          "times": {
            "each": "hours.intervals",
            "value": "$"
          }
        }
      }
    },
    {
      "id": "issues",
      "type": "list",
      "label": "Issues",
      "max_items": 7,
      "items": [],
      "source": {
        "ref": "p",
        "empty": {
          "text": "No unresolved issues seen in the last 24 hours.",
          "when": {
            "path": "n_all",
            "equals": 0
          }
        },
        "map": {
          "label": {
            "if": {
              "path": "n_all",
              "gt": 60
            },
            "then": {
              "if": {
                "path": "cut",
                "equals": "yes"
              },
              "then": {
                "template": "Issues · the first 60 of at least {n_all}"
              },
              "else": {
                "template": "Issues · the first 60 of {n_all}"
              }
            },
            "else": {
              "if": {
                "path": "cut",
                "equals": "yes"
              },
              "then": {
                "template": "Issues · the busiest {n_all}"
              },
              "else": {
                "template": "Issues"
              }
            }
          },
          "items": {
            "each": "rows",
            "fields": {
              "key": "id",
              "text": {
                "template": "{title|clip:160|verbatim}"
              },
              "subtitle": {
                "if": {
                  "all": [
                    {
                      "path": "culprit",
                      "exists": true
                    },
                    {
                      "path": "culprit",
                      "not": ""
                    }
                  ]
                },
                "then": {
                  "if": {
                    "path": "events",
                    "equals": 1
                  },
                  "then": {
                    "template": "1 event · {culprit|clip:30}"
                  },
                  "else": {
                    "template": "{events} events · {culprit|clip:30}"
                  }
                },
                "else": {
                  "if": {
                    "path": "events",
                    "equals": 1
                  },
                  "then": {
                    "template": "1 event"
                  },
                  "else": {
                    "template": "{events} events"
                  }
                }
              },
              "detail": {
                "if": {
                  "path": "substatus",
                  "in": [
                    "escalating",
                    "regressed",
                    "new"
                  ]
                },
                "then": {
                  "path": "substatus",
                  "values": {
                    "escalating": "Escalating",
                    "regressed": "Regressed",
                    "new": "New"
                  }
                },
                "else": {
                  "template": "{lastSeen|ago}"
                }
              },
              "icon": {
                "path": "level",
                "values": {
                  "fatal": "xmark.octagon.fill",
                  "error": "exclamationmark.circle",
                  "warning": "exclamationmark.triangle",
                  "info": "info.circle",
                  "debug": "info.circle"
                },
                "default": "exclamationmark.circle"
              },
              "color": {
                "path": "level",
                "values": {
                  "fatal": "red"
                }
              },
              "url": {
                "template": "legato://page/sentry-issue?id={id|raw}"
              }
            }
          }
        }
      },
      "row_actions": [
        {
          "label": "Resolve",
          "icon": "checkmark.circle",
          "method": "PUT",
          "path": "/api/0/organizations/tidewater-apps/issues/{id}/",
          "body": {
            "status": "resolved"
          },
          "error": "detail",
          "confirm": {
            "message": "Resolve {shortId}? Sentry marks it Regressed if it happens again.",
            "button": "Resolve"
          }
        },
        {
          "label": "Archive",
          "icon": "archivebox",
          "method": "PUT",
          "path": "/api/0/organizations/tidewater-apps/issues/{id}/",
          "body": {
            "status": "ignored",
            "substatus": "archived_until_escalating",
            "statusDetails": {}
          },
          "error": "detail",
          "confirm": {
            "message": "Archive {shortId} until it escalates?",
            "button": "Archive"
          }
        }
      ]
    }
  ]
}
