-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[App Search] Updated Search UI to new URL #101320
[App Search] Updated Search UI to new URL #101320
Conversation
@elasticmachine merge upstream |
@@ -87,6 +90,14 @@ export const EngineLogic = kea<MakeLogicType<EngineValues, EngineActions>>({ | |||
() => [selectors.engine], | |||
(engine) => engine?.unconfirmedFields?.length > 0, | |||
], | |||
searchKey: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to POST the search key to the new search experience URL from the Search UI form. Since all keys that are valid for a particular engine are already available on engine.apiTokens
from state, I added a selector to easily access the first available search token.
Since tokens that do not have access to the current engine are not returned in this object, I do not have to check their access level, as we already know it has access to the current engine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this added logic/selector. Feels elegant and makes sense.
const { engineName } = EngineLogic.values; | ||
const { searchKey, engineName } = EngineLogic.values; | ||
|
||
if (!searchKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We make a call to fetch all the data that the Search UI form needs below. As part of this API call, the API will actualy return an "errors" field that will return the message "It looks like you don't have any Public Search Keys with access to the 'engine1' engine. Please visit the Credentials page to set one up." In ent-search, we simply printed the error from that field to the screen.
In this UI, I opted to explicitly check for that condition and add that error message to an i18n string, so that it can be translated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I agree with this approach. It's seems strange to add this to listener that largely does an http call. I think I would have kept this as a static part of the SearchUiForm with useValues(EngineLogic)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I think I chose to put it in this logic file because I wanted to use our flash messaging system, which is stateful and requires a call to something like setErrorMessage
to use.
I could have done that in like a useEffect in SearchUiForm
but that seems clunkier. I like it here because we can short circuit the API call and all flash messages are generated from the logic file.
It could also be a stateless check where we just do like !searchKey && <EuiCallout...
, but then that conflicts with the flash messaging system we use. Like it gets hairy having them both exist on the page together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I see Byron's point - it does seem odd to skip loading fieldData entirely just because a searchKey is missing. I don't think this is overly clunky to put in a useEffect personally - would you be cool with making that change?
const { searchKey, engineName } = useValues(EngineLogic);
useEffect(() => {
if (!searchKey) setErrorMessage(NO_SEARCH_KEY_ERROR(engineName));
}, [searchKey]);
3 or so lines doesn't feel so bad to me, and I do think it makes more sense (conceptually) in the view than this specific listener.
Definitely ++ to keeping this using our flash messages + i18n though!
@@ -33,7 +33,7 @@ describe('generatePreviewUrl', () => { | |||
empty2: [''], // Empty fields should be stripped | |||
}) | |||
).toEqual( | |||
'http://localhost:3002/as/engines/national-parks-demo/reference_application/preview?facets[]=baz&facets[]=qux&sortFields[]=quux&sortFields[]=quuz&titleField=foo&urlField=bar' | |||
'http://localhost:3002/as/engines/national-parks-demo/search_experience/preview?facets[]=baz&facets[]=qux&sortFields[]=quux&sortFields[]=quuz&titleField=foo&urlField=bar' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new route that was set up specifically for this form, which accepts a search token in order to render the search experience preview, rather than authenticating like the former route.
@@ -119,8 +127,8 @@ export const SearchUIForm: React.FC = () => { | |||
/> | |||
</EuiFormRow> | |||
<EuiButton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than being a link as before, this is not a form with a submit button so that we can POST to the new route.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, I had two question-that-is-really-more-of-a-comments. I'm going to QA now
searchKey: [ | ||
() => [selectors.engine], | ||
(engine: Partial<EngineDetails>) => { | ||
const isSearchKey = (token: ApiToken) => token.type === ApiTokenTypes.Search; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could pull this function out instead of declaring it in here every time (idk if its worth writing a test for it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going completely the opposite direction, I would have just left it as an inline fn in .find()
But it doesn't bother me either way personally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, quite the array of opinions! I just pulled this out for readability. It was long in the tooth inline in the find
.
const { engineName } = EngineLogic.values; | ||
const { searchKey, engineName } = EngineLogic.values; | ||
|
||
if (!searchKey) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I agree with this approach. It's seems strange to add this to listener that largely does an http call. I think I would have kept this as a static part of the SearchUiForm with useValues(EngineLogic)
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
@byronhulcher Are you looking for any changes in particular before approving? |
...earch/public/applications/app_search/components/search_ui/components/search_ui_form.test.tsx
Show resolved
Hide resolved
titleField: 'bar', | ||
facets: ['baz'], | ||
sortFields: ['qux'], | ||
it('should disable everything while data is loading', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this piece of UX + test - love it! 🎉
This LGTM - I think I'm +1 to Byron on #101320 (comment), and moving the error display to a view |
Ok. I'll make the change, though TBH, I'm really medium on it and don't really feel like expending the cycles. |
Just keep an eye on it so we can get this approved and merged please. |
@JasonStoltz if you're feeling medium on it but wouldn't mind it happening, I'd be cool pushing up the change in your stead to save you some effort. Totally up to you though! |
Actually, I do feel strongly about this. I want the fields to be disabled if there is no search key, there's no way you can generate a UI without one. So it's pointless to fetch the fields. I am also relying on the |
Ahhh that's a solid point about disabling fields that I missed! I think that's a good enough argument to not block this PR and I'm fine with merging this in as-is 👍 |
🙇♂️ 🙏 |
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
* master: (54 commits) Implement "select all" rules feature (elastic#100554) [ML] Remove script fields from the Anomaly detection alerting rule executor (elastic#101607) [Security solutions][Endpoint] Update event filtering texts (elastic#101563) [Enterprise Search] Mocks/tests tech debt - avoid hungry mocking (elastic#101107) [FTR] Updates esArchive paths [FTR] Updates esArchive paths [Security Solution][Detection Engine] Adds runtime field tests (elastic#101664) Added APM PHP agent to the list of agent names (elastic#101062) [CI] Restore old version_info behavior when .git directory is present (elastic#101642) [Fleet] Add fleet server telemetry (elastic#101400) [APM] Syncs agent config settings to APM Fleet policies (elastic#100744) [esArchiver] drop support for --dir, use repo-relative paths instead (elastic#101345) Revert "[xpack/test] restore incremental: false in ts project" [Security Solution] Remove Host Isolation feature flag (elastic#101655) [xpack/test] restore incremental: false in ts project [DOCS] Adds link to video landing page (elastic#101413) [ML] Move Index Data Visualizer into separate plugin (Part 1) (elastic#100922) Improve security plugin return types (elastic#101492) [ts] migrate `x-pack/test` to composite ts project (elastic#101441) [App Search] Updated Search UI to new URL (elastic#101320) ...
Summary
This PR does 2 things:
When testing:
Checklist
Delete any items that are not applicable to this PR.
For maintainers