keystone_ui 0.85.0 → 0.86.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: 85457be1129db7d375f22f600c702f0c2d75c8d93e1dbb9443cbf6c59ab57294
4
- data.tar.gz: 677ef89d8e94bf3fc4a8fd46df2ce7d7e99e91766bdc6ffee2bcc19c1c293e2f
3
+ metadata.gz: c351ad6abee58f4d2001dab3cf8e299735b69bd2e09651b8c85943c169d17afc
4
+ data.tar.gz: d6f4e92fde93ed1a94a49446c613707a50c2d5cb3d57aac8ee27e06f01a2edeb
5
5
  SHA512:
6
- metadata.gz: bc60e2d038b07b075cef52782834681100eb2c3e7814e600f11db7f7e7d3045f3ece2067799039cc94e1a6eea2b88c43cee24c24238db589b67e1f399ddbedfe
7
- data.tar.gz: 00432aab92887c8f5d5e2ad30f80cb9a3c3b2a05513987731058e6adfebee1c84ea454963c624e022585ee17af8e38f7dc7abc38d89bf1d20a5f861cf9e50ed8
6
+ metadata.gz: a327fe7872d4c828217c2dbf33c8b6042a520771708d0b04870b2c627ad00cfa8001bfae481475575c15e156cd5a0697756c2d98fc12236b9a8dfce484c69a1c
7
+ data.tar.gz: c126fda060d77148908eabb68b1d1d2ab538060ff0bc9ad2d80441a2cd09409f2d05aa2221be673fe6fae98a8d790a590fc4fb95fcf94a1d5de20532ff28a5ab
@@ -1,17 +1,24 @@
1
1
  <% if entries.empty? %>
2
2
  <%= render Keystone::Ui::EmptyStateComponent.new(title: "No steps") %>
3
3
  <% else %>
4
- <div class="flex flex-col gap-3">
4
+ <div class="<%= timeline_classes %>" data-timeline>
5
+ <% if one_line %>
6
+ <div class="<%= ONE_LINE_AXIS_CLASSES %>">
7
+ <% marks.each do |mark| %>
8
+ <span class="<%= MARK_CLASSES %>" data-timeline-mark style="<%= mark[:style] %>"><%= mark[:label] %></span>
9
+ <% end %>
10
+ </div>
11
+ <% end %>
5
12
  <% 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 %>">
13
+ <% label = content_tag(row_href(row) ? :a : :span, row[:label], class: label_classes, data: { timeline_label: "" }, href: row_href(row)) %>
14
+ <% status = capture do %>
15
+ <span class="<%= status_classes %>">
16
+ <% if running?(row) %><%= render Keystone::Ui::StatusDotComponent.new(state: :info, label: "Running") %><% end %>
17
+ <span data-timeline-duration><%= duration(row) %></span>
18
+ </span>
19
+ <% end %>
20
+ <% track = capture do %>
21
+ <div class="<%= track_classes %>">
15
22
  <% row[:tries].each do |entry| %>
16
23
  <% if entry[:queued_at] %>
17
24
  <div class="<%= QUEUED_CLASSES %>" data-timeline-queued style="<%= queued_style(entry) %>"></div>
@@ -19,11 +26,21 @@
19
26
  <%= 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 %>
20
27
  <% end %>
21
28
  </div>
29
+ <% end %>
30
+ <%= tag.div(data: { timeline_row: "" }, class: row_classes(row), aria: { current: ("true" if selected?(row)) }) do %>
31
+ <% if one_line %>
32
+ <%= label %><%= track %><%= status %>
33
+ <% else %>
34
+ <div class="<%= ROW_TEXT_CLASSES %>"><%= label %><%= status %></div>
35
+ <%= track %>
36
+ <% end %>
37
+ <% end %>
38
+ <% end %>
39
+ <% unless one_line %>
40
+ <div class="<%= AXIS_CLASSES %>">
41
+ <span data-timeline-axis-start><%= axis_start_label %></span>
42
+ <span data-timeline-axis-end><%= total_duration %></span>
22
43
  </div>
23
44
  <% 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>
27
- </div>
28
45
  </div>
29
46
  <% end %>
@@ -9,16 +9,39 @@ module Keystone
9
9
  QUEUED_CLASSES = "ks-timeline-queued absolute inset-y-0"
10
10
  SCREEN_READER_CLASSES = "sr-only"
11
11
  SELECTED_ROW_CLASSES = "ks-table-row-current"
12
+ TIMELINE_CLASSES = "flex flex-col ks-grid-gap-sm"
13
+ ONE_LINE_TIMELINE_CLASSES = "sm:grid sm:grid-cols-[fit-content(40%)_1fr_auto]"
14
+ ONE_LINE_ROW_CLASSES = "grid grid-cols-[1fr_auto] items-center ks-grid-gap-x-sm text-sm sm:col-span-3 sm:grid-cols-subgrid"
15
+ ONE_LINE_LABEL_CLASSES = "ks-meter-label min-w-0 truncate sm:mb-0"
16
+ ONE_LINE_TRACK_CLASSES = "col-span-2 row-start-2 sm:col-span-1 sm:col-start-2 sm:row-start-1"
17
+ ONE_LINE_STATUS_CLASSES = "ks-meter-label justify-self-end sm:mb-0"
12
18
  ROW_TEXT_CLASSES = "ks-meter-label flex justify-between text-sm"
13
19
  AXIS_CLASSES = "ks-meter-label flex justify-between text-xs"
14
20
  ROW_STATUS_CLASSES = "flex items-center ks-grid-gap-sm"
21
+ ONE_LINE_AXIS_CLASSES = "ks-meter-label relative h-4 text-xs sm:col-start-2"
22
+ MARK_CLASSES = "absolute top-0 whitespace-nowrap"
15
23
  MINIMUM_BAR_PERCENT = 2
24
+ MARK_STEPS = [ 1, 2, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800, 3600, 7200, 10_800, 21_600, 43_200, 86_400 ].freeze
25
+ MAXIMUM_MARK_INTERVALS = 6
16
26
 
17
- attr_reader :entries
27
+ attr_reader :entries, :one_line
18
28
 
19
- def initialize(entries:)
29
+ def initialize(entries:, one_line: false)
20
30
  entries.each { |entry| check_times(entry) }
21
31
  @entries = entries
32
+ @one_line = one_line
33
+ end
34
+
35
+ def track_classes
36
+ [ TRACK_CLASSES, (ONE_LINE_TRACK_CLASSES if one_line) ].compact.join(" ")
37
+ end
38
+
39
+ def label_classes
40
+ ONE_LINE_LABEL_CLASSES if one_line
41
+ end
42
+
43
+ def status_classes
44
+ [ ROW_STATUS_CLASSES, (ONE_LINE_STATUS_CLASSES if one_line) ].compact.join(" ")
22
45
  end
23
46
 
24
47
  def bar_style(entry)
@@ -37,6 +60,14 @@ module Keystone
37
60
  row[:tries].any? { |entry| entry[:selected] }
38
61
  end
39
62
 
63
+ def timeline_classes
64
+ [ TIMELINE_CLASSES, (ONE_LINE_TIMELINE_CLASSES if one_line) ].compact.join(" ")
65
+ end
66
+
67
+ def row_classes(row)
68
+ [ (ONE_LINE_ROW_CLASSES if one_line), (SELECTED_ROW_CLASSES if selected?(row)) ].compact.join(" ").presence
69
+ end
70
+
40
71
  def running?(row)
41
72
  row[:tries].any? { |entry| entry[:ended_at].nil? }
42
73
  end
@@ -61,6 +92,10 @@ module Keystone
61
92
  written_duration(axis_end - axis_start)
62
93
  end
63
94
 
95
+ def marks
96
+ (0..mark_intervals).map { |index| { label: written_mark(index * mark_step), style: mark_style(index) } }
97
+ end
98
+
64
99
  def axis_start_label
65
100
  written_duration(0)
66
101
  end
@@ -80,6 +115,36 @@ module Keystone
80
115
  parts.map { |amount, unit| "#{amount}#{unit}" }.join(" ")
81
116
  end
82
117
 
118
+ def written_mark(seconds)
119
+ hours, rest = seconds.divmod(3600)
120
+ minutes, seconds = rest.divmod(60)
121
+ parts = [ [ hours, "h" ], [ minutes, "m" ], [ seconds, "s" ] ].reject { |amount, _| amount.zero? }
122
+ parts.empty? ? "0s" : parts.map { |amount, unit| "#{amount}#{unit}" }.join(" ")
123
+ end
124
+
125
+ def mark_style(index)
126
+ return "left: 0%" if index.zero?
127
+ return "right: 0%" if index == mark_intervals
128
+
129
+ "left: #{percent(index * mark_step)}%; transform: translateX(-50%)"
130
+ end
131
+
132
+ def mark_step
133
+ @mark_step ||= MARK_STEPS.find { |step| span <= step * MAXIMUM_MARK_INTERVALS } || (span / (MARK_STEPS.last * MAXIMUM_MARK_INTERVALS)).ceil * MARK_STEPS.last
134
+ end
135
+
136
+ def mark_intervals
137
+ [ (span / mark_step).ceil, 1 ].max
138
+ end
139
+
140
+ def scale
141
+ one_line ? mark_intervals * mark_step : span
142
+ end
143
+
144
+ def span
145
+ axis_end - axis_start
146
+ end
147
+
83
148
  def axis_start
84
149
  @axis_start ||= entries.map { |entry| entry[:queued_at] || entry[:started_at] }.min
85
150
  end
@@ -101,8 +166,7 @@ module Keystone
101
166
  end
102
167
 
103
168
  def share(seconds)
104
- span = axis_end - axis_start
105
- span.zero? ? 0 : (seconds / span * 100).round(2)
169
+ scale.zero? ? 0 : (seconds.fdiv(scale) * 100).round(2)
106
170
  end
107
171
  end
108
172
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.85.0"
4
+ VERSION = "0.86.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, 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.
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, drawn one line per step with a marked time axis if wanted, 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, 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.
101
+ - `ui_timeline` — rows of timed steps on one shared time axis, each try of a step a bar on its row, optionally one line per row with a marked axis, 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.
@@ -765,9 +765,10 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
765
765
  the fill turns green with `over: :success` or amber with `over: :warning`.
766
766
  - `ui_bucket_series(buckets:)` takes an array of hashes with the keywords
767
767
  of `ui_bucket`, such as `[{ goal: 10, actual: 7, label: "Mon" }, ...]`.
768
- - `ui_timeline(entries:)` takes no block. `entries:` is
768
+ - `ui_timeline(entries:, one_line: false)` takes no block. `entries:` is
769
769
  `[{ label:, started_at:, ended_at: nil, queued_at: nil, failed: false, href: nil, selected: false }, ...]`,
770
- with every time a `Time` value.
770
+ with every time a `Time` value. `one_line:` picks the layout, described
771
+ below.
771
772
  - It draws one row per label, in the order each label first appears.
772
773
  Entries that share a label, such as the tries of one step, share that
773
774
  row and each draws its own bar, so pass a step's tries one after another
@@ -777,7 +778,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
777
778
  `started_at` of any entry to the latest `ended_at`, or to the latest
778
779
  `started_at` when that is later.
779
780
  - An entry with no `ended_at:`, or `ended_at: nil`, is a try still
780
- running. Its bar runs to the end of the axis, and its row shows an
781
+ running. Its bar runs to the latest `ended_at` or `started_at` of any
782
+ entry, and its row shows an
781
783
  `:info` status dot beside its duration that screen readers read as
782
784
  "Running". Leave `ended_at:` out only for a try that has not finished.
783
785
  - Every bar is drawn at least 2% of the track wide, so a try that took no
@@ -799,13 +801,31 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
799
801
  screen readers announce it as the current item. Pass it on the entry the
800
802
  page is showing, such as the try whose detail page holds the timeline,
801
803
  and on one entry at most.
802
- - Each row shows its label and its duration on one line, then its track.
803
- The row's duration runs from its first entry's `started_at` to its last
804
- entry's `ended_at`, or to the end of the axis when that last entry is
805
- still running, so queued time before the first try is not counted.
806
- - Under the rows the axis reads `0s` on the left and the whole span on the
807
- right. Durations are written as `1h 0m 5s`, leaving out leading zero
808
- units, and a zero duration is `0s`.
804
+ - Each row shows its label, its duration and its track. The row's duration
805
+ runs from its first entry's `started_at` to its last entry's `ended_at`,
806
+ or to the end of the axis when that last entry is still running, so
807
+ queued time before the first try is not counted. Durations are written as
808
+ `1h 0m 5s`, leaving out leading zero units, and a zero duration is `0s`.
809
+ - With the default `one_line: false`, each row shows its label and its
810
+ duration on one line with its track below them, at every width. Under
811
+ the rows the axis reads `0s` on the left and the whole span on the right,
812
+ and the bars fill the track from the start of the axis to its end.
813
+ - With `one_line: true`, from `sm:` up each row is one line: its label,
814
+ then its track, then its duration. The label column is as wide as the
815
+ longest label up to 40% of the timeline, a longer label is cut off with
816
+ an ellipsis, and every row's track has the same width and lines up with
817
+ the others. Below `sm:` each row shows its label and duration on one
818
+ line with its track on a second line across the full width.
819
+ - Above a one-line timeline's first row, in the track column, the axis
820
+ shows marks at even
821
+ intervals from `0s`, at the smallest of 1, 2, 5, 10, 15 or 30 seconds,
822
+ 1, 2, 5, 10, 15 or 30 minutes, or 1, 2, 3, 6, 12 or 24 hours that covers
823
+ the whole span in six intervals or fewer, and at whole days past six
824
+ days. The axis ends at the first mark at or after the span, so the
825
+ longest bar can stop short of the right edge, and every bar and mark is
826
+ placed on that axis. A mark is written with each non-zero unit, such as
827
+ `1m 30s` or `1h 5s`.
828
+ - Ask the developer which layout a screen uses.
809
829
  - An entry with no `started_at:` raises `ArgumentError` naming its label,
810
830
  and so does an entry whose `ended_at:` is before its `started_at:`. Check
811
831
  the times before rendering rather than rescuing the error.
@@ -77,7 +77,15 @@ One decision: is keystone_ui set up in the app?
77
77
  as "Running". Every bar is drawn at least a small visible width, so a try
78
78
  that took no time still shows. An entry with no start time, or one that ends
79
79
  before it starts, raises `ArgumentError` naming its label. A timeline with no
80
- 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
+ entries shows a message saying there are no steps. By default each row shows
81
+ its label and duration on one line with the bar below, and the axis under the
82
+ rows shows only `0s` and the total duration. A timeline can be drawn one line
83
+ per row instead: from `sm:` up each row holds its label, its bar and its
84
+ duration side by side, every row's bar has the same width, and a long label is
85
+ cut off with an ellipsis. Below `sm:` the bar moves under the label and
86
+ duration. In that layout the axis, drawn above the first row, shows marks at the smallest round time step
87
+ that covers the run in six intervals or fewer, and the axis ends at the last mark rather than at the latest
88
+ time, so bars are placed against that longer axis. An entry can carry an address, and then its bar is a link to it whose
81
89
  name screen readers announce is the entry's label, and the row's label links
82
90
  to the address of the last entry in that row that has one. An entry can be
83
91
  marked selected, and the row holding it is drawn in the same tint as a data
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.85.0
4
+ version: 0.86.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider