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
5 changes: 5 additions & 0 deletions .changeset/help-report-in-more.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ftw": patch
---

The help file moves from under the plan chart to More, as a "Get help" tile next to Settings, Setup and Version. Asking for help is about the whole box, not the plan. It downloads the same file as before.
18 changes: 2 additions & 16 deletions web/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1894,24 +1894,9 @@ body.ftw-app .plan-warning-details > pre {
}
body.ftw-app .plan-actions { gap: 10px; display: flex; align-items: center; }

/* The "why is it doing that?" escape hatch, below the chart because
that's where the question forms. Understated: it should be findable
when something looks wrong, not compete with the plan itself. */
body.ftw-app .plan-help-request {
margin: 10px 0 2px;
padding-top: 10px;
border-top: 1px solid var(--border);
}
body.ftw-app .plan-help-request button { padding-left: 0; }
body.ftw-app .plan-help-request button[disabled] {
opacity: 0.6;
cursor: default;
text-decoration: none;
}

body.ftw-app .more-actions {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 12px;
margin-bottom: 18px;
}
Expand All @@ -1930,6 +1915,7 @@ body.ftw-app .more-action {
text-decoration: none;
cursor: pointer;
}
body.ftw-app .more-action[disabled] { cursor: default; opacity: 0.7; }
body.ftw-app .more-action:hover {
border-color: var(--accent-e);
background: color-mix(in oklch, var(--ink-raised) 92%, var(--accent-e));
Expand Down
45 changes: 45 additions & 0 deletions web/diagnose.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,51 @@
const badge = document.querySelector('ftw-update-badge');
if (badge && typeof badge.open === 'function') badge.open();
});
const helpShortcut = document.getElementById('more-help-btn');
if (helpShortcut) helpShortcut.addEventListener('click', downloadHelpReport);
}

// Pulls GET /api/support/dump and saves it. The archive leads with
// 00-help-report.md, the readable answer to "why is it doing that?" and
// "what happened last night?", and carries the logs, config and a week of
// telemetry, plans and control journal behind it. One button and one
// file, so a user asking for help never has to work out which download we
// meant. The bare report is still at /api/support/report.
//
// It sits under More with Settings, Setup and Version: asking for help is
// about the whole box, not one view of it.
function downloadHelpReport() {
const btn = document.getElementById('more-help-btn');
const status = document.getElementById('more-help-status');
if (!btn || btn.disabled) return;
const original = status ? status.textContent : '';
const say = text => { if (status) status.textContent = text; };
btn.disabled = true;
say('Building the file…');
const restore = text => {
say(text);
setTimeout(() => {
btn.disabled = false;
say(original);
}, 4000);
};
apiFetch('/api/support/dump')
.then(resp => {
if (!resp.ok) throw new Error('HTTP ' + resp.status);
return resp.blob().then(blob => {
const stamp = new Date().toISOString().slice(0, 16).replace(/[-:T]/g, '');
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'ftw-help-' + stamp + '.zip';
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(() => URL.revokeObjectURL(url), 30000);
restore('Downloaded');
});
})
.catch(err => restore('Failed: ' + (err && err.message ? err.message : String(err))));
}

function applyHash() {
Expand Down
38 changes: 25 additions & 13 deletions web/help-report.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,41 @@ import { readFileSync } from "node:fs";
import test from "node:test";

const plan = readFileSync(new URL("./plan.js", import.meta.url), "utf8");
const diagnose = readFileSync(new URL("./diagnose.js", import.meta.url), "utf8");
const index = readFileSync(new URL("./index.html", import.meta.url), "utf8");
const diagnostics = readFileSync(new URL("./diagnostics-modal.js", import.meta.url), "utf8");

test("the plan card offers a help report", () => {
assert.match(index, /id="plan-help-report"/);
// The label has to name the problem the user has, not the artefact we
// produce — someone whose battery is misbehaving does not search for
// "diagnostics".
assert.match(index, /Something looks wrong\?/);
function section(html, id) {
const start = html.indexOf(`id="${id}"`);
assert.notEqual(start, -1, `${id} is missing`);
const end = html.indexOf("</main>", start);
return html.slice(start, end);
}

// Asking for help is about the whole box, so the file sits under More with
// Settings, Setup and Version, not under one view such as the plan.
test("the help report lives under More, not under Plan", () => {
const more = section(index, "view-more");
assert.match(more, /id="more-help-btn"/);
assert.match(more, /<strong>Get help<\/strong>/);
// The plan card is moved into the Plan view at run time, so check the
// whole page: the old button under the chart is gone.
assert.doesNotMatch(index, /plan-help-report|Download a help report/);
assert.doesNotMatch(plan, /support\/dump|downloadHelpReport/);
});

// One button, one file. The archive leads with the readable report and
// carries the logs behind it, so a user asking for help never has to work
// out which of two downloads we meant.
test("the help-report button downloads the bundle, not just the text", () => {
assert.match(plan, /getElementById\('plan-help-report'\)/);
assert.match(plan, /apiFetch\('\/api\/support\/dump'\)/);
assert.match(plan, /a\.download = 'ftw-help-' \+ stamp \+ '\.zip'/);
test("the help button downloads the bundle, not just the text", () => {
assert.match(diagnose, /getElementById\('more-help-btn'\)/);
assert.match(diagnose, /apiFetch\('\/api\/support\/dump'\)/);
assert.match(diagnose, /a\.download = 'ftw-help-' \+ stamp \+ '\.zip'/);
});

test("the help-report button reports failure instead of failing silently", () => {
assert.match(plan, /restore\('Failed: '/);
assert.match(plan, /btn\.disabled = true/);
test("the help button reports failure instead of failing silently", () => {
assert.match(diagnose, /restore\('Failed: '/);
assert.match(diagnose, /btn\.disabled = true/);
});

test("the driver diagnose modal also links the report", () => {
Expand Down
13 changes: 4 additions & 9 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,6 @@ <h2>Plan</h2>
<span id="plan-sell-legend" class="legend-item bat-only" hidden title="What the battery gives that the home sells to the grid"><span class="legend-color" style="background:var(--red-e)"></span> Sell</span>
<span class="legend-item bat-only" title="State of charge — battery fill %, 0–100. Its line takes the colour of what the battery does, grey where it waits"><span class="legend-color" style="background:var(--fg-dim)"></span> SoC</span>
</div>
<!-- The escape hatch for "why is it doing that?". Downloads one
Markdown file holding the live state, the active plan slot,
forecast-versus-reality and any automated findings — enough
for someone else to answer without a screenshot round-trip. -->
<div class="plan-help-request">
<button type="button" id="plan-help-report" class="btn-link">
Something looks wrong? Download a help report
</button>
</div>
</section>
</section>

Expand Down Expand Up @@ -866,6 +857,10 @@ <h2>Setup, settings and system</h2>
<span class="more-action-icon" aria-hidden="true">↻</span>
<span><strong>Version</strong><small>Running version and updates</small></span>
</button>
<button id="more-help-btn" class="more-action" type="button">
<span class="more-action-icon" aria-hidden="true">?</span>
<span><strong>Get help</strong><small id="more-help-status">One file to share when you ask for help</small></span>
</button>
</section>
</main>

Expand Down
46 changes: 0 additions & 46 deletions web/plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -1564,52 +1564,6 @@ import {
else helpModal.setAttribute('open', '');
});
}
const reportBtn = document.getElementById('plan-help-report');
if (reportBtn) reportBtn.addEventListener('click', downloadHelpReport);
}

// Pulls GET /api/support/dump and saves it. That archive leads with
// 00-help-report.md — the readable answer to "why is it doing that?" and
// "what happened last night?" — and carries the logs, config and a week
// of telemetry, plans and control journal behind it. One button and
// one file, because a user asking for help should not have to work out
// which of two downloads we wanted. The bare report is still at
// /api/support/report for anyone who wants only the text.
//
// Lives here rather than in the driver Diagnose modal because the
// question is asked while looking at the plan, not at a device.
function downloadHelpReport() {
const btn = document.getElementById('plan-help-report');
if (!btn || btn.disabled) return;
const original = btn.textContent;
btn.disabled = true;
btn.textContent = 'Building report…';
const restore = function (text) {
btn.textContent = text;
setTimeout(function () {
btn.disabled = false;
btn.textContent = original;
}, 4000);
};
apiFetch('/api/support/dump')
.then(function (resp) {
if (!resp.ok) throw new Error('HTTP ' + resp.status);
return resp.blob().then(function (blob) {
const stamp = new Date().toISOString().slice(0, 16).replace(/[-:T]/g, '');
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'ftw-help-' + stamp + '.zip';
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(function () { URL.revokeObjectURL(url); }, 30000);
restore('Downloaded');
});
})
.catch(function (err) {
restore('Failed: ' + (err && err.message ? err.message : String(err)));
});
}

if (document.readyState === 'loading') {
Expand Down