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

[App Search] Remaining Result Settings logic and routes #94947

Merged
merged 9 commits into from
Mar 22, 2021

Conversation

JasonStoltz
Copy link
Member

Summary

This PR migrates the remaining logic and server routes for Result Settings.

This PR is probably best reviewed commit by commit. Server routes are not added in a single commit, they are added along with the commit that adds a listener that requires them.

This logic is migrated as is from ent-search. I believe as discussed in the last PR there are opportunities for refactor. Please note them here, and if it's alright, I'd like to address them on a case by case basis as I see how the UI is actually using these methods. For example, I think we could remove redundant server and client fields state. We also may be able to convert these custom "confirmation" modals to regular widow.confirms, like we do elsewhere in the app. However, I'm not comfortable doing this until I can actually test this end to end with the UI in place.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@JasonStoltz JasonStoltz added release_note:skip Skip the PR/issue when compiling release notes v7.13.0 auto-backport Deprecated - use backport:version if exact versions are needed labels Mar 18, 2021
@JasonStoltz JasonStoltz requested a review from a team March 18, 2021 16:31
@JasonStoltz
Copy link
Member Author

@elasticmachine merge upstream

@@ -90,6 +114,15 @@ export const ResultSettingsLogic = kea<MakeLogicType<ResultSettingsValues, Resul
resetAllFields: () => true,
updateField: (fieldName, settings) => ({ fieldName, settings }),
saving: () => true,
clearRawSizeForField: (fieldName) => fieldName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Even when I'm only passing a single argument, I've been wrapping it like clearRawSizeForField: (fieldName) => ({fieldName}) because I like the consistency, and also when I realize I need to add another argument later. This is fine, just wanted to mention my approach.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's definitely the better approach. Kea recommends the same thing:

Actions are functions that take whatever arguments you choose and return a payload. This payload should always be an object: (amount) => ({ amount }).

Copy link
Member Author

Choose a reason for hiding this comment

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

I was just trying to migrate this, so I moved it over as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to make changes anyway, so I updated this: aa858df

Comment on lines +240 to +248
Object.entries(serverResultFields).reduce(
(acc: ServerFieldResultSettingObject, [fieldName, resultSetting]) => {
if (resultSetting.raw || resultSetting.snippet) {
acc[fieldName] = resultSetting;
}
return acc;
},
{}
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Functional programming is funny! Here's an alternative approach:

Object.entries(serverResultFields)
  .filter(([_, resultSetting]) => resultSetting.raw || resultSetting.snippet)
  .reduce((acc, [fieldName, resultSetting]) => {...acc, [fieldName]: resultSetting}, {})

I don't think you need to change it, they both accomplish the same thing and are about as readable, just wanted to flex a little 💪

actions.updateField(fieldName, omit(values.resultFields[fieldName], ['snippetSize']));
},
toggleRawForField: (fieldName: string) => {
// We cast this b/c it could be an empty object, which we can still treat as a FieldResultSetting safely
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a huge fan of stuff like "b/c" in comments because it can be confusing to non-native English speakers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines +121 to +126
export const areFieldsEmpty = (fields: FieldResultSettingObject) => {
const anyNonEmptyField = Object.values(fields).find((resultSettings) => {
return !isEmpty(resultSettings);
});
return !anyNonEmptyField;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

You could probably re-write this to use a for...in loop, which would allow you to short-circuit immediately if you founnd a non-empty field, but we're not talking about 1,000,000 fields here.

Copy link
Member Author

Choose a reason for hiding this comment

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

True. .find will return the first match it finds in an array so I believe it is equally efficient, fwiw.

@byronhulcher
Copy link
Contributor

Meant to include this w/ approval: I left some non-blocking thoughts in a few places, this looks fine to me to merge

@JasonStoltz JasonStoltz enabled auto-merge (squash) March 22, 2021 17:54
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

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.9MB 1.9MB +3.9KB

History

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

@kibanamachine
Copy link
Contributor

💚 Backport successful

7.x / #95105

This backport PR will be merged automatically after passing CI.

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 22, 2021
kibanamachine added a commit that referenced this pull request Mar 22, 2021
@JasonStoltz JasonStoltz deleted the result_settings_logic_2 branch April 6, 2021 13:04
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 release_note:skip Skip the PR/issue when compiling release notes v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants