[openstreetmap/openstreetmap-website] sidebar_classic_pagination - width calculation not clear (Issue #5105)

mmd notifications at github.com
Wed Aug 21 20:44:25 UTC 2024


I've noticed that in some cases, pagination cells are very narrow, in particular when we're showing two disabled cells ("..."), like in example 1 below.

To calculate a threshold value, we're currently applying the following logic:

```
      width += body.length
```

I'm wondering why we're not taking the actual length of the strings we're showing on the screen into account. So instead of the previous calculation, that would be:

```
      width += body.first.length
```

### Example 1


![image](https://github.com/user-attachments/assets/5067cd13-3d76-4132-9b11-e1cd188ed687)

Debug output:

```
====
["1", 1] --- 2
["...", "disabled"] --- 2
["5", 5] --- 2
["6", 6] --- 2
["7", "active"] --- 2
["8", 8] --- 2
["9", 9] --- 2
["...", "disabled"] --- 2
["11", 11] --- 2
====
36
====
```

### Example 2


![image](https://github.com/user-attachments/assets/80d786d2-9014-4e0a-8a1f-e32613099d6c)

Debug output:

```
====
["1", 1] --- 2
["2", 2] --- 2
["3", "active"] --- 2
["4", 4] --- 2
["5", 5] --- 2
["...", "disabled"] --- 2
["11", 11] --- 2
====
28
====
```


### Debug code


```ruby
  def sidebar_classic_pagination(pages, page_param)
    max_width_for_default_padding = 35

    puts "===="
    width = 0
    pagination_items(pages, {}).each do |body|
      width += 2 # padding width
      width += body.length
      puts "#{body} --- #{body.length}"
    end
    puts "===="
    puts width
    puts "===="
    link_classes = ["page-link", { "px-1" => width > max_width_for_default_padding }]
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/5105
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/issues/5105 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240821/f624d2a3/attachment.htm>


More information about the rails-dev mailing list