Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/src/page/status-pages/builder/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { publicAddress, publicUrl, STATUS_PAGE_BASE_URL, statusPagesHref } from
import { textField } from "../shared/fields"
import { APPEARANCES, presetCards } from "../shared/look"
import { monitorStatusOf } from "../shared/derive"
import { orNull } from "../shared/form"
import { checkedRows } from "../shared/picker"
import { pickerView } from "../shared/picker-view"
import { daysOf, previewDocument, previewFrame, previewTheme } from "../shared/preview"
Expand Down Expand Up @@ -182,7 +183,7 @@ const draftDocument = (model: Model): string => {
id: draftComponentId(index),
name: Str.trim(row.name) === "" ? "Untitled component" : Str.trim(row.name),
description: null,
group: Str.trim(row.group) === "" ? null : Str.trim(row.group),
group: orNull(row.group),
monitorStatus: monitorStatusOf(monitors, row.monitorId),
manualStatus: row.monitorId === null ? row.manualStatus : null,
showUptime: true,
Expand All @@ -196,7 +197,6 @@ const draftDocument = (model: Model): string => {
snapshot,
nowMs,
isSelectable: false,
selectedIds: [],
publicUrl: isSlug(model.slug) ? publicUrl(STATUS_PAGE_BASE_URL, model.slug) : null,
})
}
Expand Down
27 changes: 19 additions & 8 deletions apps/web/src/page/status-pages/editor/analyst.scene.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { OrgId } from "@maple/domain"
import { StatusPagePublicId } from "@maple/domain/http/v2"
import * as Policy from "@maple/domain/policy"
import { Result, Schema, Array as Arr } from "effect"
import { expect as expectView, given, role, scene, text, withViewInputs } from "foldkit/scene"
import { expect as expectView, given, Mount, role, scene, text, withViewInputs } from "foldkit/scene"
import * as Dialog from "@maple/views/ui/dialog"
import { MountDialog } from "@maple/views/ui/dialog"
import { describe, test } from "vitest"
import type { PageContext } from "../../contract"
import { ORG } from "../../kit/alert-test-rows"
Expand All @@ -23,13 +25,17 @@ const view = withViewInputs(pageView, { context })()
const MEMBER = Policy.grantsOf(["org:member"])
const ANALYST = Policy.grantsOf(["org:analyst"])

/** The editor's Page tab over `incidents`, read by a session holding `grants`. */
/** The editor's Incidents tab over `incidents`, read by a session holding `grants`. */
const loaded = (
grants: ReadonlyArray<Policy.Permission>,
incidents: ReadonlyArray<ReturnType<typeof incident>>,
): Model => {
const entered = init(
{ _tag: "StatusPage", pageId: Schema.encodeSync(StatusPagePublicId)(statusPage().id), search: {} },
{
_tag: "StatusPage",
pageId: Schema.encodeSync(StatusPagePublicId)(statusPage().id),
search: { view: "incidents" },
},
context,
).model
return Arr.reduce(
Expand Down Expand Up @@ -58,29 +64,31 @@ const loaded = (
const DRAFT = incident(1, { published: false })
const MAINTENANCE = incident(2, { kind: "maintenance", title: "Database upgrade" })

const mounted = Mount.resolve(MountDialog, Dialog.Message.CompletedMountDialog())

const opened = (grants: ReadonlyArray<Policy.Permission>, row: ReturnType<typeof incident>, n: number) =>
pageUpdate(loaded(grants, [row]), Message.ClickedIncident({ incidentId: incidentId(n) })).model

describe("status page editor, analyst", () => {
test("Post incident is offered to a member and not to an analyst", () => {
test("Declare incident is offered to a member and not to an analyst", () => {
scene(
{ update: pageUpdate, view },
given(loaded(ANALYST, [])),
expectView(text("Nothing posted.")).toExist(),
expectView(role("button", { name: "Post incident" })).toBeAbsent(),
expectView(text("No open incidents.")).toExist(),
expectView(role("button", { name: "Declare incident" })).toBeAbsent(),
)
scene(
{ update: pageUpdate, view },
given(loaded(MEMBER, [])),
expectView(text("Nothing posted. Post incident when something breaks.")).toExist(),
expectView(role("button", { name: "Post incident" })).toExist(),
expectView(role("button", { name: "Declare incident" })).toExist(),
)
})

test("an analyst reads an open incident's updates and gets none of its actions", () => {
scene(
{ update: pageUpdate, view },
given(opened(ANALYST, DRAFT, 1)),
mounted,
expectView(text("Draft, not public")).toExist(),
expectView(role("region", { name: "Updates" })).toExist(),
expectView(role("button", { name: "Publish" })).toBeAbsent(),
Expand All @@ -95,6 +103,7 @@ describe("status page editor, analyst", () => {
scene(
{ update: pageUpdate, view },
given(opened(MEMBER, DRAFT, 1)),
mounted,
expectView(role("button", { name: "Publish" })).toExist(),
expectView(role("button", { name: "Post update" })).toExist(),
expectView(role("button", { name: "Resolve" })).toExist(),
Expand All @@ -107,12 +116,14 @@ describe("status page editor, analyst", () => {
scene(
{ update: pageUpdate, view },
given(opened(ANALYST, MAINTENANCE, 2)),
mounted,
expectView(role("button", { name: "Complete" })).toBeAbsent(),
expectView(role("button", { name: "Delete maintenance" })).toBeAbsent(),
)
scene(
{ update: pageUpdate, view },
given(opened(MEMBER, MAINTENANCE, 2)),
mounted,
expectView(role("button", { name: "Complete" })).toExist(),
expectView(role("button", { name: "Delete maintenance" })).toExist(),
)
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/page/status-pages/editor/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ export const FocusEditorElement = Command.define("FocusStatusPageEditorElement",
Dom.focus(`#${CSS.escape(id)}`).pipe(Effect.ignore, Effect.as(Message.CompletedFocus())),
})

/** Scrolls an opened component's row into view as it mounts: it may open from the live page. */
export const RevealOpenComponent = Mount.define("RevealStatusPageComponent", {
messages: [Message.CompletedFocus],
execute: ({ element }) =>
Effect.sync(() => element.scrollIntoView({ block: "nearest" })).pipe(
Effect.as(Message.CompletedFocus()),
),
})

/** Focuses the element as it mounts, in the same render, so no keystroke lands elsewhere first. */
export const FocusNewRow = Mount.define("FocusStatusPageEditorRow", {
messages: [Message.CompletedFocus],
Expand Down
Loading
Loading