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

Fix Embedded dashboard parameters parse runtime error #41545

Merged
merged 3 commits into from Apr 18, 2024

Conversation

deniskaber
Copy link
Contributor

@deniskaber deniskaber commented Apr 17, 2024

Closes #41483

Description

This fixes runtime issue with parsing embedded / public dashboard parameters that represent numbers with leading "0".
Mainly caused by https://github.com/metabase/metabase/pull/38271/files#diff-c472624b3ca71f585a7e771826cca7ae8434b170963e19f384cbde56d066c804R110-R113

How to verify

Follow steps from #41483

Demo

Upload a demo video or before/after screenshots if sensible or remove the section

Checklist

  • Tests have been added/updated to cover changes in this PR

@deniskaber deniskaber self-assigned this Apr 17, 2024
@deniskaber deniskaber added .Team/Embedding backport Automatically create PR on current release branch on merge labels Apr 17, 2024
@deniskaber deniskaber added this to the 0.49.7 milestone Apr 17, 2024
@deniskaber deniskaber requested a review from a team April 17, 2024 19:33
@deniskaber deniskaber changed the title Fix parameters parse Fix Embedded dashboard parameters parse runtime error Apr 17, 2024
Copy link

replay-io bot commented Apr 17, 2024

Status Complete ↗︎
Commit 2955a3d
Results
⚠️ 8 Flaky
2402 Passed

Copy link
Contributor

@heypoom heypoom left a comment

Choose a reason for hiding this comment

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

Code and tests looks good! I wonder if we should warn the developer who is embedding the dashboard that their embedding parameter is invalid, in case they accidentally made a typo.

});

// should not throw runtime error and render dashboard content
expect(screen.getByText(DASHBOARD_TITLE)).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

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

This test only verifies that the dashboard is rendered not crashed. But it doesn't assert that the filter value is retained.

I've tried a few iterations to make this unit test work by passing dashcards and parameters but couldn't do that. Maybe you could try or create an E2E if that's easier. I think it's important to capture that 01 would still be present and used as a filter.

At first I thought this code wasn't fixing the issue because there's also no filter value assertion in the test.

});

// should not throw runtime error and render dashboard content
expect(screen.getByText(DASHBOARD_TITLE)).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

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

I think the behaviour customers expect is that the filter will have value 1, should we make an expect on that too?
I think we'll need to so some more mocking to make the filter show up in the UI

Copy link
Member

Choose a reason for hiding this comment

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

To get 01 in the URL, customer needs to enter 01 in the filter. If the initial result shows as 01 then I'd expect that he might expect it to still show 01 (like what it initially was before refreshing the page)
image

Copy link
Member

@WiNloSt WiNloSt left a comment

Choose a reason for hiding this comment

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

I'll approve, but could you modify the test as suggested? That ensures that the value will be actually used in a filter rather than asserting non-existing filter.

it("should render when a filter passed with value starting from '0' (metabase#41483)", () => {
cy.get("@dashboardId").then(id => {
visitPublicDashboard(id, {
params: { number: "02" },
Copy link
Member

@WiNloSt WiNloSt Apr 18, 2024

Choose a reason for hiding this comment

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

could you use text as it's already existing?

Suggested change
params: { number: "02" },
params: { text: "02" },

image

Then we should be able to query the widget value like so

    cy.url().should("include", "text=02");
    filterWidget().findByText("02").should("be.visible");

@vvaezian
Copy link

vvaezian commented Apr 18, 2024

@heypoom

I wonder if we should warn the developer who is embedding the dashboard that their embedding parameter is invalid

@npretto

I think the behaviour customers expect is that the filter will have value 1

Filter value with a leading zero is not invalid. It's common in ID columns to have leading zeros. Therefore the leading zero should not be removed when used as filter value.

@deniskaber deniskaber enabled auto-merge (squash) April 18, 2024 17:04
@deniskaber deniskaber merged commit 198ebcf into master Apr 18, 2024
109 checks passed
@deniskaber deniskaber deleted the 41483-embedding-params-zero branch April 18, 2024 17:15
github-actions bot pushed a commit that referenced this pull request Apr 18, 2024
* Fix parameters parse

* Add e2e test

* Add e2e test
metabase-bot bot added a commit that referenced this pull request Apr 18, 2024
* Fix parameters parse

* Add e2e test

* Add e2e test

Co-authored-by: Denis Berezin <denis.berezin@metabase.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Automatically create PR on current release branch on merge .Team/Embedding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leading zero in filter value in embedded dashboard breaks it
5 participants