oficina / estilo Public

Merge main (switcher tiles) into fix/connect-item-when-linked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 1817c1c6c7efed114707b63ca4ccbf94e5e72ffb parent 0b375d5parent d53b8e9
3 files changed, +138 −0
  • chrome/chrome.css +9 −0
  • chrome/suite.go +46 −0
  • chrome/suite_test.go +83 −0

CI failed — run details

diff --git a/chrome/chrome.css b/chrome/chrome.css
index 71c0490..d16395d 100644
--- a/chrome/chrome.css
+++ b/chrome/chrome.css
@@ -184,6 +184,15 @@
[estilo-switcher-app]:focus-visible { background: var(--rst-accent-soft); }
[estilo-switcher-app][aria-current] { background: var(--rst-accent-soft); font-weight: 600; }
[estilo-switcher-app] img { border-radius: 21%; }
+/* Three 5.5rem tiles hung from the trigger overflow a phone's inline start
+ (at 320px, and sooner when the corner is the wider "Sign in" link), so
+ below 30rem the panel spans the bar instead, as menubar panels do, and
+ the three columns share its width. */
+@media (max-width: 30rem) {
+ [estilo-switcher] { position: static; }
+ [estilo-switcher-panel] { inset-inline: 0.5rem; inline-size: auto; min-inline-size: 0; max-inline-size: none; }
+ [estilo-switcher-grid] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
+}
/* The account menu. The account is always the last thing at the inline
end of the bar: the "same corner" rule. */
diff --git a/chrome/suite.go b/chrome/suite.go
new file mode 100644
index 0000000..d2a9b07
--- /dev/null
+++ b/chrome/suite.go
@@ -0,0 +1,46 @@
+package chrome
+
+import (
+ "net/url"
+ "strings"
+
+ "amadan.net/oficina/estilo.git/brand"
+)
+
+// suite is the apps registered with the suite's identity service, in the
+// switcher's order: slug, then product name (the same in every locale).
+// Fichas, Mail and Files are deliberately absent; they are not registered.
+var suite = []struct{ slug, name string }{
+ {"docs", "Docs"},
+ {"sheets", "Sheets"},
+ {"slides", "Slides"},
+ {"calendar", "Calendar"},
+ {"memoria", "Memoria"},
+ {"calls", "Calls"},
+}
+
+// SuiteApps is the switcher's tiles for the app whose slug is current,
+// derived from the hub directory's origin: an app's host is its slug
+// under the directory's host, so "https://oficina.works" gives
+// "https://docs.oficina.works/". Icons are brand.Path(slug), so every
+// caller must mount brand.Handler().
+//
+// It returns nil when directory is not an absolute origin, which leaves
+// the switcher as the "All apps" link alone. A current slug that is not
+// in the suite marks no tile.
+func SuiteApps(directory, current string) []SwitcherApp {
+ u, err := url.Parse(strings.TrimSuffix(directory, "/"))
+ if err != nil || (u.Scheme != "https" && u.Scheme != "http") || u.Host == "" || u.User != nil || (u.Path != "" && u.Path != "/") || u.RawQuery != "" || u.Fragment != "" {
+ return nil
+ }
+ apps := make([]SwitcherApp, len(suite))
+ for i, app := range suite {
+ apps[i] = SwitcherApp{
+ Name: app.name,
+ Href: u.Scheme + "://" + app.slug + "." + u.Host + "/",
+ Icon: brand.Path(app.slug),
+ Current: app.slug == current,
+ }
+ }
+ return apps
+}
diff --git a/chrome/suite_test.go b/chrome/suite_test.go
new file mode 100644
index 0000000..579ef7c
--- /dev/null
+++ b/chrome/suite_test.go
@@ -0,0 +1,83 @@
+package chrome
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestSuiteAppsDerivesEachAppFromTheDirectory(t *testing.T) {
+ apps := SuiteApps("https://oficina.works", "sheets")
+ want := []SwitcherApp{
+ {Name: "Docs", Href: "https://docs.oficina.works/", Icon: "/static/estilo/brand/docs.svg"},
+ {Name: "Sheets", Href: "https://sheets.oficina.works/", Icon: "/static/estilo/brand/sheets.svg", Current: true},
+ {Name: "Slides", Href: "https://slides.oficina.works/", Icon: "/static/estilo/brand/slides.svg"},
+ {Name: "Calendar", Href: "https://calendar.oficina.works/", Icon: "/static/estilo/brand/calendar.svg"},
+ {Name: "Memoria", Href: "https://memoria.oficina.works/", Icon: "/static/estilo/brand/memoria.svg"},
+ {Name: "Calls", Href: "https://calls.oficina.works/", Icon: "/static/estilo/brand/calls.svg"},
+ }
+ if len(apps) != len(want) {
+ t.Fatalf("got %d tiles, want %d: %+v", len(apps), len(want), apps)
+ }
+ for i := range want {
+ if apps[i] != want[i] {
+ t.Errorf("tile %d = %+v, want %+v", i, apps[i], want[i])
+ }
+ }
+ // A trailing slash and a port are the directory's own; both carry over.
+ if got := SuiteApps("http://oficina.localhost:8080/", "calls")[5]; got.Href != "http://calls.oficina.localhost:8080/" || !got.Current {
+ t.Fatalf("calls tile = %+v", got)
+ }
+}
+
+func TestSuiteAppsMarksNothingForAnUnknownApp(t *testing.T) {
+ for _, current := range []string{"", "fichas", "meet", "Docs"} {
+ for _, app := range SuiteApps("https://oficina.works", current) {
+ if app.Current {
+ t.Errorf("current %q marks %s", current, app.Name)
+ }
+ }
+ }
+}
+
+func TestSuiteAppsNeedsAnOrigin(t *testing.T) {
+ for _, directory := range []string{"", "oficina.works", "/apps", "ftp://oficina.works", "https://oficina.works/apps", "https://u@oficina.works", "https://oficina.works?x=1", "https://oficina.works#x", "https://"} {
+ if apps := SuiteApps(directory, "docs"); apps != nil {
+ t.Errorf("SuiteApps(%q) = %+v, want nil", directory, apps)
+ }
+ }
+}
+
+func TestSwitcherRendersSuiteTilesAboveAllApps(t *testing.T) {
+ b := signedIn("x")
+ b.Switcher.Apps = SuiteApps("https://oficina.example", "slides")
+ b.Switcher.CurrentLabel = "x-thisapp"
+ html := render(t, "estilo-bar", b)
+ panel := html[strings.Index(html, "<div estilo-menu estilo-switcher-panel>"):]
+ panel = panel[:strings.Index(panel, "</details>")]
+
+ grid, rest, ok := strings.Cut(panel, "<hr>")
+ if !ok || !strings.Contains(grid, "<div estilo-switcher-grid>") {
+ t.Fatal("no grid above a divider", panel)
+ }
+ if !strings.Contains(rest, `href="https://oficina.example/"`) || !strings.Contains(rest, "x-allapps") || strings.Contains(rest, "estilo-switcher-app") {
+ t.Fatal("All apps is not alone below the divider", rest)
+ }
+ if n := strings.Count(grid, "<a estilo-switcher-app "); n != 6 {
+ t.Fatalf("%d tiles, want 6", n)
+ }
+ last := -1
+ for _, name := range []string{"Docs", "Sheets", "Slides", "Calendar", "Memoria", "Calls"} {
+ i := strings.Index(grid, "<span>"+name)
+ if i < last {
+ t.Fatalf("%s is missing or out of order", name)
+ }
+ last = i
+ }
+ current := `<a estilo-switcher-app href="https://slides.oficina.example/" aria-current="true"><img src="/static/estilo/brand/slides.svg" alt="" width="32" height="32"><span>Slides<span estilo-visually-hidden> x-thisapp</span></span></a>`
+ if !strings.Contains(grid, current) {
+ t.Fatal("the current tile is not marked", grid)
+ }
+ if strings.Count(grid, "aria-current") != 1 || strings.Count(grid, "x-thisapp") != 1 {
+ t.Fatal("more than one tile is current", grid)
+ }
+}