Skip to content

Conversation

@iethree
Copy link
Contributor

@iethree iethree commented Aug 3, 2022

Description

This adds support for query options for dashboard parameters. The current frontend implementation simply includes the default options for each operator. The practical result is that for a "contains" operator, we now run a case-insensitive query. This also enables us to allow configurable options on the frontend in the future.

Screen Shot 2022-08-03 at 4 47 43 PM

Resolves #21359

Results

before after
Screen Shot 2022-08-04 at 6 12 10 AM Screen Shot 2022-08-04 at 6 11 49 AM

This PR is a draft because while it solves the problem of string filters being case sensitive, it doesn't necessarily
do it in the best way.

This isn't necessarily
a bug, but it seems that there is no way for the frontend to set the :case-sensitive true/false option anyway.

For the purposes of this initial attempt at a solution, I have modified the endpoint
` POST "/:dashboard-id/dashcard/:dashcard-id/card/:card-id/query"` to automatically include an option map containing
:case-sensitive false.

The machinery to take this option into consideration already exists with the default :sql ->honeysql function in the `
metabase.driver.sql.query-processor` namespace. See the `like-clause` private function in particular.

Since the query processor is a bit opaque to me at present, I was unable to figure out if there is a proper way that
the frontend could send an options map (or key-value pair) all the way through the qp middleware to the query building
stage. I discovered that if you conj a map `{:case-sensitive false}` to the output of the `to-clause` function in
`metabase.driver.common.parameters.operators`, you will get the desired case-insensitive behavior. So, I modified the
to-clause function in this PR to appropriately conj an options map if one exists.

What I'd like to know:

- is there a super-simple way to pass an option in already that I just missed? (eg. I thought perhaps in the `[:field
13 nil]` that 'nil' could be an options map, but I couldn't get that to work for me)

- is there a middleware approach that I should consider?

- any other options to appropriately hanlde this?
If the frontend sends an options map on an options key inside the parameter, this endpoint will pass that on, so no
change is needed.
@iethree iethree requested review from a team and adam-james-v August 3, 2022 22:52
@iethree iethree self-assigned this Aug 3, 2022
@codecov
Copy link

codecov bot commented Aug 3, 2022

Codecov Report

Merging #24582 (ac4d7fe) into master (d26ecbf) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master   #24582      +/-   ##
==========================================
- Coverage   65.29%   65.27%   -0.03%     
==========================================
  Files        2785     2788       +3     
  Lines       85187    85223      +36     
  Branches    10506    10524      +18     
==========================================
+ Hits        55623    55629       +6     
- Misses      25232    25253      +21     
- Partials     4332     4341       +9     
Flag Coverage Δ
back-end 85.81% <0.00%> (-0.02%) ⬇️
front-end 46.40% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
frontend/src/metabase/meta/Card.js 23.52% <0.00%> (-0.72%) ⬇️
...rc/metabase/driver/common/parameters/operators.clj 41.86% <0.00%> (-10.64%) ⬇️
...ts/settings/ChartSettingFieldsPartition.styled.tsx 71.42% <0.00%> (-28.58%) ⬇️
...ions/components/ScalarValue/ScalarValue.styled.tsx 90.00% <0.00%> (-10.00%) ⬇️
...d/src/metabase/parameters/utils/mapping-options.js 78.94% <0.00%> (-3.41%) ⬇️
...ns/components/ObjectDetail/ObjectRelationships.tsx 72.22% <0.00%> (-2.78%) ⬇️
...ns/components/ObjectDetail/ObjectDetail.styled.tsx 82.35% <0.00%> (-2.27%) ⬇️
...c/metabase/visualizations/visualizations/Gauge.jsx 29.36% <0.00%> (-2.26%) ⬇️
...ualizations/components/ScalarValue/ScalarValue.jsx 76.92% <0.00%> (-1.65%) ⬇️
frontend/src/metabase/components/ExplicitSize.jsx 7.57% <0.00%> (-0.37%) ⬇️
... and 16 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@iethree iethree force-pushed the case-insensitive-dashboard-filter branch from 03de196 to 8eb221b Compare August 3, 2022 23:09
Copy link
Contributor

@adam-james-v adam-james-v left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Looks good to me 👍

…ase-sensitive-issue-21359' into case-insensitive-dashboard-filter
@adam-james-v adam-james-v added the backport Automatically create PR on current release branch on merge label Aug 4, 2022
@adam-james-v adam-james-v merged commit 5b0b592 into master Aug 4, 2022
@adam-james-v adam-james-v deleted the case-insensitive-dashboard-filter branch August 4, 2022 18:02
github-actions bot pushed a commit that referenced this pull request Aug 4, 2022
* Dashboard Card String Filters are now case-insensitive

This PR is a draft because while it solves the problem of string filters being case sensitive, it doesn't necessarily
do it in the best way.

This isn't necessarily
a bug, but it seems that there is no way for the frontend to set the :case-sensitive true/false option anyway.

For the purposes of this initial attempt at a solution, I have modified the endpoint
` POST "/:dashboard-id/dashcard/:dashcard-id/card/:card-id/query"` to automatically include an option map containing
:case-sensitive false.

The machinery to take this option into consideration already exists with the default :sql ->honeysql function in the `
metabase.driver.sql.query-processor` namespace. See the `like-clause` private function in particular.

Since the query processor is a bit opaque to me at present, I was unable to figure out if there is a proper way that
the frontend could send an options map (or key-value pair) all the way through the qp middleware to the query building
stage. I discovered that if you conj a map `{:case-sensitive false}` to the output of the `to-clause` function in
`metabase.driver.common.parameters.operators`, you will get the desired case-insensitive behavior. So, I modified the
to-clause function in this PR to appropriately conj an options map if one exists.

What I'd like to know:

- is there a super-simple way to pass an option in already that I just missed? (eg. I thought perhaps in the `[:field
13 nil]` that 'nil' could be an options map, but I couldn't get that to work for me)

- is there a middleware approach that I should consider?

- any other options to appropriately hanlde this?

* Revert the endpoint.

If the frontend sends an options map on an options key inside the parameter, this endpoint will pass that on, so no
change is needed.

* include parameter options in datasetQuery

Co-authored-by: Adam James <[email protected]>
metabase-bot bot added a commit that referenced this pull request Aug 4, 2022
#24609)

* Dashboard Card String Filters are now case-insensitive

This PR is a draft because while it solves the problem of string filters being case sensitive, it doesn't necessarily
do it in the best way.

This isn't necessarily
a bug, but it seems that there is no way for the frontend to set the :case-sensitive true/false option anyway.

For the purposes of this initial attempt at a solution, I have modified the endpoint
` POST "/:dashboard-id/dashcard/:dashcard-id/card/:card-id/query"` to automatically include an option map containing
:case-sensitive false.

The machinery to take this option into consideration already exists with the default :sql ->honeysql function in the `
metabase.driver.sql.query-processor` namespace. See the `like-clause` private function in particular.

Since the query processor is a bit opaque to me at present, I was unable to figure out if there is a proper way that
the frontend could send an options map (or key-value pair) all the way through the qp middleware to the query building
stage. I discovered that if you conj a map `{:case-sensitive false}` to the output of the `to-clause` function in
`metabase.driver.common.parameters.operators`, you will get the desired case-insensitive behavior. So, I modified the
to-clause function in this PR to appropriately conj an options map if one exists.

What I'd like to know:

- is there a super-simple way to pass an option in already that I just missed? (eg. I thought perhaps in the `[:field
13 nil]` that 'nil' could be an options map, but I couldn't get that to work for me)

- is there a middleware approach that I should consider?

- any other options to appropriately hanlde this?

* Revert the endpoint.

If the frontend sends an options map on an options key inside the parameter, this endpoint will pass that on, so no
change is needed.

* include parameter options in datasetQuery

Co-authored-by: Adam James <[email protected]>

Co-authored-by: Ryan Laurie <[email protected]>
Co-authored-by: Adam James <[email protected]>
@abhayait
Copy link

abhayait commented Dec 8, 2022

From which version the case insensitive fix is available?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard's "text/contains" filter is case-sensitive

5 participants