Changed parts: the list is the car's, not the app's

The Changed parts section offered all three parts to every car. An EV changes no
oil, and a checkbox nobody will ever tick is one more thing to read past on every
service — so which parts a car records now belongs to the car, the same way its
tabs, its Information rows and its Service history columns already do.

It works the way those three do because a fourth mechanism for the same idea
would be a fourth to keep in step: hidden_service_parts on the car, validated by
the endpoint that already does this, stored as the hidden set so a part added in
a later release is on by default, and needing write access because the choice
belongs to the car and everyone it is shared with sees it.

There is no order beside it, which is the one place this departs from the other
three. Those arrange things whose position means something — a tab bar reads left
to right, a table's columns are read across. The parts are a checkbox list inside
a single column, and moving Cabin air filter above Oil says nothing. Adding one
later is the same shape as the others if that turns out to be wrong.

A part switched off leaves the form and the history together — the chips on the
phone's cards, the web column's summary and the panel it opens. "I don't record
this" means it stops taking up room, not that it takes up room saying nothing,
which is the rule a hidden column already follows. That is the judgment call
here: a car with five years of oil changes hides them all by switching the part
off. Nothing is written to the records, so switching it back on brings every one
of those chips back, which is what makes the call safe to reverse.

The part that would have been a silent data bug: the API rewrites all three
booleans from the body of a service update, so a form that simply stopped
sending a hidden part would set it false on the next edit of any old record.
Both forms therefore keep every part in their state and submit every one — only
the checkboxes are filtered. The mirror of that is a *new* record, where a hidden
part starts false rather than at its `initial`, since ticking a box nobody was
shown is not a default, it's a guess. Oil is the only part with initial: true, so
that case is live the moment anyone hides it.

Verified: go vet and go test ./... pass, with a new test covering that every part
is hideable (unlike the tabs and the columns — a service that changed nothing is
a real service), that the "parts" column key is refused as a part key and a part
key as a column key, and that no part is also a column. flutter analyze is clean
and flutter test passes 32 to 35, the new ones covering visibleParts, that a
hidden part's chips go while its stored boolean stays, and the picker's fourth
section. npm run build is clean.

Both apps were driven against throwaway stub APIs. Web: the picker saved
{"hiddenServiceParts":["oil"]}, the table's parts cell went from "Oil & Oil
filter +2" to "Engine air filter, Cabin air filter", the record whose only part
was oil went to an empty cell, the panel dropped to two rows, the add form
offered two unticked boxes where oil's initial: true would have ticked one, and
editing the three-part record sent changedOil:true back with a box that was never
on screen. Phone: the same car rendered chips "Engine air, Cabin air", "Changed
parts —" for the oil-only record, and an add sheet with exactly two unticked
boxes.

Not verified: no automated test guards the web behaviour — the web app still has
no test runner, so the above was read out of the live DOM and the outgoing
request bodies by hand. The phone's picker was checked by widget test and by
rendering, but its Save was not driven end to end. Neither app was run against
the real API Server: bootstrap appends the new field on the next start, and until
that start a client sending hiddenServiceParts takes a 400 — they deploy together
from this repo, but the server must go first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
tajniak81
2026-08-22 23:30:08 +02:00
co-authored by Claude Opus 5
parent 7718b32013
commit 35e6c511b7
24 changed files with 356 additions and 50 deletions
+4 -3
View File
@@ -194,9 +194,10 @@ POST /api/vehicle-providers/{provider}/import
# which PATCH /api/me {carOrder} sets)
GET /api/cars POST /api/cars
GET /api/cars/{id} PATCH /api/cars/{id} DELETE /api/cars/{id}
PUT /api/cars/{id}/view # which tabs, Information rows and service-history
# columns this car shows, and the order of the tabs,
# the rows, the columns and the provider readings
PUT /api/cars/{id}/view # which tabs, Information rows, service-history
# columns and service parts this car shows, and the
# order of the tabs, the rows, the columns and the
# provider readings
GET /api/cars/{id}/provider POST /api/cars/{id}/provider
POST /api/cars/{id}/provider/sync
GET /api/cars/{id}/service-records GET /api/cars/{id}/technical-checks
+28 -4
View File
@@ -295,6 +295,20 @@ var hideableServiceColumns = map[string]bool{
"notes": true, "file": true,
}
// hideableServiceParts are the parts a service record can say were changed, and
// so the ones a car can take off its list: an EV changes no oil, and offering it
// on every service form is a checkbox nobody there will ever tick. Keys mirror
// SERVICE_PARTS in the web app's lib/serviceParts.js and kServiceParts in the
// phone's service_parts.dart — one per boolean on the service_records
// collection.
//
// Every part is hideable, unlike the tabs and the columns: there is no part the
// form needs, because a service that changed nothing at all is a service with an
// empty Changed parts section, which is a thing that happens.
var hideableServiceParts = map[string]bool{
"oil": true, "engineFilter": true, "cabinFilter": true,
}
// arrangeableServiceColumns are the columns that table can be rearranged into:
// the hideable ones plus Date, which cannot be switched off but has no reason to
// be stuck at the left. Derived from hideableServiceColumns so the two sets
@@ -346,10 +360,11 @@ func normalizeKeys(in []string, allowed map[string]bool, what string) ([]string,
}
// PUT /api/cars/{id}/view — choose what this car's page shows: which tabs, which
// rows of the Information tab, which columns of the Service history table, and
// the order the tabs, the Information rows, those columns and the connected
// service's headline readings are laid out in. Body: {hiddenTabs?: [...],
// hiddenFields?: [...], hiddenServiceColumns?: [...], tabOrder?: [...],
// rows of the Information tab, which columns of the Service history table, which
// parts its service form offers, and the order the tabs, the Information rows,
// those columns and the connected service's headline readings are laid out in.
// Body: {hiddenTabs?: [...], hiddenFields?: [...], hiddenServiceColumns?: [...],
// hiddenServiceParts?: [...], tabOrder?: [...],
// fieldOrder?: [...], serviceColumnOrder?: [...], metricOrder?: [...]}; only the
// lists present are written, so a client can rearrange one group without
// resending the others. Its own endpoint rather than fields on the car edit, so an ordinary
@@ -361,6 +376,7 @@ func (s *Server) updateCarView(w http.ResponseWriter, r *http.Request) {
HiddenTabs *[]string `json:"hiddenTabs"`
HiddenFields *[]string `json:"hiddenFields"`
HiddenServiceColumns *[]string `json:"hiddenServiceColumns"`
HiddenServiceParts *[]string `json:"hiddenServiceParts"`
TabOrder *[]string `json:"tabOrder"`
FieldOrder *[]string `json:"fieldOrder"`
ServiceColumnOrder *[]string `json:"serviceColumnOrder"`
@@ -405,6 +421,14 @@ func (s *Server) updateCarView(w http.ResponseWriter, r *http.Request) {
}
payload["hidden_service_columns"] = columns
}
if in.HiddenServiceParts != nil {
parts, err := normalizeKeys(*in.HiddenServiceParts, hideableServiceParts, "service part")
if err != nil {
writeError(w, http.StatusBadRequest, err.Error())
return
}
payload["hidden_service_parts"] = parts
}
if in.TabOrder != nil {
// A wider set than the hidden tabs: Information is arrangeable although it
// cannot be switched off. A partial list is accepted, and the tabs it
+43
View File
@@ -200,6 +200,49 @@ func TestNormalizeHiddenServiceColumns(t *testing.T) {
}
}
// The parts a service can change hide against their own set — one key per
// boolean on the service_records collection, and no order beside it, because
// they are a checkbox list inside a single column.
func TestNormalizeHiddenServiceParts(t *testing.T) {
got, err := normalizeKeys([]string{" oil ", "cabinFilter", "oil", ""}, hideableServiceParts, "service part")
if err != nil {
t.Fatalf("normalizeKeys: %v", err)
}
assertKeys(t, got, []string{"oil", "cabinFilter"}) // trimmed, blanks dropped, deduped
// Every part is hideable, unlike the tabs and the columns: a service that
// changed nothing is a real service, so there is no part the form must keep.
for _, key := range []string{"oil", "engineFilter", "cabinFilter"} {
if !hideableServiceParts[key] {
t.Errorf("service part %q should be hideable", key)
}
}
if len(hideableServiceParts) != 3 {
t.Errorf("hideableServiceParts has %d entries, want the 3 booleans on a service record", len(hideableServiceParts))
}
// "parts" is the column those three share; it is not one of them. Sending
// the column key here would hide nothing and quietly succeed if the two sets
// were not kept apart.
if _, err := normalizeKeys([]string{"parts"}, hideableServiceParts, "service part"); err == nil {
t.Error("normalizeKeys accepted the parts column as a part, want an error")
}
if _, err := normalizeKeys([]string{"notes"}, hideableServiceParts, "service part"); err == nil {
t.Error("normalizeKeys accepted a column key as a service part, want an error")
}
if _, err := normalizeKeys([]string{"oil", "nonsense"}, hideableServiceParts, "service part"); err == nil {
t.Error("normalizeKeys accepted an unknown service part, want an error")
}
// And no part is a column, which is what keeps the table from widening as
// parts are added.
for key := range hideableServiceParts {
if arrangeableServiceColumns[key] {
t.Errorf("service part %q must not also be a column", key)
}
}
}
// The columns arrange against a wider set than they hide against, the way the
// tabs do: the date cannot be switched off, but it can be moved off the left.
func TestNormalizeServiceColumnOrder(t *testing.T) {
+4 -1
View File
@@ -68,7 +68,8 @@ type carRecord struct {
Created string `json:"created"`
Updated string `json:"updated"`
// Switched-off tabs, Information fields and Service history columns, plus
// Switched-off tabs, Information fields, Service history columns and service
// parts, plus
// the arrangements of the tabs, the Information rows, those columns and the
// connected service's readings. Raw
// because PocketBase hands back whatever a json field holds — null on a car
@@ -76,6 +77,7 @@ type carRecord struct {
HiddenTabs json.RawMessage `json:"hidden_tabs"`
HiddenFields json.RawMessage `json:"hidden_fields"`
HiddenServiceColumns json.RawMessage `json:"hidden_service_columns"`
HiddenServiceParts json.RawMessage `json:"hidden_service_parts"`
TabOrder json.RawMessage `json:"tab_order"`
FieldOrder json.RawMessage `json:"field_order"`
ServiceColumnOrder json.RawMessage `json:"service_column_order"`
@@ -109,6 +111,7 @@ func (rec carRecord) toModel() models.Car {
HiddenTabs: decodeStringList(rec.HiddenTabs),
HiddenFields: decodeStringList(rec.HiddenFields),
HiddenServiceColumns: decodeStringList(rec.HiddenServiceColumns),
HiddenServiceParts: decodeStringList(rec.HiddenServiceParts),
TabOrder: decodeStringList(rec.TabOrder),
FieldOrder: decodeStringList(rec.FieldOrder),
ServiceColumnOrder: decodeStringList(rec.ServiceColumnOrder),
+3
View File
@@ -52,6 +52,9 @@ var collectionsSchema = map[string][]fieldDef{
// never records what was changed). Date is not hideable and so never
// appears here.
fJSON("hidden_service_columns", 2000),
// And the parts its services never change (["oil"] on an EV), which come
// off the service form and out of that column together.
fJSON("hidden_service_parts", 2000),
// The order the tabs are laid out in, as tab keys, the same for the
// Information rows, the Service history columns, and the connected
// service's headline readings. Empty means the page's own default order.
+10
View File
@@ -91,6 +91,16 @@ type Car struct {
// nothing.
HiddenServiceColumns []string `json:"hiddenServiceColumns"`
// HiddenServiceParts is the parts this car's services never change, as part
// keys (["oil"] on an EV, which has none to change). They come off the
// Changed parts section of the service form and out of the history's parts
// column together: a part nobody records is one nobody wants offered either.
// The hidden set like the ones above, so a part added later is on by
// default, and there is no order beside it — the parts are a checkbox list
// inside one column, and their position says nothing a tab's or a column's
// does.
HiddenServiceParts []string `json:"hiddenServiceParts"`
// ServiceColumnOrder is the arrangement of those columns, covering the
// hidden ones so a column switched back on returns to where it was. It does
// include "date", which cannot be switched off but can be moved off the