Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Ask checkVisibility in a way every admitted browser understands
Guido Boyke96479e0b2be2
diff --git a/app/javascript/controllers/assistant_panel_controller.js b/app/javascript/controllers/assistant_panel_controller.jsindex bfa2ea9..a8e9400 100644--- a/app/javascript/controllers/assistant_panel_controller.js+++ b/app/javascript/controllers/assistant_panel_controller.js@@ -868,7 +868,7 @@ export default class extends Controller {for (const marker of document.querySelectorAll("[data-assistant-context]")) {if (this.element.contains(marker)) continueif (marker.closest(".layout.hide-content")) continue- if (marker.checkVisibility?.({ visibilityProperty: true }) === false) continue+ if (!this.pageContextVisible(marker)) continueconst id = marker.dataset.assistantContextconst type = marker.dataset.assistantContextType@@ -885,6 +885,17 @@ export default class extends Controller {return contexts}+ // Asked with the option's original name: allow_browser :modern admits Chrome 120 and+ // Firefox 121, which ignore the newer visibilityProperty (and so answer only for+ // display:none); every later version still takes the old name. Safari before 17.4+ // has no checkVisibility: a box says display:none, and visibility is inherited.+ pageContextVisible(marker) {+ if (typeof marker.checkVisibility === "function") {+ return marker.checkVisibility({ checkVisibilityCSS: true })+ }+ return marker.getClientRects().length > 0 && getComputedStyle(marker).visibility === "visible"+ }+// Which objects the thread points at right now, read off the chip the server// rendered, as the raw space-separated key list. Same channel as openThreadId,// and for the same reason: the server never gets to tell this node anything.diff --git a/spec/javascript/controllers/assistant_panel_visibility.test.js b/spec/javascript/controllers/assistant_panel_visibility.test.jsnew file mode 100644index 0000000..9fdbc3d--- /dev/null+++ b/spec/javascript/controllers/assistant_panel_visibility.test.js@@ -0,0 +1,83 @@+// What: which page objects the assistant counts as seen (assistant_panel_controller+// #pageContextVisible, used by #pageContexts), in each browser the application admits.+// Type: node:test over the controller's source with fake markers; no browser.+// Why: allow_browser :modern admits Chrome 120, Firefox 121 and Safari 17.2. The first+// two know checkVisibility only with its original option name (checkVisibilityCSS) and+// ignore the newer visibilityProperty; Safari before 17.4 has no checkVisibility at+// all. Asked the wrong way, both offered the meeting hidden behind the ticket tab at+// the narrow stage (doc/ticket_meeting_panel_plan.md S2, S3), and the fakes of+// assistant_panel_page_contexts.test.js answer any question, so they could not tell.+import { test } from "node:test"+import assert from "node:assert/strict"+import { readFileSync } from "node:fs"+import { runInNewContext } from "node:vm"++const source = readFileSync(new URL("../../../app/javascript/controllers/assistant_panel_controller.js", import.meta.url), "utf8")+ .replace(/^import .*\n/gm, "")+ .replace("export default class", "class AssistantPanelController")++function marker({ id = "meeting", hasBox = true, visibility = "visible", closedLane = false, inAssistant = false } = {}) {+ return {+ dataset: { assistantContext: id, assistantContextType: "Meeting", assistantContextLabel: id },+ visibility, hasBox, inAssistant,+ closest: () => (closedLane ? {} : null),+ getClientRects: () => (hasBox ? [{}] : [])+ }+}++// With the API, the marker answers as Chrome 120 and Firefox 121 do: only the original+// option name makes it look at the visibility property. Without it, Safari 17.2.+function fixture(markers, visibilityAPI) {+ if (visibilityAPI) {+ for (const each of markers) {+ each.checkVisibility = ({ checkVisibilityCSS = false } = {}) =>+ each.hasBox && (!checkVisibilityCSS || each.visibility === "visible")+ }+ }+ const Controller = runInNewContext(`${source}\nAssistantPanelController`, {+ Controller: class {},+ document: { querySelectorAll: () => markers },+ getComputedStyle: each => ({ visibility: each.visibility })+ })+ const controller = new Controller()+ controller.element = { contains: each => each.inAssistant }+ return controller+}++// The controller runs in its own realm: its arrays are not this realm's arrays.+const keysOf = controller => Array.from(controller.pageContexts(), context => context.key)++for (const visibilityAPI of [true, false]) {+ const browser = visibilityAPI ? "checkVisibility with its original options" : "no checkVisibility"++ test(`${browser}: a visible meeting is on offer`, () => {+ assert.deepEqual(keysOf(fixture([marker()], visibilityAPI)), ["Meeting:meeting"])+ })++ for (const [state, options] of [+ ["a closed panel (display:none)", { hasBox: false }],+ ["the column behind the other tab (visibility:hidden)", { visibility: "hidden" }],+ ["visibility:collapse", { visibility: "collapse" }]+ ]) {+ test(`${browser}: ${state} is not on offer`, () => {+ assert.deepEqual(keysOf(fixture([marker(options)], visibilityAPI)), [])+ })+ }++ test(`${browser}: hidden markers do not keep a later visible one from the offer`, () => {+ const controller = fixture([+ marker({ id: "closed", hasBox: false }),+ marker({ id: "behind", visibility: "hidden" }),+ marker({ id: "visible" })+ ], visibilityAPI)+ assert.deepEqual(keysOf(controller), ["Meeting:visible"])+ })++ test(`${browser}: a citation in the assistant and a closed lane stay out`, () => {+ const controller = fixture([+ marker({ id: "citation", inAssistant: true }),+ marker({ id: "closing", closedLane: true })+ ], visibilityAPI)+ assert.deepEqual(keysOf(controller), [])+ })+}