Skip to content

Fix type/PK -> type/Name and type/FK field remapping in the QB#45047

Merged
ranquild merged 77 commits intomasterfrom
selected-values-remapping
Jul 12, 2024
Merged

Fix type/PK -> type/Name and type/FK field remapping in the QB#45047
ranquild merged 77 commits intomasterfrom
selected-values-remapping

Conversation

@ranquild
Copy link
Copy Markdown
Contributor

@ranquild ranquild commented Jul 2, 2024

Fixes #45063
Fixes #7231
Fixes #37955

BE changes:

  • Hydrates name_field for query metadata.

MBQL lib API changes:

  • Fixes dimensions parsing. This makes external, i.e. type/FK remapping work out of the box.
  • Makes type/PK -> type/Name field remapping work.

FE changes:

  • Makes SearchValuePicker handle mixed remapping options. Adds loading state.
  • Note that selected values are displayed as raw values and this is out of scope for this PR.

How to verify type/PK -> type/Name remapping:

  • Make sure that in Table Metadata for People.Name Entity Name semantic type is set
  • Set Filtering on this field for People.ID to A list of all values
  • Open People table. Click on ID -> Filter on this column. You should see a list of remapped values.
  • Set Filtering on this field for People.ID to Search box
  • Open People table. Click on ID -> Filter on this column. Start typing some name. You should get autocomplete. Please note that the placeholder Search by ID is misleading and this is something that we need to fix separately.

How to verify type/FK -> column remapping:

  • Open Table Metadata -> Orders.Product ID -> Click Use original value -> Use foreign key -> Select Products.Title.
  • Set Filtering on this field to A list of all values
  • Open Orders table. Click on Product ID -> Filter on this column. You should see a list of product names.
  • Do the same with Search box.

@ranquild ranquild self-assigned this Jul 2, 2024
@ranquild ranquild added the backport Automatically create PR on current release branch on merge label Jul 2, 2024
Copy link
Copy Markdown
Contributor

@bshepherdson bshepherdson left a comment

Choose a reason for hiding this comment

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

These changes look sensible to me.

@ranquild ranquild changed the title Basic support for search values remapping [WIP] Basic support for search values remapping Jul 2, 2024
@ranquild ranquild marked this pull request as ready for review July 2, 2024 19:52
@ranquild ranquild requested a review from camsaul as a code owner July 2, 2024 19:52
@replay-io
Copy link
Copy Markdown

replay-io bot commented Jul 2, 2024

Status Complete ↗︎
Commit 1b81e26
Results
⚠️ 4 Flaky
2781 Passed

`:internal`."
[dimensions]
(when-let [dimension (m/find-first (fn [dimension]
(#{"external" "internal"} (object-get dimension "type")))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

dimension is a CLJS map here, not JS object; that's why all object-get calls return nil

@ranquild ranquild marked this pull request as draft July 3, 2024 01:03
@ranquild ranquild changed the title [WIP] Basic support for search values remapping Fix type/FK field remapping in the QB Jul 3, 2024
skip:
fieldId === searchFieldId ||
selectedValues.length === 0 ||
searchValue.length !== 0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this to avoid CLS while user is typing? Or to optimize?
Definitely deserves a comment.

But maybe we don't need it?

);

const options = useMemo(() => getFieldOptions(fieldValues), [fieldValues]);
const options = useMemo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sometimes remapped values turn back to raw values.
In the video I'm using commas to apply subsequent values.

2024-07-11.16-58-45.mp4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2024-07-11.17-13-53.mp4

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

^ native inputs are not changed here, it's a different component

Copy link
Copy Markdown
Contributor Author

@ranquild ranquild Jul 11, 2024

Choose a reason for hiding this comment

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

@kamilmielnik the only reason I can think of why values can turn into raw values:

  • search response -> pick value
  • we can remap the value because search results are still here
  • we send a new remapping request to the newly selected values
  • you start typing something new
  • there is a new search response
  • if the search response becomes available before the remapping response, in this interval you would see unmapped values

I might be able to fix this but this would make the implementation really really much more difficult.

Copy link
Copy Markdown
Contributor Author

@ranquild ranquild Jul 12, 2024

Choose a reason for hiding this comment

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

OK, I made it out of scope of this PR. I cannot make it work cleanly after several days. Please take a look again, and read the PR description again.

});

describe("type/PK -> type/Name remapping (metabase#45063)", () => {
it("should work with questions", () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we assert metrics as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Metrics are going to be reworked soon. It's better not to test them right now

});
});

describe("issue 45063", () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see a repro for #7231

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

there is - you can actually find values

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add a (metabase#7231) tag somewhere (cy.log?) for it.
Also for #37955

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 11, 2024

Codenotify: Notifying subscribers in CODENOTIFY files for diff 7e6adfa...1b81e26.

Notify File(s)
@kdoh frontend/src/metabase/ui/components/inputs/MultiAutocomplete/MultiAutocomplete.tsx

@ranquild ranquild requested review from a team and kamilmielnik July 12, 2024 02:33
@@ -787,15 +787,16 @@
(mu/defn ^:private remapped-field :- [:maybe ::lib.schema.metadata/column]
Copy link
Copy Markdown
Contributor Author

@ranquild ranquild Jul 12, 2024

Choose a reason for hiding this comment

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

PK values are not remapped to type/Name fields. But we allow searching by Name. That's why remapped-field checks for FKs only and is effectively unchanged.

Copy link
Copy Markdown
Contributor

@kamilmielnik kamilmielnik left a comment

Choose a reason for hiding this comment

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

FE code looks good, approving.
Please consider the UX suggestion 🙏

Note that selected values are displayed as raw values and this is out of scope for this PR.

Do we have this reported as a separate issue?

});
});

describe("issue 45063", () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add a (metabase#7231) tag somewhere (cy.log?) for it.
Also for #37955

Comment on lines +57 to +62
const searchOptions = canSearch ? getFieldOptions(fieldValues) : [];
const visibleOptions = getFilteredOptions(
searchOptions,
searchValue,
selectedValues,
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not confident it's a good idea to have FE-side filtering on top of BE-side filtering.
I see where this is coming from but it makes for a bad UX in some of the cases.
I tried it without getFilteredOptions and I think it works way more smooth this way.
Please consult product/design team if you disagree.

There's an annoying flicker of dropdown content on subsequent searches (but not the first one).

2024-07-12.14-08-12.mp4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reported it separately: #45473

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/Querying

Projects

None yet

4 participants