evidence-dev / evidence

Business intelligence as code: build fast, interactive data visualizations in pure SQL and markdown
https://evidence.dev
MIT License
4.44k stars 212 forks source link

[Bug]: Slider can't accept dynamic defaultValue #2539

Open Ash-Woods opened 2 months ago

Ash-Woods commented 2 months ago

Describe the bug

I am attempting to pass a dynamic defaultValue on a Slider so that users can adjust the value as needed from a more configurable position, rather than solely starting at 0. I am using the below code:

<Slider
    title="Median Days" 
    name=days_slider
    min=0
    max={max_flow_time_median_days[0].max_value}
    defaultValue={max_flow_time_median_days[0].max_value}
/>

and it continues to default at 0.

image (13)

Steps to Reproduce

Create the query, then create the Slider. Once complete, load the page in dev mode and it navigate to the rendered component on the screen.

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1
    Memory: 185.11 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.13.1 - /usr/local/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.5.2 - /usr/local/bin/npm
    Watchman: 2024.08.26.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 128.0.6613.120
    Safari: 17.5
  npmPackages:
    @evidence-dev/bigquery: ^2.0.7 => 2.0.7 
    @evidence-dev/core-components: ^4.7.5 => 4.7.5 
    @evidence-dev/csv: ^1.0.12 => 1.0.12 
    @evidence-dev/databricks: ^1.0.7 => 1.0.7 
    @evidence-dev/duckdb: ^1.0.11 => 1.0.11 
    @evidence-dev/evidence: ^39.1.4 => 39.1.4 
    @evidence-dev/motherduck: ^1.0.2 => 1.0.2 
    @evidence-dev/mssql: ^1.0.9 => 1.0.9 
    @evidence-dev/mysql: ^1.1.3 => 1.1.3 
    @evidence-dev/postgres: ^1.0.6 => 1.0.6 
    @evidence-dev/snowflake: ^1.1.1 => 1.1.1 
    @evidence-dev/sqlite: ^2.0.6 => 2.0.6 
    @evidence-dev/trino: ^1.0.8 => 1.0.8 
    evidence-connector-aws-athena: ^1.2.0 => 1.2.0

Severity

annoyance

Additional Information, or Workarounds

No response

ItsMeBrianD commented 2 months ago

This is an interesting use-case for the slider, thanks for filing this!

I would propose that the Slider accept some props like this:

<Slider
    title="Median Days" 
    name=days_slider
    data={max_flow_time_median_days}
    min=0
    maxColumn=max_value
    defaultValue=max_value
/>

This ties it to a query, and makes it a little more intuitive to update the defaultValue after the slider has already been rendered (and potentially interacted with).

Ash-Woods commented 2 months ago

Thanks @ItsMeBrianD , that sounds great!

archiewood commented 3 weeks ago

Suggested alternative approach- make the default value reactive to changes in the values that are passed to it.

kwongz commented 3 weeks ago

fixed #2672