Skip to content

Commit

Permalink
Converts from and to V1ExplorePreset
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Oct 22, 2024
1 parent 7921816 commit fd6f6c1
Show file tree
Hide file tree
Showing 22 changed files with 1,279 additions and 316 deletions.
388 changes: 211 additions & 177 deletions proto/gen/rill/runtime/v1/resources.pb.go

Large diffs are not rendered by default.

91 changes: 75 additions & 16 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.

2 changes: 2 additions & 0 deletions proto/gen/rill/runtime/v1/runtime.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3999,6 +3999,8 @@ 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: |-
Expand Down
28 changes: 15 additions & 13 deletions proto/rill/runtime/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -382,33 +382,35 @@ message ExplorePreset {
// 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 = 25;

// 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;
string timezone = 11;
string time_grain = 12;
optional string time_range = 6;
optional string timezone = 11;
optional string time_grain = 12;

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

ExploreWebView view = 14;
optional ExploreWebView view = 14;

string overview_sort_by = 15;
bool overview_sort_asc = 16;
string overview_expanded_dimension = 17;
optional string overview_sort_by = 15;
optional bool overview_sort_asc = 16;
optional string overview_expanded_dimension = 17;

string time_dimension_measure = 18;
string time_dimension_chart_type = 19;
bool time_dimension_pin = 20;
optional string time_dimension_measure = 18;
optional string time_dimension_chart_type = 19;
optional bool time_dimension_pin = 20;

repeated string pivot_rows = 21;
repeated string pivot_cols = 22;
string pivot_sort_by = 23;
bool pivot_sort_asc = 24;
optional string pivot_sort_by = 23;
optional bool pivot_sort_asc = 24;
}

enum ExploreComparisonMode {
Expand Down
14 changes: 11 additions & 3 deletions runtime/compilers/rillv1/parse_explore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type ExploreYAML struct {
commonYAML `yaml:",inline"` // Not accessed here, only setting it so we can use KnownFields for YAML parsing
commonYAML `yaml:",inline"` // Not accessed here, only setting it so we can use KnownFields for YAML parsing
Title string `yaml:"title"`
Description string `yaml:"description"`
MetricsView string `yaml:"metrics_view"`
Expand Down Expand Up @@ -214,14 +214,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
41 changes: 24 additions & 17 deletions runtime/compilers/rillv1/parse_metrics_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@ import (
"fmt"
"strings"
"time"
// Load IANA time zone data
_ "time/tzdata"

runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime/pkg/duration"
"gopkg.in/yaml.v3"

// Load IANA time zone data
_ "time/tzdata"
)

// MetricsViewYAML is the raw structure of a MetricsView resource defined in YAML
type MetricsViewYAML struct {
commonYAML `yaml:",inline"` // Not accessed here, only setting it so we can use KnownFields for YAML parsing
Title string `yaml:"title"`
DisplayName string `yaml:"display_name"` // Backwards compatibility
Description string `yaml:"description"`
Model string `yaml:"model"`
Database string `yaml:"database"`
DatabaseSchema string `yaml:"database_schema"`
Table string `yaml:"table"`
TimeDimension string `yaml:"timeseries"`
Watermark string `yaml:"watermark"`
SmallestTimeGrain string `yaml:"smallest_time_grain"`
FirstDayOfWeek uint32 `yaml:"first_day_of_week"`
FirstMonthOfYear uint32 `yaml:"first_month_of_year"`
Title string `yaml:"title"`
DisplayName string `yaml:"display_name"` // Backwards compatibility
Description string `yaml:"description"`
Model string `yaml:"model"`
Database string `yaml:"database"`
DatabaseSchema string `yaml:"database_schema"`
Table string `yaml:"table"`
TimeDimension string `yaml:"timeseries"`
Watermark string `yaml:"watermark"`
SmallestTimeGrain string `yaml:"smallest_time_grain"`
FirstDayOfWeek uint32 `yaml:"first_day_of_week"`
FirstMonthOfYear uint32 `yaml:"first_month_of_year"`
Dimensions []*struct {
Name string
Label string
Expand Down Expand Up @@ -872,14 +871,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
16 changes: 7 additions & 9 deletions web-admin/src/features/embeds/ExploreEmbed.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script lang="ts">
import { Dashboard } from "@rilldata/web-common/features/dashboards";
import DashboardThemeProvider from "@rilldata/web-common/features/dashboards/DashboardThemeProvider.svelte";
import DashboardURLStateProvider from "@rilldata/web-common/features/dashboards/proto-state/DashboardURLStateProvider.svelte";
import DashboardURLStateSync from "@rilldata/web-common/features/dashboards/url-state/DashboardURLStateSync.svelte";
import StateManagersProvider from "@rilldata/web-common/features/dashboards/state-managers/StateManagersProvider.svelte";
import DashboardStateProvider from "@rilldata/web-common/features/dashboards/stores/DashboardStateProvider.svelte";
import { createRuntimeServiceGetExplore } from "@rilldata/web-common/runtime-client";
import { errorStore } from "../errors/error-store";
Expand Down Expand Up @@ -38,13 +37,12 @@
{:else if data}
{#key exploreName}
<StateManagersProvider {exploreName} {metricsViewName}>
<DashboardStateProvider {exploreName}>
<DashboardURLStateProvider {metricsViewName}>
<DashboardThemeProvider>
<Dashboard {exploreName} {metricsViewName} />
</DashboardThemeProvider>
</DashboardURLStateProvider>
</DashboardStateProvider>
<!-- TODO -->
<DashboardURLStateSync partialMetrics={{}}>
<DashboardThemeProvider>
<Dashboard {exploreName} {metricsViewName} />
</DashboardThemeProvider>
</DashboardURLStateSync>
</StateManagersProvider>
{/key}
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import { viewAsUserStore } from "@rilldata/web-admin/features/view-as-user/viewAsUserStore";
import { Dashboard } from "@rilldata/web-common/features/dashboards";
import DashboardThemeProvider from "@rilldata/web-common/features/dashboards/DashboardThemeProvider.svelte";
import DashboardURLStateProvider from "@rilldata/web-common/features/dashboards/proto-state/DashboardURLStateProvider.svelte";
import DashboardURLStateSync from "@rilldata/web-common/features/dashboards/url-state/DashboardURLStateSync.svelte";
import StateManagersProvider from "@rilldata/web-common/features/dashboards/state-managers/StateManagersProvider.svelte";
import DashboardStateProvider from "@rilldata/web-common/features/dashboards/stores/DashboardStateProvider.svelte";
import { useExplore } from "@rilldata/web-common/features/explores/selectors";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
Expand Down Expand Up @@ -88,20 +87,18 @@
<StateManagersProvider {metricsViewName} {exploreName}>
{#if $user.isSuccess && $user.data.user}
<DashboardBookmarksStateProvider {metricsViewName} {exploreName}>
<DashboardURLStateProvider {metricsViewName}>
<DashboardURLStateSync>
<DashboardThemeProvider>
<Dashboard {metricsViewName} {exploreName} />
</DashboardThemeProvider>
</DashboardURLStateProvider>
</DashboardURLStateSync>
</DashboardBookmarksStateProvider>
{:else}
<DashboardStateProvider {exploreName}>
<DashboardURLStateProvider {metricsViewName}>
<DashboardThemeProvider>
<Dashboard {metricsViewName} {exploreName} />
</DashboardThemeProvider>
</DashboardURLStateProvider>
</DashboardStateProvider>
<DashboardURLStateSync>
<DashboardThemeProvider>
<Dashboard {metricsViewName} {exploreName} />
</DashboardThemeProvider>
</DashboardURLStateSync>
{/if}
</StateManagersProvider>
{/key}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const metricsViewReducers = {
schema,
);
if (!partial) return;
console.log("syncFromUrl", partial);

updateMetricsExplorerByName(name, (metricsExplorer) => {
for (const key in partial) {
Expand All @@ -204,7 +205,7 @@ const metricsViewReducers = {
});
},

syncFromUrlParams(
mergePartialExplorerEntity(
name: string,
partialMetrics: Partial<MetricsExplorerEntity>,
metricsView: V1MetricsViewSpec,
Expand All @@ -227,6 +228,7 @@ const metricsViewReducers = {
sync(name: string, explore: V1ExploreSpec) {
if (!name || !explore || !explore.measures) return;
updateMetricsExplorerByName(name, (metricsExplorer) => {
console.log("sync");
// remove references to non existent measures
syncMeasures(explore, metricsExplorer);

Expand Down
15 changes: 8 additions & 7 deletions web-common/src/features/dashboards/stores/syncDashboardState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function createDashboardStateSync(
// Successive syncs with metrics view spec
// metricsExplorerStore.sync(exploreName, explore);
} else {
console.log("init");
// Running for the 1st time. Initialise the dashboard store.
metricsExplorerStore.init(
exploreName,
Expand All @@ -79,13 +80,13 @@ export function createDashboardStateSync(
get(page).url.searchParams.get("state") ?? initialUrlStateRes?.data;
if (initialUrlState) {
// If there is data to be loaded, load it during the init
metricsExplorerStore.syncFromUrl(
exploreName,
initialUrlState,
metricsView,
explore,
metricsViewSchemaRes.data.schema,
);
// metricsExplorerStore.syncFromUrl(
// exploreName,
// initialUrlState,
// metricsView,
// explore,
// metricsViewSchemaRes.data.schema,
// );
// Call sync to make sure changes in dashboard are honoured
metricsExplorerStore.sync(exploreName, explore);
}
Expand Down
Loading

0 comments on commit fd6f6c1

Please sign in to comment.