Skip to content

[App Search] Suggestions Callouts for Engine, Analytics, and Manual Curation Detail#113864

Merged
byronhulcher merged 13 commits intoelastic:masterfrom
byronhulcher:suggestions-callout
Oct 6, 2021
Merged

[App Search] Suggestions Callouts for Engine, Analytics, and Manual Curation Detail#113864
byronhulcher merged 13 commits intoelastic:masterfrom
byronhulcher:suggestions-callout

Conversation

@byronhulcher
Copy link
Copy Markdown
Contributor

@byronhulcher byronhulcher commented Oct 4, 2021

Summary

Implements two new components:

  • SuggestedCurationsCallout, included on our Engine and Analytics pages
  • SuggestedDocumentsCallout, included on our Curation Detail page for manual curations

These are powered by an underlying SuggestionsCallout component that utilizes localstorage (through our useLocalStorage hook) to track whether the callout has been dismissed or not. The callout uses location.pathname to identify whether it has been dismissed already or not. This assumes that only one SuggestionsCallout is present per view/unique location.pathname.

Screenshots

Screen Shot 2021-10-04 at 8 00 46 PM

Screen Shot 2021-10-04 at 8 03 31 PM

Screen Shot 2021-10-04 at 8 10 12 PM

Checklist

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.

This is weird, but it seems more readable than {...MOCK_VALUES, {...MOCK_VALUES.curation, curation: etc etc, and I think its better than just writing a whole new object, because this highlights specifically whats changed vs the defaults. But it is kinda weird (I wish lodash.set didn't mutate the source object)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See comment above about lodash fp

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.

Thanks for the tip! I did this in a2a3a8a

@byronhulcher byronhulcher force-pushed the suggestions-callout branch 2 times, most recently from ecf9a61 to 7b1a5bd Compare October 4, 2021 23:13
iconType="eyeClosed"
size="s"
onClick={() => {
setLastDismissedTimestamp(new Date().toISOString());
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.

An ISO timestamp is of form 2021-10-04T22:53:20.588Z. This matches the style of the timestamp we get back from the API. We've used both ISO timestamps and unix timestamps interchangeably in our codebase so far.

@byronhulcher byronhulcher marked this pull request as ready for review October 5, 2021 00:30
@byronhulcher byronhulcher requested review from a team and JasonStoltz October 5, 2021 00:30
@byronhulcher byronhulcher changed the title Suggestions Callouts for Engine, Analytics, and Manual Curation Detail [App Search] Suggestions Callouts for Engine, Analytics, and Manual Curation Detail Oct 5, 2021
@byronhulcher byronhulcher added auto-backport Deprecated - use backport:version if exact versions are needed Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.16.0 labels Oct 5, 2021
@byronhulcher
Copy link
Copy Markdown
Contributor Author

This has conflicts but should still be reviewed, they will be resolved once #113885 is merged

Copy link
Copy Markdown
Member

@JasonStoltz JasonStoltz left a comment

Choose a reason for hiding this comment

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

I'm good with this, just a couple of optional suggestions to consider. Let me know what you think.

import { ENGINE_CURATION_SUGGESTION_PATH } from '../../../routes';
import { generateEnginePath } from '../../engine';

import { SuggestionsCallout } from '../components/suggestions_callout';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, I like how these share a base callout component.

curation: { suggestion, queries },
} = useValues(CurationLogic);

if (typeof suggestion === 'undefined' || suggestion.status !== 'pending') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just curious why you check for undefined rather than falsy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would be nice to have statuses in an enum or at constants.

Copy link
Copy Markdown
Contributor Author

@byronhulcher byronhulcher Oct 5, 2021

Choose a reason for hiding this comment

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

Just curious why you check for undefined rather than falsy.

To be honest, I default to checking specifically for undefined so I don't have to remember whether false/0/""/{} etc are a valid value for the variable or not.

Would be nice to have statuses in an enum or at constants.

This field uses a union to enforce specific values

  status: 'pending' | 'applied' | 'automated' | 'rejected' | 'disabled';

VSCode and tsc will complain if you use a value here that's not one of these strings. And I can still hover over stuggestion.status and it lists all the valid strings. In fact its kind of more useful than enums because for an SuggestionStatus enum it would just say status: SuggestionStatus.

When I used enums on Crawler there was some pushback against that and towards using unions. I dunno which is better tbh. For what its worth I think using a union still enforces a single "source of truth" for valid values, and I think its unlikely we'd change these valid values (that would be a breaking API change) so I'm not super worried about having to search/replace this. Anyway tsc would let us know which values we forgot to update.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, maybe adding the strings to a constants file at least. We can deal with that in a different PR if we want.


it('is empty when curation status is not pending', () => {
const values = cloneDeep(MOCK_VALUES); // set mutates so we cloneDeep first
set(values, 'curation.suggestion.status', 'applied');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, using set makes these tests more concise, I like it.

I think you could use lodash/fp which is immutable...

import { set } from 'lodash/fp';
set('curation.suggestion.status', 'applied', values)

That would avoid the cloneDeep

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.

Thanks for the tip, I did this in a2a3a8a


interface SearchRelevanceSuggestions {
count: number;
curation: {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have a type for curation already that we could use here?

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.

So this is more like a summary/details type than the CurationSuggestion type use get back from our endpoints. These are aggregated details coming from an internal endpoint. We do this for meta engines and crawler as well to track similar top-level engine level information we want to be aware of in the whole Engine UX. I tried to clarify that with new names in e0ed6a4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See comment above about lodash fp

@tylersmalley
Copy link
Copy Markdown
Member

@elasticmachine merge upstream

@tylersmalley
Copy link
Copy Markdown
Member

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
enterpriseSearch 1517 1520 +3

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
enterpriseSearch 1.4MB 1.4MB +2.8KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Oct 6, 2021
…uration Detail (#113864) (#114051)

Co-authored-by: Byron Hulcher <byronhulcher@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Deprecated - use backport:version if exact versions are needed Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants