Class: Clowk::Phlex::Charts::IntervalPicker

Inherits:
Clowk::Phlex::Component show all
Defined in:
lib/clowk/phlex/charts/interval_picker.rb

Overview

Components::Metrics::IntervalPicker — dropdown that controls the chart's bucket size (the x-axis density) INDEPENDENTLY from the range pills. Range answers "how far back?"; interval answers "how granular?".

Why a separate control instead of preset range/interval pairs: operator flexibility. The same "last 1h" can be examined at 1m (60 spikes) or 5m (12 smoothed points) depending on what they're hunting — a burst hidden in the average vs the overall trend.

Mirrors the DS dropdown pattern of Components::Metrics::MetricPicker (same data-controller="dropdown", same trigger/menu structure) so the modal toolbar reads as a row of consistent pickers.

Mounted on:

- Views::Metrics::Index (page toolbar, next to the RangePicker)
- Views::Metrics::ChartModalBody (modal toolbar, next to the
range pills + metric picker + pod picker)

URL contract: the active interval lives in the interval query param. auto is the default and is OMITTED from the URL (clean URLs by default — operator only sees the param when they've explicitly picked one).

Constant Summary collapse

OPTIONS =

Drop OPTIONS in lockstep with MetricsPageData::INTERVALS and MetricsWarehouse::INTERVAL_ALIASES keys. Drift between any of the three = picker rows that silently roundtrip to "auto".

%w[auto 1s 10s 15s 1m 5m 15m 30m 1h].freeze

Instance Method Summary collapse

Constructor Details

#initialize(current:, base_path:, extra_params: {}, turbo_stream: false) ⇒ IntervalPicker

current: currently active interval (e.g. "auto", "1m") base_path: URL each row hits (metrics_path or metrics_chart_path) extra_params: merged into every URL EXCEPT interval (which the picker overrides per row). Pass the request query minus interval. turbo_stream: emit data-turbo-stream on row anchors so the swap stays modal-local (used inside the modal toolbar). Defaults to false for the page-level picker which does a normal navigation.



41
42
43
44
45
46
# File 'lib/clowk/phlex/charts/interval_picker.rb', line 41

def initialize(current:, base_path:, extra_params: {}, turbo_stream: false)
  @current = current.to_s.presence || "auto"
  @base_path = base_path
  @extra_params = extra_params || {}
  @turbo_stream = turbo_stream
end

Instance Method Details

#view_templateObject



48
49
50
51
52
53
# File 'lib/clowk/phlex/charts/interval_picker.rb', line 48

def view_template
  div(class: "relative", data: {controller: "dropdown"}) do
    trigger
    menu
  end
end