h2oai / wave

Realtime Web Apps and Dashboards for Python and R
https://wave.h2o.ai
Apache License 2.0
3.9k stars 323 forks source link

feat: Support decimal values in table progress cell type #824 #2329

Closed dbranley closed 1 month ago

dbranley commented 1 month ago

Closes #824

The PR fulfills these requirements: (check all the apply)

As explained in the issue, the table progress cell currently rounds values to whole numbers when diplaying them as a percentage. With this change, the percentage will now render with up to 2 decimal places. This is accomplished by using toFixed(2) and parseFloat() together to ensure data is rounded properly and then trailing zeros are removed. The code change in ui/src/progress_table_cell_type.tsx looks like this:

<div className={css.percent}>{`${Number.parseFloat((progress * 100).toFixed(2))}%`}</div>

Here is a partial screen shot of the Table example where you can see the progress data now being displayed with up to 2 decimal places:

output_example_issue_824

There is a new test case in progress_table_cell_type.test.tsx. The test rerenders the XProgressTableCellType component in a loop to make sure that the component is rendering the following input decimal values correctly:

  progressValues = [
    {input: 0.88, output: '88%'},
    {input: 0.888, output: '88.8%'},
    {input: 0.8888, output: '88.88%'},
    {input: 0.88888, output: '88.89%'},
    {input: 0.88899, output: '88.9%'},
    {input: 0.88999, output: '89%'},]

I ran all the ui tests and confirmed they passed. Here is a screen shot for that:

wave_ui_test_issue_824