- Every interface string of Project Management goes through the catalog: 539 new rows with fr, ja, and zh-CN. - Storage and model messages use a local message() marker and stay free of host imports. The interface translates them. - A board renders again when the language changes. Dates use the interface language. - Fix: the ribbon button waits for the feature switches at startup, and the settings code loads no feature module. - Add six smoke tests: board state, cards, menus, drag and drop, views, and language. - Add docs/guides/project-management.md and UI-060. Update the user, plugin, SDK, host, development, and interface docs and CLAUDE.md. - Name the fake board view of tree/renameUndo "Board fixture", because the native Project Management button is now in the ribbon.
124 lines
7.4 KiB
Svelte
124 lines
7.4 KiB
Svelte
<!--
|
|
Settings → Project Management, and the Project Management settings of the board menu. It is in the main bundle and
|
|
loads no feature code: the priority levels are in the `projectManagement` settings section (`pmSettings.ts`), and
|
|
the default board is in `.runestone/pm/workspace.json` of the workspace (`pmBoards.ts`). It shows only while
|
|
Project Management is on. Each change saves at once.
|
|
-->
|
|
<script lang="ts">
|
|
import { onDestroy, onMount } from "svelte";
|
|
import { message, t } from "$lib/i18n";
|
|
import Icon from "$lib/ui/Icon.svelte";
|
|
import { showActionMenu } from "$lib/ui/managedActionMenu";
|
|
import { PRIORITY_LEVELS, onProjectManagementChange, readProjectManagement, writeProjectManagement, type PriorityLevels, type ProjectManagementSettings } from "./pmSettings";
|
|
import { readBoardCatalog, writeDefaultBoard, type BoardSummary } from "./pmBoards";
|
|
|
|
let { compact = false }: { compact?: boolean } = $props();
|
|
// The errors here are catalog keys without values (pmBoards.ts) or host text. The full `errorText()` of the feature
|
|
// (pm/ui/text.ts) is not necessary, and this component must load no feature module.
|
|
const errorText = (reason: unknown) => $t(reason instanceof Error ? reason.message : String(reason));
|
|
|
|
const levelNames: Record<PriorityLevels, string> = { 2: message("2 — High and Low"), 3: message("3 — High, Medium, and Low"), 5: message("5 — Highest through Lowest") };
|
|
let settings = $state<ProjectManagementSettings>(readProjectManagement());
|
|
let boards = $state<BoardSummary[]>([]);
|
|
let defaultBoard = $state("");
|
|
let boardsReady = $state(false);
|
|
let boardNote = $state("");
|
|
let saving = $state(false);
|
|
let notice = $state("");
|
|
let error = $state("");
|
|
let closeMenu = () => {};
|
|
let disposed = false;
|
|
const active = $derived(boards.filter(board => !board.archived));
|
|
const boardName = $derived(defaultBoard ? active.find(board => board.id === defaultBoard)?.name ?? $t("Unavailable board (opens All tasks)") : $t("All tasks"));
|
|
|
|
function picker(event: MouseEvent, label: string, choices: { label: string; checked: boolean; run: () => void }[]) {
|
|
closeMenu();
|
|
const anchor = event.currentTarget as HTMLButtonElement;
|
|
const bounds = anchor.getBoundingClientRect();
|
|
closeMenu = showActionMenu({ x: bounds.left, y: bounds.bottom + 4, label, parent: anchor.closest("dialog") ?? undefined,
|
|
items: choices.map(choice => ({ label: choice.label, radio: true, checked: choice.checked, run: choice.run })) }).close;
|
|
}
|
|
|
|
function saveLevels(priorityLevels: PriorityLevels) {
|
|
error = "";
|
|
settings = { ...settings, priorityLevels };
|
|
writeProjectManagement(settings).then(() => { notice = $t("Changes saved."); })
|
|
.catch(() => { error = $t("Could not save these settings. Your previous settings still apply. Try again."); notice = ""; settings = readProjectManagement(); });
|
|
}
|
|
|
|
async function saveDefault(id: string) {
|
|
const previous = defaultBoard;
|
|
error = ""; saving = true; defaultBoard = id;
|
|
try { await writeDefaultBoard(id || null); if (!disposed) notice = $t("Changes saved."); }
|
|
catch (reason) { if (!disposed) { defaultBoard = previous; notice = ""; error = errorText(reason); } }
|
|
finally { saving = false; }
|
|
}
|
|
|
|
async function readBoards() {
|
|
try {
|
|
const catalog = await readBoardCatalog();
|
|
if (disposed) return;
|
|
boards = catalog.boards;
|
|
defaultBoard = catalog.defaultBoardId ?? "";
|
|
boardsReady = true;
|
|
boardNote = "";
|
|
} catch (reason) {
|
|
if (!disposed) boardNote = /no workspace/i.test(String(reason)) ? $t("Open a workspace to choose its default board.") : errorText(reason);
|
|
}
|
|
}
|
|
|
|
onMount(() => {
|
|
void readBoards();
|
|
return onProjectManagementChange(() => { settings = readProjectManagement(); });
|
|
});
|
|
onDestroy(() => { disposed = true; closeMenu(); });
|
|
</script>
|
|
|
|
<div class="pm-settings">
|
|
{#if !compact}
|
|
<h2>{$t("Project Management")}</h2>
|
|
<p class="intro">{$t("The boards of each workspace stay in {folder} in the workspace.", { folder: ".runestone/pm" })}</p>
|
|
{/if}
|
|
<div class="card">
|
|
<div class="setting-row">
|
|
<div><span class="name" id="pm-priority-label">{$t("Priority levels")}</span><p id="pm-priority-description">{$t("Existing card priorities stay unchanged when you change this setting.")}</p></div>
|
|
<button class="picker" type="button" aria-label={$t("Priority levels")} aria-describedby="pm-priority-description" aria-haspopup="menu"
|
|
onclick={event => picker(event, $t("Priority levels"), PRIORITY_LEVELS.map(levels => ({ label: $t(levelNames[levels]), checked: settings.priorityLevels === levels, run: () => saveLevels(levels) })))}>
|
|
{$t(levelNames[settings.priorityLevels])}<Icon icon="chevron-down" />
|
|
</button>
|
|
</div>
|
|
<div class="setting-row">
|
|
<div><span class="name" id="pm-default-label">{$t("Default board")}</span><p id="pm-default-description">{boardNote || $t("Choose the board that opens in this workspace. Restored tabs keep their board.")}</p></div>
|
|
<button class="picker" type="button" aria-label={$t("Default board")} aria-describedby="pm-default-description" aria-haspopup="menu" disabled={!boardsReady || saving}
|
|
onclick={event => picker(event, $t("Default board"), [
|
|
{ label: $t("All tasks"), checked: !defaultBoard, run: () => void saveDefault("") },
|
|
...active.map(board => ({ label: board.name, checked: defaultBoard === board.id, run: () => void saveDefault(board.id) })),
|
|
])}>
|
|
{boardName}<Icon icon="chevron-down" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
|
<p class="saved" role="status">{notice}</p>
|
|
</div>
|
|
|
|
<style>
|
|
.pm-settings { min-width: 0; }
|
|
h2 { margin: 0; font-size: var(--rs-settings-heading-size); font-weight: 600; color: var(--rs-text-strong); }
|
|
p { margin: 0; color: var(--rs-text-dim); line-height: 1.45; overflow-wrap: anywhere; }
|
|
.intro { margin: 6px 0 var(--rs-settings-section-gap); }
|
|
.card { padding: 0 12px; background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
|
|
.setting-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; padding: var(--rs-settings-row-padding) 0; }
|
|
.setting-row > div:first-child { flex: 1 1 200px; min-width: 0; }
|
|
.setting-row + .setting-row { border-top: 1px solid var(--rs-border); }
|
|
.name { font-weight: 500; color: var(--rs-text); }
|
|
.setting-row p { margin-top: 3px; font-size: var(--rs-settings-description-size); }
|
|
.picker { display: inline-flex; align-items: center; justify-content: space-between; gap: var(--rs-settings-gap); min-height: var(--rs-settings-control-height); box-sizing: border-box; max-width: 100%; min-width: 160px; padding: 4px 8px; border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg); color: var(--rs-text); font: inherit; text-align: left; cursor: pointer; }
|
|
.picker:not(:disabled):hover { background: var(--rs-bg-active); }
|
|
.picker:disabled { color: var(--rs-text-dim); cursor: default; }
|
|
.picker :global(svg) { width: 14px; height: 14px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; }
|
|
.picker:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: 2px; }
|
|
.saved { font-size: 12px; color: var(--rs-ok); min-height: 20px; margin-top: 10px; }
|
|
.error { color: var(--rs-error); margin-top: 10px; }
|
|
</style>
|