keystone_ui 0.81.0 → 0.83.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3516b268acea8768fce1e6047f13603e698cd447fe6e3fa0f22fed56fca71fb
4
- data.tar.gz: 2da41656eefaec66eea22dca56955a7410b91b6cce7c5d5f4459172a86f42de0
3
+ metadata.gz: 67a56427f22ff9c7ae35a6c75cb9b093685ad735f4aa74d6369becb3cfd43a7c
4
+ data.tar.gz: 2d62089b40ae9778a19603c4ef693aa3a97742defe3b7d54d15dc0b46702622f
5
5
  SHA512:
6
- metadata.gz: 5d4b015f5d4821117e4af16452ac86a0f935b39b365730e093b1d7789641d878bcd691573e1c9efe5618d109743080b88f3389ac2d74b403adb1004ba131dc9e
7
- data.tar.gz: 4baae133e97445b05547688c777a95d10415ad9f5adc0a1af8bd9a0efdbc6317a28a4437a4e449be2f62bb7d3450ea49fee8c959702bfccf1132813d927c80aa
6
+ metadata.gz: d5fed99a13700d260fcfbc176eb29c4a1292711a3452524f5022b2a0865dabacccb417391a1e8594e49cae99e8ec87178c836915b955cdc61f82f3fa736fc636
7
+ data.tar.gz: a629ce6735d60acd71d5adf22fd0b03837b3b18344cc00938225762c08551e29c7fa6132d08956148fc564d48ec74884783751189c827e0f3ba3a0bfe35b87d3
@@ -1,22 +1,29 @@
1
- <div class="flex flex-col gap-3">
2
- <% rows.each do |row| %>
3
- <div data-timeline-row>
4
- <div class="<%= ROW_TEXT_CLASSES %>">
5
- <span data-timeline-label><%= row[:label] %></span>
6
- <span data-timeline-duration><%= duration(row) %></span>
7
- </div>
8
- <div class="<%= TRACK_CLASSES %>">
9
- <% row[:tries].each do |entry| %>
10
- <% if entry[:queued_at] %>
11
- <div class="<%= QUEUED_CLASSES %>" data-timeline-queued style="<%= queued_style(entry) %>"></div>
1
+ <% if entries.empty? %>
2
+ <%= render Keystone::Ui::EmptyStateComponent.new(title: "No steps") %>
3
+ <% else %>
4
+ <div class="flex flex-col gap-3">
5
+ <% rows.each do |row| %>
6
+ <div data-timeline-row<% if selected?(row) %> class="<%= SELECTED_ROW_CLASSES %>" aria-current="true"<% end %>>
7
+ <div class="<%= ROW_TEXT_CLASSES %>">
8
+ <%= content_tag(row_href(row) ? :a : :span, row[:label], data: { timeline_label: "" }, href: row_href(row)) %>
9
+ <span class="<%= ROW_STATUS_CLASSES %>">
10
+ <% if running?(row) %><%= render Keystone::Ui::StatusDotComponent.new(state: :info, label: "Running") %><% end %>
11
+ <span data-timeline-duration><%= duration(row) %></span>
12
+ </span>
13
+ </div>
14
+ <div class="<%= TRACK_CLASSES %>">
15
+ <% row[:tries].each do |entry| %>
16
+ <% if entry[:queued_at] %>
17
+ <div class="<%= QUEUED_CLASSES %>" data-timeline-queued style="<%= queued_style(entry) %>"></div>
18
+ <% end %>
19
+ <%= content_tag(bar_tag(entry), class: bar_classes(entry), data: { timeline_bar: "" }, style: bar_style(entry), href: entry[:href]) do %><% if entry[:href] %><span class="<%= SCREEN_READER_CLASSES %>"><%= entry[:label] %></span> <% end %><% if entry[:failed] %><span class="<%= SCREEN_READER_CLASSES %>">Failed</span><% end %><% end %>
12
20
  <% end %>
13
- <div class="<%= bar_classes(entry) %>" data-timeline-bar style="<%= bar_style(entry) %>"><% if entry[:failed] %><span class="<%= SCREEN_READER_CLASSES %>">Failed</span><% end %></div>
14
- <% end %>
21
+ </div>
15
22
  </div>
23
+ <% end %>
24
+ <div class="<%= AXIS_CLASSES %>">
25
+ <span data-timeline-axis-start><%= axis_start_label %></span>
26
+ <span data-timeline-axis-end><%= total_duration %></span>
16
27
  </div>
17
- <% end %>
18
- <div class="<%= AXIS_CLASSES %>">
19
- <span data-timeline-axis-start><%= axis_start_label %></span>
20
- <span data-timeline-axis-end><%= total_duration %></span>
21
28
  </div>
22
- </div>
29
+ <% end %>
@@ -8,23 +8,39 @@ module Keystone
8
8
  FAILED_CLASSES = "ks-timeline-failed"
9
9
  QUEUED_CLASSES = "ks-timeline-queued absolute inset-y-0"
10
10
  SCREEN_READER_CLASSES = "sr-only"
11
+ SELECTED_ROW_CLASSES = "ks-table-row-current"
11
12
  ROW_TEXT_CLASSES = "ks-meter-label flex justify-between text-sm"
12
13
  AXIS_CLASSES = "ks-meter-label flex justify-between text-xs"
14
+ ROW_STATUS_CLASSES = "flex items-center ks-grid-gap-sm"
15
+ MINIMUM_BAR_PERCENT = 2
13
16
 
14
17
  attr_reader :entries
15
18
 
16
19
  def initialize(entries:)
20
+ entries.each { |entry| check_times(entry) }
17
21
  @entries = entries
18
22
  end
19
23
 
20
24
  def bar_style(entry)
21
- "left: #{percent(entry[:started_at] - axis_start)}%; width: #{percent(entry[:ended_at] - entry[:started_at])}%"
25
+ "left: #{percent(entry[:started_at] - axis_start)}%; width: #{bar_width(entry)}%"
22
26
  end
23
27
 
24
28
  def rows
25
29
  entries.group_by { |entry| entry[:label] }.map { |label, tries| { label: label, tries: tries } }
26
30
  end
27
31
 
32
+ def row_href(row)
33
+ row[:tries].filter_map { |entry| entry[:href] }.last
34
+ end
35
+
36
+ def selected?(row)
37
+ row[:tries].any? { |entry| entry[:selected] }
38
+ end
39
+
40
+ def running?(row)
41
+ row[:tries].any? { |entry| entry[:ended_at].nil? }
42
+ end
43
+
28
44
  def queued_style(entry)
29
45
  "left: #{percent(entry[:queued_at] - axis_start)}%; width: #{percent(entry[:started_at] - entry[:queued_at])}%"
30
46
  end
@@ -33,8 +49,12 @@ module Keystone
33
49
  [ BAR_CLASSES, (FAILED_CLASSES if entry[:failed]) ].compact.join(" ")
34
50
  end
35
51
 
52
+ def bar_tag(entry)
53
+ entry[:href] ? :a : :div
54
+ end
55
+
36
56
  def duration(row)
37
- written_duration(row[:tries].last[:ended_at] - row[:tries].first[:started_at])
57
+ written_duration(ended_at(row[:tries].last) - row[:tries].first[:started_at])
38
58
  end
39
59
 
40
60
  def total_duration
@@ -47,6 +67,11 @@ module Keystone
47
67
 
48
68
  private
49
69
 
70
+ def check_times(entry)
71
+ raise ArgumentError, "Timeline entry #{entry[:label].inspect} has no started_at" unless entry[:started_at]
72
+ raise ArgumentError, "Timeline entry #{entry[:label].inspect} ends before it starts" if entry[:ended_at] && entry[:ended_at] < entry[:started_at]
73
+ end
74
+
50
75
  def written_duration(seconds)
51
76
  hours, rest = seconds.round.divmod(3600)
52
77
  minutes, seconds = rest.divmod(60)
@@ -60,11 +85,24 @@ module Keystone
60
85
  end
61
86
 
62
87
  def axis_end
63
- @axis_end ||= entries.map { |entry| entry[:ended_at] }.max
88
+ @axis_end ||= entries.map { |entry| entry[:ended_at] || entry[:started_at] }.max
89
+ end
90
+
91
+ def ended_at(entry)
92
+ entry[:ended_at] || axis_end
93
+ end
94
+
95
+ def bar_width(entry)
96
+ format("%g", [ share(ended_at(entry) - entry[:started_at]), MINIMUM_BAR_PERCENT ].max)
64
97
  end
65
98
 
66
99
  def percent(seconds)
67
- format("%g", (seconds / (axis_end - axis_start) * 100).round(2))
100
+ format("%g", share(seconds))
101
+ end
102
+
103
+ def share(seconds)
104
+ span = axis_end - axis_start
105
+ span.zero? ? 0 : (seconds / span * 100).round(2)
68
106
  end
69
107
  end
70
108
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.81.0"
4
+ VERSION = "0.83.0"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: keystone_ui-develop
3
- description: Use PROACTIVELY for building or editing screens in a Rails app that has keystone_ui — page shells with Back links and breadcrumbs, forms and fields, a search field that picks a record or enters a new one, data tables with saved columns, desktop navigation, sidebars and bottom tabs, a page's main action as a phone top-bar icon or a button fixed to the bottom of the screen, a question asked before a button or main action goes ahead, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels, goal buckets and timelines of timed steps with retries, queued time and failed tries, amounts shown in green or red as a gain or loss, status dots coloured by state, pictures held to half the screen, two versions of a text compared line by line side by side, info buttons and breakdowns, marketing sections, a light/dark theme switch — MUST BE USED instead of hand-writing ERB and Tailwind for UI.
3
+ description: Use PROACTIVELY for building or editing screens in a Rails app that has keystone_ui — page shells with Back links and breadcrumbs, forms and fields, a search field that picks a record or enters a new one, data tables with saved columns, desktop navigation, sidebars and bottom tabs, a page's main action as a phone top-bar icon or a button fixed to the bottom of the screen, a question asked before a button or main action goes ahead, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels, goal buckets and timelines of timed steps with retries, queued time, failed tries, steps still running, links to each try and the current step marked, amounts shown in green or red as a gain or loss, status dots coloured by state, pictures held to half the screen, two versions of a text compared line by line side by side, info buttons and breakdowns, marketing sections, a light/dark theme switch — MUST BE USED instead of hand-writing ERB and Tailwind for UI.
4
4
  tools: Bash, Read, Write, Edit, Grep
5
5
  scope: UI — pages, forms, tables, navigation, dashboards
6
6
  ---
@@ -98,7 +98,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
98
98
  - `ui_funnel` — a conversion funnel drawn as bars or one joined shape.
99
99
  - `ui_bucket` — an upright container filled toward a goal.
100
100
  - `ui_bucket_series` — a wrapping row of buckets.
101
- - `ui_timeline` — rows of timed steps on one shared time axis, each try of a step a bar on its row, with optional queued time and failed tries marked.
101
+ - `ui_timeline` — rows of timed steps on one shared time axis, each try of a step a bar on its row, with optional queued time, failed tries and tries still running marked, bars and row labels that open an address, the current row marked, and a "No steps" message when there are no entries.
102
102
  - `ui_pipeline` — a staged flow diagram with buttons and breakable links that post to the app.
103
103
  - `ui_hero` — a marketing hero with title, call-to-action buttons and an aside.
104
104
  - `ui_cta_banner` — a marketing banner holding call-to-action buttons.
@@ -753,7 +753,7 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
753
753
  - `ui_bucket_series(buckets:)` takes an array of hashes with the keywords
754
754
  of `ui_bucket`, such as `[{ goal: 10, actual: 7, label: "Mon" }, ...]`.
755
755
  - `ui_timeline(entries:)` takes no block. `entries:` is
756
- `[{ label:, started_at:, ended_at:, queued_at: nil, failed: false }, ...]`,
756
+ `[{ label:, started_at:, ended_at: nil, queued_at: nil, failed: false, href: nil, selected: false }, ...]`,
757
757
  with every time a `Time` value.
758
758
  - It draws one row per label, in the order each label first appears.
759
759
  Entries that share a label, such as the tries of one step, share that
@@ -761,21 +761,45 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
761
761
  in the order they ran.
762
762
  - Every bar is placed by its entry's `started_at` and `ended_at` on one
763
763
  axis shared by all rows. The axis runs from the earliest `queued_at` or
764
- `started_at` of any entry to the latest `ended_at`.
764
+ `started_at` of any entry to the latest `ended_at`, or to the latest
765
+ `started_at` when that is later.
766
+ - An entry with no `ended_at:`, or `ended_at: nil`, is a try still
767
+ running. Its bar runs to the end of the axis, and its row shows an
768
+ `:info` status dot beside its duration that screen readers read as
769
+ "Running". Leave `ended_at:` out only for a try that has not finished.
770
+ - Every bar is drawn at least 2% of the track wide, so a try that took no
771
+ time still shows. When every entry starts and ends at one moment, every
772
+ bar is drawn at that width at the left edge of the track.
765
773
  - An entry given `queued_at:` also draws the time from `queued_at` to
766
774
  `started_at` before its bar, in the queued colour. Leave it out when the
767
775
  wait is not known.
768
776
  - An entry given `failed: true` draws its bar in the danger colour, and
769
777
  screen readers read it as "Failed". Ask the developer which tries count
770
778
  as failed and whether the queued time is shown.
779
+ - An entry given `href:` draws its bar as a link to that address, read out
780
+ by screen readers as the entry's label. A row's label links to the
781
+ `href:` of the row's last entry that has one, and with none it is plain
782
+ text. Ask the developer which page each try opens, such as that try's
783
+ own detail page.
784
+ - An entry given `selected: true` marks its row as the current one: the
785
+ row is drawn in the same tint as `ui_data_table`'s `current_row:` and
786
+ screen readers announce it as the current item. Pass it on the entry the
787
+ page is showing, such as the try whose detail page holds the timeline,
788
+ and on one entry at most.
771
789
  - Each row shows its label and its duration on one line, then its track.
772
790
  The row's duration runs from its first entry's `started_at` to its last
773
- entry's `ended_at`, so queued time before the first try is not counted.
791
+ entry's `ended_at`, or to the end of the axis when that last entry is
792
+ still running, so queued time before the first try is not counted.
774
793
  - Under the rows the axis reads `0s` on the left and the whole span on the
775
794
  right. Durations are written as `1h 0m 5s`, leaving out leading zero
776
795
  units, and a zero duration is `0s`.
777
- - It needs at least one entry and a span longer than zero, so do not render
778
- it for an empty list or for entries that all start and end at one moment.
796
+ - An entry with no `started_at:` raises `ArgumentError` naming its label,
797
+ and so does an entry whose `ended_at:` is before its `started_at:`. Check
798
+ the times before rendering rather than rescuing the error.
799
+ - An empty `entries:` draws a centred "No steps" message in place of the
800
+ timeline, so it can be rendered for a list that may be empty. The
801
+ wording is fixed, so ask the developer whether it fits, and when it does
802
+ not, check for no entries and call `ui_empty_state` instead.
779
803
  - `ui_pipeline(title:, boxes:, links:, subtitle: nil)` — `boxes:` is
780
804
  `[{ label:, count:, accent:, action: }, ...]`, with `accent:` one of
781
805
  `:amber` `:emerald` `:danger` `:muted`, and `action:` is
@@ -71,7 +71,16 @@ One decision: is keystone_ui set up in the app?
71
71
  try's end. Queued time is drawn as its own segment before the bar, and a
72
72
  failed try is marked failed both in colour and for screen readers. The axis
73
73
  runs from the earliest queued or start time of any entry to the latest end
74
- time.
74
+ or start time. An entry with no end time is still running: its bar runs to
75
+ the end of the axis, and its row shows a status dot that screen readers read
76
+ as "Running". Every bar is drawn at least a small visible width, so a try
77
+ that took no time still shows. An entry with no start time, or one that ends
78
+ before it starts, raises `ArgumentError` naming its label. A timeline with no
79
+ entries shows a message saying there are no steps. An entry can carry an address, and then its bar is a link to it whose
80
+ name screen readers announce is the entry's label, and the row's label links
81
+ to the address of the last entry in that row that has one. An entry can be
82
+ marked selected, and the row holding it is drawn in the same tint as a data
83
+ table's current row and announced to screen readers as the current item.
75
84
  - **Going back.** A form or show page shell needs a way back: a back link, a
76
85
  trail of earlier pages shown as breadcrumbs, or a trail the app supplies for
77
86
  the request. A nav tab's own page passes an empty trail and shows no back
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.81.0
4
+ version: 0.83.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider