Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: variable, input and output support for custom dashboards #5301

Merged
merged 22 commits into from
Aug 20, 2024

Conversation

AdityaHegde
Copy link
Collaborator

@AdityaHegde AdityaHegde commented Jul 17, 2024

#5231

Remaining Items

  • Lint fixes
  • Support special characters as arguments in Data query
  • Support platform validation for Vega specs with args inside them
  • Change type for show to string and link with variables store

Spec for select component

# Chart YAML
# Reference documentation: https://docs.rilldata.com/reference/project-files/charts
    
type: component

data:
  metrics_sql: |
    SELECT advertiser_name, measure_2
    FROM Bids_Sample_Dash
    LIMIT 250

output: 
  name: selection
  value: Leafly

select:
  placeholder: No selection
  valueField: advertiser_name
  label: Advertiser name

Sample Spec for Bar template with variable

kind: component

input:
 - name: selection
   type: string
   value: Instacart

data:
  metrics_sql: |
    SELECT
    time_grain_hour,
    measure_2
    FROM
        Bids_Sample_Dash
    WHERE
        __time >= '2023-03-06T00:30:00.000Z' 
        AND __time < '2023-03-08T00:30:00.000Z'
        AND advertiser_name = '{{ .args.selection }}'
    ORDER BY
        time_grain_hour DESC
    LIMIT 200
    OFFSET 0

bar_chart:
  x: time_grain_hour
  y: measure_2

Sample dashboard spec

type: dashboard
columns: 20
gap: 1

variables:
  - name: selection
    type: string
    value: Instacart

items:
  - component: horizontal_bar_chart
    height: 6
    width: 11
    x: 4
    y: 12
  - component: kpi_template
    height: 2
    width: 5
    x: 4
    y: 2
  - component: kpi_template
    height: 2
    width: 6
    x: 9
    y: 2
  - component: selection
    height: 1
    width: 5
    x: 5
    y: 1
  - component: stacked_area_chart
    height: 4
    width: 11
    x: 4
    y: 8
  - component: image
    height: 1
    width: 1
    x: 4
    y: 1
  - component: bar_template
    height: 4
    width: 11
    x: 4
    y: 4

@djbarnwal djbarnwal marked this pull request as ready for review July 25, 2024 09:34
@djbarnwal djbarnwal changed the title feat: variable poc feat: variable, input and output support for custom dashboards Jul 29, 2024
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/httputil"
"github.com/rilldata/rill/runtime/pkg/observability"
"github.com/rilldata/rill/runtime/server/auth"
"go.opentelemetry.io/otel/attribute"
)

func (s *Server) componentDataHandler(w http.ResponseWriter, req *http.Request) error {
func (s *Server) parseTemplate(w http.ResponseWriter, req *http.Request) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the response here is structured and pretty small, it would probably be better to define an RPC with protocol buffers for it

if err != nil {
return nil
}
fmt.Println(name, args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these fmt.Printlns leftover from debugging?

Comment on lines 156 to 164
res, err := ctrl.Get(ctx, &runtimev1.ResourceName{Kind: runtime.ResourceKindComponent, Name: name}, false)
if err != nil {
return nil
}

blob, _, err := s.runtime.GetFile(ctx, instanceID, res.Meta.GetFilePaths()[0])
if err != nil {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not safe to rely on file loading from APIs that are used for dashboard serving because the files may be unavailable (for example, if the Github clone takes a long time or Github is unavailable). Viewer roles also are not allowed to have any way of loading files for security reasons.

So it should only use fields in res (which are available for querying as soon as the server is up).

@begelundmuller
Copy link
Contributor

Here's a PR that adds an RPC that addresses the above issues with the parseTemplate and componentDataHandler APIs: #5362.

@djbarnwal djbarnwal self-requested a review August 20, 2024 08:35
@djbarnwal djbarnwal merged commit 135e909 into main Aug 20, 2024
7 checks passed
@djbarnwal djbarnwal deleted the feat/variable-poc branch August 20, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants