Skip to content
Merged
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
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ off to Planner for timeline work.

## Timeline interactions

Use **Add task** in the header, or **Add your first task** in an empty
collection. Planner creates a portable TaskNotes task through the collection's
implementing `tasknotes.task` type, using its default status and priority. The
new task is shared with TaskNotes, not a separate Planner task copy. Set its
schedule and other planning properties in the inspector after adding it.

An empty collection shows **No tasks yet**. If a saved view or the current
filters hide tasks, Planner instead prompts you to change the view or filters.
A secondary TaskNotes link opens the same collection in the matching LAB,
staging, or production app; TaskNotes still owns its own sign-in and approval.

- Use the minus and plus controls to move between quarter, month, fortnight,
week, work-week, day, hour, and quarter-hour scales. `Ctrl`/`Cmd` + wheel
zooms around the pointer.
Expand Down Expand Up @@ -117,22 +128,24 @@ local callback URLs are never deployed.
The application requests full-collection authorization because mdbase saved
views are collection-level resources. Task records are still selected and
mutated only through `tasknotes.task`. Planner declares capability contract v2
with required atomic groups `collection.read`, `records.edit`, `views.manage`,
with required atomic groups `collection.read`, `records.create`, `records.edit`, `views.manage`,
and `definitions.manage` for these workflows:

- inspect the collection contract
- apply the shared TaskNotes type pack and declared Base-source include setting
during authorization
- query and read TaskNotes records
- watch for collection changes
- update TaskNotes records
- create and update TaskNotes records
- list and execute saved views
- read, create, and update saved-view sources

Atomic consent also grants record validation/rename, type reading/creation, and
saved-view source deletion. Saved-view deletion is not record deletion, and no
independent operation permission is requested. Record creation/deletion, files,
offline replicas, and background scheduling remain excluded. See
independent operation permission is requested. Task creation also requires the
`add` file action; an older approval without it needs renewed consent. Record
deletion, arbitrary file operations, offline replicas, and background scheduling
remain excluded. See
[the migration guard and rollout order](docs/capability-v2-migration.md): the
vendored beta96 v2 candidate SDK is source-bound development evidence, not a published or
signed release. This v2 draft must not deploy before the qualified v2 writer.
Expand Down
13 changes: 8 additions & 5 deletions docs/capability-v2-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ and no optional capabilities:
| Group | Consent meaning |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `collection.read` | Describe, changes, read/query, list/execute views, read view sources, validate records, and read types. |
| `records.edit` | Update and rename records; no record creation or deletion. |
| `records.create` | Create TaskNotes tasks through their implementing record contract. |
| `records.edit` | Update and rename records; no record deletion. |
| `views.manage` | Create, update, and delete saved-view sources. Whole-group consent intentionally includes saved-view deletion, not record deletion. |
| `definitions.manage` | Create/update types and assess/apply type packs. |

Expand All @@ -87,10 +88,12 @@ deletion. These are atomic group meanings, not independently requested operation
permissions. Setup assessment/application is handled by Connect's separate
setup flow, with the existing provisions unchanged.

No `records.create`, `records.delete`, `offline.replica`, or
`background.schedule` is requested. Collection file actions `list`, `read`,
`replace` and `move` are declared because next accounts approve
`collection.read` and `records.edit` together with their matching file actions. Full-collection authorization remains
Planner now requests `records.create` for its add-task workflow, together with
the `add` file action. Existing approvals must grant this expanded declaration;
the app cannot treat an old edit-only grant as creation authority.
No `records.delete`, `offline.replica`, or `background.schedule` is requested.
Collection file actions `list`, `read`, `add`, `replace` and `move` accompany
`collection.read`, `records.create` and `records.edit`. Full-collection authorization remains
necessary for Bases, while the application continues to select and mutate task
records through `tasknotes.task` only. No app capability aliases or fabricated
SDK groups were introduced; session state handling remains SDK-owned.
Expand Down
25 changes: 25 additions & 0 deletions e2e/planner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ test.beforeEach(async ({ page }) => {
await expect(page.getByRole("heading", { name: "Timeline" })).toBeVisible();
});

for (const width of [1440, 834, 390, 360]) {
test(`adds an ordinary task from the persistent control at ${width}px`, async ({
page,
}) => {
await page.setViewportSize({ width, height: 900 });
const add = page.getByRole("button", { name: "Add task", exact: true });
await expect(add).toBeInViewport();
await add.click();
const dialog = page.getByRole("dialog", { name: "Add task", exact: true });
const title = dialog.getByRole("textbox", { name: "Task title" });
await expect(title).toBeFocused();
await title.fill("A task captured in Planner");
await dialog.getByRole("button", { name: "Add task", exact: true }).click();
await expect(dialog).toHaveCount(0);
await expect(
page.getByRole("heading", { name: "A task captured in Planner" }),
).toBeVisible();
expect(
await page.evaluate(
() => document.documentElement.scrollWidth <= innerWidth,
),
).toBe(true);
});
}

test("zooms and toggles TaskNotes completion", async ({ page }) => {
await expect(page.locator(".zoom-control output")).toHaveText("Weeks");
const timeline = page.locator(".gantt-scroll");
Expand Down
3 changes: 2 additions & 1 deletion public/.well-known/mdbase-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
"contract_version": 2,
"required": [
"collection.read",
"records.create",
"records.edit",
"views.manage",
"definitions.manage"
]
},
"access": "full_collection",
"files": {
"required": ["list", "read", "replace", "move"],
"required": ["list", "read", "add", "replace", "move"],
"scope": { "kind": "collection" }
},
"configuration": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/planner-manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { TASKNOTES_TYPE_PACK_VERSION } from "./canonical-task-pack.mjs";

export const requiredCapabilities = Object.freeze([
"collection.read",
"records.create",
"records.edit",
"views.manage",
"definitions.manage",
Expand Down Expand Up @@ -46,7 +47,7 @@ export async function buildPlannerManifest({ appUrl, development = false }) {
// Next accounts approve each record capability together with its file
// actions: reading needs list and read, editing needs replace and move.
files: {
required: ["list", "read", "replace", "move"],
required: ["list", "read", "add", "replace", "move"],
scope: { kind: "collection" },
},
configuration: [
Expand Down
4 changes: 3 additions & 1 deletion scripts/planner-manifest.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ describe("Planner mdbase manifest", () => {
contract_version: 2,
required: [
"collection.read",
"records.create",
"records.edit",
"views.manage",
"definitions.manage",
],
},
files: {
required: ["list", "read", "replace", "move"],
required: ["list", "read", "add", "replace", "move"],
scope: { kind: "collection" },
},
});
Expand Down Expand Up @@ -115,6 +116,7 @@ describe("Planner mdbase manifest", () => {
contract_version: 2,
required: [
"collection.read",
"records.create",
"records.edit",
"views.manage",
"definitions.manage",
Expand Down
2 changes: 1 addition & 1 deletion src/components/gantt-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ export function GanttChart({
return (
<section className="gantt-empty">
<h2>No tasks match these controls</h2>
<p>Change the project, search, or completed-task filter.</p>
<p>Change the saved view, search, or task filters.</p>
</section>
);

Expand Down
164 changes: 164 additions & 0 deletions src/components/planner.create.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import {
cleanup,
fireEvent,
render,
screen,
within,
waitFor,
} from "@testing-library/react";
import { MdbaseError } from "@mdbase-dev/sdk";
import { DemoPlannerRepository } from "../data/demo-repository";
import { Planner } from "./planner";

beforeEach(() => {
vi.stubGlobal(
"matchMedia",
vi.fn(() => ({ matches: false })),
);
HTMLElement.prototype.scrollTo = vi.fn();
});
afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});

async function setup(empty = true) {
const repository = new DemoPlannerRepository();
const collection = await repository.load();
const created = {
...collection.tasks[0],
id: crypto.randomUUID(),
title: "First shared task",
};
const load = vi
.spyOn(repository, "load")
.mockResolvedValue({ ...collection, tasks: empty ? [] : collection.tasks });
repository.createTask = vi.fn(async () => {
load.mockResolvedValue({ ...collection, tasks: [created] });
return created;
});
render(<Planner repository={repository} onChangeCollection={vi.fn()} />);
await screen.findByRole("button", { name: /Sample tasks/ });
return { repository, created };
}

describe("Planner task creation", () => {
it("offers an empty-state action and a persistent add control, then shows the created task", async () => {
const { repository } = await setup();
expect(screen.getByRole("button", { name: "Add task" })).toBeEnabled();
fireEvent.click(
screen.getByRole("button", { name: "Add your first task" }),
);
const dialog = screen.getByRole("dialog", { name: "Add task" });
const title = within(dialog).getByRole("textbox", { name: "Task title" });
expect(title).toHaveFocus();
expect(
within(dialog).getByRole("button", { name: "Add task" }),
).toBeDisabled();
fireEvent.change(title, { target: { value: "First shared task" } });
fireEvent.submit(
within(dialog).getByRole("button", { name: "Add task" }).closest("form")!,
);
await waitFor(() =>
expect(repository.createTask).toHaveBeenCalledWith(
"First shared task",
expect.any(String),
),
);
await waitFor(() =>
expect(screen.queryByRole("dialog", { name: "Add task" })).toBeNull(),
);
expect(screen.queryByText("No tasks yet")).toBeNull();
expect(screen.getAllByText("First shared task").length).toBeGreaterThan(0);
expect(screen.getByRole("button", { name: "Add task" })).toBeEnabled();
});

it("keeps add available with existing tasks and preserves a refused draft without reporting success", async () => {
const { repository } = await setup(false);
vi.mocked(repository.createTask).mockRejectedValueOnce(
new Error("The collection refused this task."),
);
fireEvent.click(screen.getByRole("button", { name: "Add task" }));
const dialog = screen.getByRole("dialog", { name: "Add task" });
const title = within(dialog).getByRole("textbox", { name: "Task title" });
fireEvent.change(title, { target: { value: "Keep this draft" } });
fireEvent.click(within(dialog).getByRole("button", { name: "Add task" }));
expect(await within(dialog).findByRole("alert")).toHaveTextContent(
"The collection refused this task.",
);
expect(title).toHaveValue("Keep this draft");
expect(screen.getByRole("dialog", { name: "Add task" })).toBeVisible();
expect(screen.queryByText("Task added")).toBeNull();
});

it("retains the original title and creation identity after an unknown outcome and reopening", async () => {
const { repository } = await setup();
vi.mocked(repository.createTask).mockRejectedValueOnce(
new MdbaseError({
code: "outcome_unknown",
recovery: "refresh",
message: "The result is unknown",
}),
);
fireEvent.click(screen.getByRole("button", { name: "Add task" }));
let dialog = screen.getByRole("dialog", { name: "Add task" });
fireEvent.change(
within(dialog).getByRole("textbox", { name: "Task title" }),
{ target: { value: "Original task" } },
);
fireEvent.click(within(dialog).getByRole("button", { name: "Add task" }));
expect(await within(dialog).findByRole("alert")).toHaveTextContent(
/same task creation/,
);
const intent = vi.mocked(repository.createTask).mock.calls[0][1];
expect(
within(dialog).getByRole("textbox", { name: "Task title" }),
).toHaveAttribute("readonly");
fireEvent.click(within(dialog).getByRole("button", { name: "Cancel" }));
fireEvent.click(screen.getByRole("button", { name: "Add task" }));
dialog = screen.getByRole("dialog", { name: "Add task" });
expect(
within(dialog).getByRole("textbox", { name: "Task title" }),
).toHaveValue("Original task");
fireEvent.click(within(dialog).getByRole("button", { name: "Add task" }));
await waitFor(() =>
expect(repository.createTask).toHaveBeenLastCalledWith(
"Original task",
intent,
),
);
await waitFor(() =>
expect(screen.queryByRole("dialog", { name: "Add task" })).toBeNull(),
);
});

it("does not send a second creation or allow cancellation while the first is in flight", async () => {
const { repository, created } = await setup();
let complete!: (value: typeof created) => void;
vi.mocked(repository.createTask).mockImplementation(
() =>
new Promise((resolve) => {
complete = resolve;
}),
);
fireEvent.click(screen.getByRole("button", { name: "Add task" }));
const dialog = screen.getByRole("dialog", { name: "Add task" });
fireEvent.change(
within(dialog).getByRole("textbox", { name: "Task title" }),
{ target: { value: "Only once" } },
);
const form = within(dialog)
.getByRole("button", { name: "Add task" })
.closest("form")!;
fireEvent.submit(form);
fireEvent.submit(form);
expect(repository.createTask).toHaveBeenCalledTimes(1);
expect(
within(dialog).getByRole("button", { name: "Cancel" }),
).toBeDisabled();
complete(created);
await waitFor(() =>
expect(screen.queryByRole("dialog", { name: "Add task" })).toBeNull(),
);
});
});
Loading
Loading