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
fix(people): sort with the person open now, not the one first loaded
Guido Boyke2c0689e66cdf
diff --git a/app/javascript/controllers/layout_toggle_controller.js b/app/javascript/controllers/layout_toggle_controller.jsindex 2c0ec64..4ef202c 100644--- a/app/javascript/controllers/layout_toggle_controller.js+++ b/app/javascript/controllers/layout_toggle_controller.js@@ -1,6 +1,6 @@import { Controller } from "@hotwired/stimulus"import { readLaneParams, laneParamNames } from "lane/params"-import { controlIndexPath, indexPaths } from "lane/filter_context"+import { controlIndexPath, indexPaths, withLiveLane } from "lane/filter_context"import { escapeOwned } from "escape_owner"// The fixed-height list/detail grids (Tickets table, Knowledge, Meetings) fill the@@ -306,7 +306,12 @@ export default class extends Controller {if (address.origin !== current.origin || !index) continue// List links intentionally change page, sort or view. Only explicit lane- // return links inherit the current list state at the index route.+ // return links inherit the current list state at the index route; a list+ // link marked data-lane-keep takes the lane open now (lib/lane/filter_context).+ if (control.tagName === 'A' && path === index && control.matches('[data-lane-keep]')) {+ control.setAttribute(attribute, withLiveLane(address, current, this.laneNames).toString())+ continue+ }if (control.tagName === 'A' && path === index && !control.matches('[data-lane-back], [data-form-lane-back], [data-lane-close]')) continueconst previousInputs = new URLSearchParams()diff --git a/app/javascript/lib/lane/filter_context.js b/app/javascript/lib/lane/filter_context.jsindex f2e656c..9886630 100644--- a/app/javascript/lib/lane/filter_context.js+++ b/app/javascript/lib/lane/filter_context.js@@ -28,3 +28,17 @@ export function indexPaths(pageIndexUrl, laneIndexUrls, origin) {const paths = [pageIndexUrl, ...laneIndexUrls].filter(Boolean).map((url) => new URL(url, origin).pathname)return [...new Set(paths)]}++// A list link that keeps the lane (data-lane-keep, the sort heads of the+// people list) was rendered with the selection of the page request. A row+// click changes the open object in the address only, so at click time the+// link takes the lane part of the live address instead: the object open now,+// or none once the lane was closed. Returns a new URL.+export function withLiveLane(address, current, laneNames) {+ const result = new URL(address.toString())+ for (const name of laneNames) {+ result.searchParams.delete(name)+ for (const value of current.searchParams.getAll(name)) result.searchParams.append(name, value)+ }+ return result+}diff --git a/app/views/organisations/people/_results.html.erb b/app/views/organisations/people/_results.html.erbindex 950ded7..8269917 100644--- a/app/views/organisations/people/_results.html.erb+++ b/app/views/organisations/people/_results.html.erb@@ -4,7 +4,9 @@right. Every row opens the lane: a person row through person_id, a memberwithout a row through member_id. The two column heads sort the list(?sort=last, E5), a full visit that keeps search, filter and the open- person. %>+ person. The person is rendered from this request; a row click changes it+ in the address only, so data-lane-keep takes the live one at click time+ (layout_toggle#syncFilterContext). %><% open_lane = request.query_parameters.slice('person_id', 'member_id').select { |_key, value| value.is_a?(String) } %><turbo-frame id="<%= Organisations::PeopleController::LIST_FRAME_ID %>"><% if entries.any? %>@@ -18,7 +20,7 @@<%= tag.span class: "people-columns__head #{head_class}" do %><%= link_to organisation_people_path(@current_organisation, list_state.except('sort').merge(key == 'last' ? { 'sort' => 'last' } : {}).merge(open_lane)),class: "people-columns__link #{'people-columns__link--active' if active}", 'aria-current': (active ? 'true' : nil),- data: { turbo_frame: '_top' } do %>+ data: { turbo_frame: '_top', lane_keep: true } do %><%= t("views.organisations.people.index.columns.#{key}") %><% if active %><i class="bi bi-arrow-down" aria-hidden="true"></i><span class="sr-only"><%= t('views.organisations.people.index.columns.sorted') %></span><% end %><% end %>diff --git a/spec/javascript/controllers/layout_toggle_controller.test.js b/spec/javascript/controllers/layout_toggle_controller.test.jsindex 1ec210e..5543186 100644--- a/spec/javascript/controllers/layout_toggle_controller.test.js+++ b/spec/javascript/controllers/layout_toggle_controller.test.js@@ -3,7 +3,7 @@ import assert from 'node:assert/strict'import { readFileSync } from 'node:fs'import { runInNewContext } from 'node:vm'import { laneParamNames } from '../../../app/javascript/lib/lane/params.js'-import { controlIndexPath, indexPaths } from '../../../app/javascript/lib/lane/filter_context.js'+import { controlIndexPath, indexPaths, withLiveLane } from '../../../app/javascript/lib/lane/filter_context.js'import { escapeOwned } from '../../../app/javascript/lib/escape_owner.js'const source = readFileSync(new URL('../../../app/javascript/controllers/layout_toggle_controller.js', import.meta.url), 'utf8')@@ -17,7 +17,7 @@ function controllerWith(document, { window = {}, groups = null, element = null }CustomEvent: class {constructor(type, options) { this.type = type; Object.assign(this, options) }},- readLaneParams: () => groups, laneParamNames, controlIndexPath, indexPaths, escapeOwned+ readLaneParams: () => groups, laneParamNames, controlIndexPath, indexPaths, withLiveLane, escapeOwned})const controller = new Controller()controller.listFilterParamsValue = []@@ -259,7 +259,8 @@ test('list navigation retains its destination while lane return links inherit cutagName: 'A', href,getAttribute() { return this.href },setAttribute(_name, value) { this.href = value },- matches() { return lane }+ // A return link answers to the lane return selectors, never to data-lane-keep.+ matches(selector) { return lane && !selector.includes('data-lane-keep') }})const destinations = ['/meetings?page=4&meeting_id=M',@@ -288,6 +289,31 @@ test('list navigation retains its destination while lane return links inherit cu}})+// Review of PR #51: the sort heads of the people list are list links that+// keep the lane (data-lane-keep). They were rendered with the person of the+// page request; at click time they take the person open now, or none.+test('a list link marked data-lane-keep takes the live selection and keeps its own list state', () => {+ const link = {+ tagName: 'A', href: '/org/o/people?q=an&sort=last&person_id=A',+ getAttribute() { return this.href },+ setAttribute(_name, value) { this.href = value },+ matches(selector) { return selector === '[data-lane-keep]' }+ }+ const element = {+ dataset: { indexUrl: '/org/o/people' },+ querySelectorAll: selector => selector === '[data-lane-index-url]' ? [] : [link]+ }+ const groups = { selection: ['person_id', 'member_id'], preview: [], form: ['new', 'user_id'], ignore: ['viewport'] }+ const controller = controllerWith({}, { element, groups })+ controller.listFilterParamsValue = ['q', 'kind', 'sort']++ controller.syncFilterContext(new URL('http://lalabase.test/org/o/people?q=an&member_id=M'))+ assert.equal(new URL(link.href).search, '?q=an&sort=last&member_id=M')++ controller.syncFilterContext(new URL('http://lalabase.test/org/o/people?q=an'))+ assert.equal(new URL(link.href).search, '?q=an&sort=last')+})+// "Alle Meetings" shows a project's meeting in its lane (PR 3 of// doc/meetings_uebersicht_vereinheitlichen_plan.md): its controls live below the// project's meetings index, which the lane head names. They take the list state@@ -298,7 +324,7 @@ test('a lane of another list takes the list state on the index its head names',tagName, href, method: 'post',getAttribute() { return this.href },setAttribute(_name, value) { this.href = value },- matches() { return matched },+ matches(selector) { return matched && !selector.includes('data-lane-keep') },querySelectorAll: () => [],append() {}})diff --git a/spec/javascript/lib/lane/filter_context.test.js b/spec/javascript/lib/lane/filter_context.test.jsindex 1e53a22..852b429 100644--- a/spec/javascript/lib/lane/filter_context.test.js+++ b/spec/javascript/lib/lane/filter_context.test.js@@ -8,7 +8,7 @@// another list (a linked ticket) must stay as it is.import { test } from "node:test"import assert from "node:assert/strict"-import { controlIndexPath, indexPaths } from "../../../../app/javascript/lib/lane/filter_context.js"+import { controlIndexPath, indexPaths, withLiveLane } from "../../../../app/javascript/lib/lane/filter_context.js"const ORIGIN = "http://x.test"const OVERVIEW = "/org/o1/meetings"@@ -42,3 +42,23 @@ test("a control of another list or a path that only starts alike is left alone",test("the same index twice is one, and full addresses become paths", () => {assert.deepEqual(indexPaths(`${ORIGIN}${PROJECT}?search=x`, [PROJECT, null], ORIGIN), [PROJECT])})++// Review of PR #51: a sort head is a list link, rendered with the selection+// of the page request. A row click changes the open person in the address+// only, so at click time the link takes the lane part of the live address:+// the person open now, or none when the lane was closed.+test("a link that keeps the lane takes the live selection, not the rendered one", () => {+ const names = ["person_id", "member_id"]+ const link = new URL(`${ORIGIN}/org/o1/people?sort=last&person_id=a`)++ const switched = withLiveLane(link, new URL(`${ORIGIN}/org/o1/people?person_id=b`), names)+ assert.equal(switched.search, "?sort=last&person_id=b")++ const member = withLiveLane(link, new URL(`${ORIGIN}/org/o1/people?member_id=m`), names)+ assert.equal(member.search, "?sort=last&member_id=m")++ const closed = withLiveLane(link, new URL(`${ORIGIN}/org/o1/people`), names)+ assert.equal(closed.search, "?sort=last")++ assert.equal(link.search, "?sort=last&person_id=a", "the rendered address is not changed in place")+})diff --git a/spec/requests/organisations/people_last_contact_spec.rb b/spec/requests/organisations/people_last_contact_spec.rbindex e4b120f..27586e9 100644--- a/spec/requests/organisations/people_last_contact_spec.rb+++ b/spec/requests/organisations/people_last_contact_spec.rb@@ -98,6 +98,10 @@ RSpec.describe 'Organisations::People last contact', :ci_guard, type: :request dhead = response.body[%r{<div class="people-columns"[\s\S]*?</div>}]expect(head).to include(CGI.escapeHTML(organisation_people_path(organisation, sort: 'last', person_id: contact.id)))+ # A row click changes the person in the address only: both heads take+ # the live one at click time (layout_toggle#syncFilterContext,+ # spec/system/people_sort_keeps_lane_spec.rb).+ expect(head.scan('data-lane-keep="true"').size).to eq(2)endit 'drops an unknown sort from every link' dodiff --git a/spec/system/people_sort_keeps_lane_spec.rb b/spec/system/people_sort_keeps_lane_spec.rbnew file mode 100644index 0000000..4e24272--- /dev/null+++ b/spec/system/people_sort_keeps_lane_spec.rb@@ -0,0 +1,62 @@+# frozen_string_literal: true++require 'rails_helper'++# Review of PR #51: the column heads of the people list are rendered with the+# selection of the page request. A row click changes the open person in the+# address and reloads only the lane, so only the browser shows whether a sort+# keeps the person open NOW (layout_toggle#syncFilterContext, data-lane-keep).+RSpec.describe 'People list sort keeps the open person', type: :system do+ let(:organisation) { create(:organisation) }+ let(:user) { create(:user, first_name: 'Anna', last_name: 'Beispiel') }++ before do+ Prosopite.pause+ ActsAsTenant.current_tenant = organisation+ role = create(:role, organisation: organisation, title: Role::ACCOUNT_ADMIN_TITLE)+ create(:membership, user: user, organisation: organisation, role: role, active: true)+ create(:person, organisation: organisation, name: 'Berta Erste')+ create(:person, organisation: organisation, name: 'Clara Zweite')+ sign_in user+ end++ after do+ ActsAsTenant.current_tenant = nil+ Prosopite.resume+ end++ def lane+ find("turbo-frame##{Organisations::PeopleController::DETAIL_FRAME_ID}")+ end++ it 'sorts with the person opened by a row click, not the one the page was loaded with' do+ berta = Person.find_by!(name: 'Berta Erste')+ clara = Person.find_by!(name: 'Clara Zweite')+ visit organisation_people_path(organisation, person_id: berta.id)+ expect(lane).to have_text('Berta Erste')++ find('.people-row', text: 'Clara Zweite').click+ expect(page).to have_current_path(/person_id=#{clara.id}/)+ expect(lane).to have_text('Clara Zweite')++ click_link I18n.t('views.organisations.people.index.columns.last')++ expect(page).to have_current_path(/sort=last/)+ expect(page).to have_current_path(/person_id=#{clara.id}/)+ expect(lane).to have_text('Clara Zweite')+ end++ it 'sorts without a person once the lane was closed' do+ berta = Person.find_by!(name: 'Berta Erste')+ visit organisation_people_path(organisation, person_id: berta.id)+ expect(lane).to have_text('Berta Erste')++ find('body').send_keys(:escape)+ expect(page).to have_no_current_path(/person_id=/)++ click_link I18n.t('views.organisations.people.index.columns.last')++ expect(page).to have_current_path(/sort=last/)+ expect(page).to have_no_current_path(/person_id=/)+ end+end