Skip to content

Commit

Permalink
feat: Readable metrics view url params (#5675)
Browse files Browse the repository at this point in the history
* Add basic to and from url methods

* Add filters to url

* Hookup the new url format

* Use ExplorePreset for defaults

* Add tests for no presets

* Add tests for presets

* Use loader function to parse url to metrics explore state

* Converts from and to V1ExplorePreset

* Use base preset to generate init explore

* Add mapping from legacy proto state

* Add tests for legacy proto parsing

* Add partial metrics entity support

* Incorporate bookmarks

* Fix home bookmarks

* Fix embed and token case

* Convert bookmarks to links with new urls

* Add support for free form editing of filters

* Rename metrics to explore where applicable

* Fix some issues and overhaul tests

* Fix compare time ranges

* Add readonly advanced filter state

* Store state in session storage

* Switch over to new url params

* Fix public urls modal not persisting

* Add basic tests for ExploreWebViewStore

* Add all ExploreWebViewStore tests

* Add leaderboard sort and filter errors

* Add custom time and scrub range

* Better default identification

* Renames

* `exploreStore` -> `exploreState`

* Use `exploreState` name

* Remove console logs

* `exploreState` cont.

* Delete old file

* Fix lint for `web-common`

* Fix lint for `web-admin`

* "Overview" -> "Explore"

* Fix typos

* Clean up `+page.ts` files

* Fix some TS errors

* Move function to `web-common`

* Fix "Pivot" button selector

* Move url params to a central place

* Fix UTs

* Fix time config E2E tests

* Move to loading state in loader function

* Fix view links tests

* Expand bookmark click area

* Restore ability to remove a highlighted time range

* (hack) Fix for comparisons with custom time ranges

* Fix "Select all" buttons

* Fix redirect loop

* Fix tsc

* Fix E2E

* Fix for visual explore editor

* Refactor bookmarks parser

* Fix type error in telemetry

* Fix compare time range not going away when disabled

* Fix filters persistance in emebd

---------

Co-authored-by: Eric P Green <[email protected]>
  • Loading branch information
AdityaHegde and ericpgreen2 authored Dec 5, 2024
1 parent 908f1ff commit 258151c
Show file tree
Hide file tree
Showing 123 changed files with 7,369 additions and 2,574 deletions.
2,069 changes: 1,212 additions & 857 deletions proto/gen/rill/runtime/v1/resources.pb.go

Large diffs are not rendered by default.

99 changes: 96 additions & 3 deletions proto/gen/rill/runtime/v1/resources.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions proto/gen/rill/runtime/v1/runtime.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4092,18 +4092,66 @@ definitions:
measuresSelector:
$ref: '#/definitions/v1FieldSelector'
description: Dynamic selector for `measures`. Will be processed during validation, so it will always be empty in `state.valid_spec`.
where:
$ref: '#/definitions/v1Expression'
timeRange:
type: string
description: |-
Time range for the explore.
It corresponds to the `range` property of the explore's `time_ranges`.
If not found in `time_ranges`, it should be added to the list.
timezone:
type: string
timeGrain:
type: string
selectTimeRange:
type: string
comparisonMode:
$ref: '#/definitions/v1ExploreComparisonMode'
description: Comparison mode.
compareTimeRange:
type: string
comparisonDimension:
type: string
description: If comparison_mode is EXPLORE_COMPARISON_MODE_DIMENSION, this indicates the dimension to use.
view:
$ref: '#/definitions/v1ExploreWebView'
exploreSortBy:
type: string
exploreSortAsc:
type: boolean
exploreSortType:
$ref: '#/definitions/v1ExploreSortType'
exploreExpandedDimension:
type: string
timeDimensionMeasure:
type: string
timeDimensionChartType:
type: string
timeDimensionPin:
type: boolean
pivotRows:
type: array
items:
type: string
pivotCols:
type: array
items:
type: string
pivotSortBy:
type: string
pivotSortAsc:
type: boolean
v1ExploreSortType:
type: string
enum:
- EXPLORE_SORT_TYPE_UNSPECIFIED
- EXPLORE_SORT_TYPE_VALUE
- EXPLORE_SORT_TYPE_PERCENT
- EXPLORE_SORT_TYPE_DELTA_PERCENT
- EXPLORE_SORT_TYPE_DELTA_ABSOLUTE
- EXPLORE_SORT_TYPE_DIMENSION
default: EXPLORE_SORT_TYPE_UNSPECIFIED
v1ExploreSpec:
type: object
properties:
Expand Down Expand Up @@ -4184,6 +4232,15 @@ definitions:
type: object
$ref: '#/definitions/v1ExploreComparisonTimeRange'
title: Comparison time ranges available for this time range
v1ExploreWebView:
type: string
enum:
- EXPLORE_WEB_VIEW_UNSPECIFIED
- EXPLORE_WEB_VIEW_EXPLORE
- EXPLORE_WEB_VIEW_TIME_DIMENSION
- EXPLORE_WEB_VIEW_PIVOT
- EXPLORE_WEB_VIEW_CANVAS
default: EXPLORE_WEB_VIEW_UNSPECIFIED
v1ExportFormat:
type: string
enum:
Expand Down
45 changes: 43 additions & 2 deletions proto/rill/runtime/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,38 @@ message ExplorePreset {
repeated string measures = 4;
// Dynamic selector for `measures`. Will be processed during validation, so it will always be empty in `state.valid_spec`.
FieldSelector measures_selector = 10;

optional Expression where = 11;

// Time range for the explore.
// It corresponds to the `range` property of the explore's `time_ranges`.
// If not found in `time_ranges`, it should be added to the list.
string time_range = 6;
optional string time_range = 6;
optional string timezone = 12;
optional string time_grain = 13;
optional string select_time_range = 14;

// Comparison mode.
ExploreComparisonMode comparison_mode = 7;
optional string compare_time_range = 15;
// If comparison_mode is EXPLORE_COMPARISON_MODE_DIMENSION, this indicates the dimension to use.
string comparison_dimension = 8;
optional string comparison_dimension = 8;

optional ExploreWebView view = 16;

optional string explore_sort_by = 17;
optional bool explore_sort_asc = 18;
optional ExploreSortType explore_sort_type = 19;
optional string explore_expanded_dimension = 20;

optional string time_dimension_measure = 21;
optional string time_dimension_chart_type = 22;
optional bool time_dimension_pin = 23;

repeated string pivot_rows = 24;
repeated string pivot_cols = 25;
optional string pivot_sort_by = 26;
optional bool pivot_sort_asc = 27;
}

enum ExploreComparisonMode {
Expand All @@ -402,6 +426,23 @@ enum ExploreComparisonMode {
EXPLORE_COMPARISON_MODE_DIMENSION = 3;
}

enum ExploreWebView {
EXPLORE_WEB_VIEW_UNSPECIFIED = 0;
EXPLORE_WEB_VIEW_EXPLORE = 1;
EXPLORE_WEB_VIEW_TIME_DIMENSION = 2;
EXPLORE_WEB_VIEW_PIVOT = 3;
EXPLORE_WEB_VIEW_CANVAS = 4;
}

enum ExploreSortType {
EXPLORE_SORT_TYPE_UNSPECIFIED = 0;
EXPLORE_SORT_TYPE_VALUE = 1;
EXPLORE_SORT_TYPE_PERCENT = 2;
EXPLORE_SORT_TYPE_DELTA_PERCENT = 3;
EXPLORE_SORT_TYPE_DELTA_ABSOLUTE = 4;
EXPLORE_SORT_TYPE_DIMENSION = 5;
}

// FieldSelector describes logic for selecting a list of fields.
// It is useful for dynamically evaluating fields when the list of potential fields is not known at parse time.
message FieldSelector {
Expand Down
12 changes: 10 additions & 2 deletions runtime/compilers/rillv1/parse_explore.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,22 @@ func (p *Parser) parseExplore(node *Node) error {
presetMeasuresSelector = tmp.Defaults.Measures.Proto()
}

var tr *string
if tmp.Defaults.TimeRange != "" {
tr = &tmp.Defaults.TimeRange
}
var compareDim *string
if tmp.Defaults.ComparisonDimension != "" {
compareDim = &tmp.Defaults.ComparisonDimension
}
defaultPreset = &runtimev1.ExplorePreset{
Dimensions: presetDimensions,
DimensionsSelector: presetDimensionsSelector,
Measures: presetMeasures,
MeasuresSelector: presetMeasuresSelector,
TimeRange: tmp.Defaults.TimeRange,
TimeRange: tr,
ComparisonMode: mode,
ComparisonDimension: tmp.Defaults.ComparisonDimension,
ComparisonDimension: compareDim,
}
}

Expand Down
12 changes: 10 additions & 2 deletions runtime/compilers/rillv1/parse_metrics_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,14 +899,22 @@ func (p *Parser) parseMetricsView(node *Node) error {
if len(spec.DefaultMeasures) == 0 {
presetMeasuresSelector = &runtimev1.FieldSelector{Selector: &runtimev1.FieldSelector_All{All: true}}
}
var tr *string
if spec.DefaultTimeRange != "" {
tr = &spec.DefaultTimeRange
}
var compareDim *string
if spec.DefaultComparisonDimension != "" {
compareDim = &spec.DefaultComparisonDimension
}
e.ExploreSpec.DefaultPreset = &runtimev1.ExplorePreset{
Dimensions: spec.DefaultDimensions,
DimensionsSelector: presetDimensionsSelector,
Measures: spec.DefaultMeasures,
MeasuresSelector: presetMeasuresSelector,
TimeRange: spec.DefaultTimeRange,
TimeRange: tr,
ComparisonMode: exploreComparisonMode,
ComparisonDimension: spec.DefaultComparisonDimension,
ComparisonDimension: compareDim,
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion runtime/compilers/rillv1/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ schema: default
`,
}

timeRange := "P4W"
resources := []*Resource{
// init.sql
{
Expand Down Expand Up @@ -317,7 +318,7 @@ schema: default
DefaultPreset: &runtimev1.ExplorePreset{
DimensionsSelector: &runtimev1.FieldSelector{Selector: &runtimev1.FieldSelector_All{All: true}},
MeasuresSelector: &runtimev1.FieldSelector{Selector: &runtimev1.FieldSelector_All{All: true}},
TimeRange: "P4W",
TimeRange: &timeRange,
ComparisonMode: runtimev1.ExploreComparisonMode_EXPLORE_COMPARISON_MODE_NONE,
},
},
Expand Down
1 change: 1 addition & 0 deletions scripts/tsc-with-whitelist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ web-admin/src/routes/[organization]/-/settings/billing/payment/+page.ts: error T
web-admin/src/routes/[organization]/-/settings/billing/upgrade/+page.ts: error TS2307
web-admin/src/routes/[organization]/-/settings/usage/+page.ts: error TS2307
web-admin/src/routes/[organization]/-/upgrade-callback/+page.ts: error TS2307
web-admin/src/routes/[organization]/[project]/-/share/[token]/+page.ts: error TS2345
web-common/src/components/data-graphic/actions/mouse-position-to-domain-action-factory.ts: error TS2322
web-common/src/components/data-graphic/actions/outline.ts: error TS18047
web-common/src/components/data-graphic/actions/outline.ts: error TS2345
Expand Down
14 changes: 7 additions & 7 deletions web-admin/src/features/bookmarks/BaseBookmarkForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Tooltip from "@rilldata/web-common/components/tooltip/Tooltip.svelte";
import TooltipContent from "@rilldata/web-common/components/tooltip/TooltipContent.svelte";
import FilterChipsReadOnly from "@rilldata/web-common/features/dashboards/filters/FilterChipsReadOnly.svelte";
import { useExploreStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import { useExploreState } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient";
import type { V1TimeRange } from "@rilldata/web-common/runtime-client";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
Expand All @@ -21,13 +21,13 @@
export let exploreName: string;
export let formState: ReturnType<typeof createForm<BookmarkFormValues>>;
$: exploreStore = useExploreStore(exploreName);
$: exploreState = useExploreState(exploreName);
let timeRange: V1TimeRange;
$: timeRange = {
isoDuration: $exploreStore.selectedTimeRange?.name,
start: $exploreStore.selectedTimeRange?.start?.toISOString() ?? "",
end: $exploreStore.selectedTimeRange?.end?.toISOString() ?? "",
isoDuration: $exploreState.selectedTimeRange?.name,
start: $exploreState.selectedTimeRange?.start?.toISOString() ?? "",
end: $exploreState.selectedTimeRange?.end?.toISOString() ?? "",
};
$: selectedTimeRange = getPrettySelectedTimeRange(
Expand Down Expand Up @@ -70,8 +70,8 @@ Managed bookmarks will be available to all viewers of this dashboard.`;
<div class="text-gray-500">Inherited from underlying dashboard view.</div>
</Label>
<FilterChipsReadOnly
dimensionThresholdFilters={$exploreStore.dimensionThresholdFilters}
filters={$exploreStore.whereFilter}
dimensionThresholdFilters={$exploreState.dimensionThresholdFilters}
filters={$exploreState.whereFilter}
{exploreName}
{timeRange}
/>
Expand Down
Loading

1 comment on commit 258151c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.