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

[control group] apply selections on reset #189830

Merged
merged 16 commits into from
Aug 8, 2024

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Aug 2, 2024

Fixes #189580

PR awaits until all control filters are ready and then applies selections during reset.

@nreese
Copy link
Contributor Author

nreese commented Aug 2, 2024

/ci

@nreese
Copy link
Contributor Author

nreese commented Aug 2, 2024

/ci

@nreese
Copy link
Contributor Author

nreese commented Aug 5, 2024

@elasticmachine merge upstream

@nreese
Copy link
Contributor Author

nreese commented Aug 5, 2024

/ci

@nreese
Copy link
Contributor Author

nreese commented Aug 5, 2024

/ci

@@ -196,7 +196,6 @@ export const OptionsListPopoverSuggestions = ({
)}
emptyMessage={<OptionsListPopoverEmptyMessage showOnlySelected={showOnlySelected} />}
onChange={(newSuggestions, _, changedOption) => {
setSelectableOptions(newSuggestions);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed because its not needed. setSelectableOptions when useEffect runs because of observable changes made when makeSelection fires

@nreese nreese marked this pull request as ready for review August 5, 2024 19:54
@nreese nreese requested a review from a team as a code owner August 5, 2024 19:55
@nreese nreese added Feature:Input Control Input controls visualization release_note:skip Skip the PR/issue when compiling release notes project:embeddableRebuild v8.16.0 labels Aug 5, 2024
@Heenawter Heenawter self-requested a review August 7, 2024 14:43
@nreese
Copy link
Contributor Author

nreese commented Aug 7, 2024

@elasticmachine merge upstream

@botelastic botelastic bot added the Feature:Embedding Embedding content via iFrame label Aug 7, 2024
if (existsSelected) selections.setExistsSelected(false);
selections.setSelectedOptions(
selectedOptions ? [...selectedOptions, keyAsType] : [keyAsType]
);
Copy link
Contributor

Choose a reason for hiding this comment

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

As a cleanup, I wonder if we could move the makeSelection function into initializeOptionsListSelections? Not a blocker, though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with moving makeSelection into initializeOptionsListSelections is that in initializeOptionsListSelections the subjects are BehaviorSubject instead of PublishingSubjects. This makes it easy to slip up and call subject.next instead of the setter. Is it better to co-locate this code in initializeOptionsListSelections or have type protections?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that's a fair point - I'm fine leaving it where it is for now for type safety in that case 👍

Comment on lines 84 to 85
await Promise.all(filtersReadyPromises);
applySelections();
Copy link
Contributor

@Heenawter Heenawter Aug 7, 2024

Choose a reason for hiding this comment

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

We should probably only call applySelections if auto-apply is disabled - otherwise, we are publishing twice when it is enabled due to the unpublishedFilters$ subscription in the control group selections manager.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolve with f1a4c63

Copy link
Contributor Author

@nreese nreese Aug 7, 2024

Choose a reason for hiding this comment

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

I added an if statement around applySelections. applySelections will not publish filters if there are no changes. See the below implementation. So I am not sure if the if statement is needed. Let me know if I should take it out.

function applySelections() {
    if (!deepEqual(filters$.value, unpublishedFilters$.value)) {
      filters$.next(unpublishedFilters$.value);
    }
    if (!deepEqual(timeslice$.value, unpublishedTimeslice$.value)) {
      timeslice$.next(unpublishedTimeslice$.value);
    }
  }

Copy link
Contributor

@Heenawter Heenawter Aug 7, 2024

Choose a reason for hiding this comment

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

Ah, good point - I personally still think we should keep the applySelections in an if (there is more overhead to calling applySelections twice than there is to check the value of applySelections). But ultimately I'm fine either way, since the at least the filters$ subject won't emit twice 👍

@nreese nreese requested a review from Heenawter August 7, 2024 21:42
Copy link
Contributor

@Heenawter Heenawter left a comment

Choose a reason for hiding this comment

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

I think whatever is causing #190066 is also impacting controls here - which makes me thinks it might be related to #189128. To see this, add a new control and try to click save - unsaved changes gets stuck:

Screen.Recording.2024-08-07.at.4.03.33.PM.mov

This is not related to this work, so it is not a blocker - but it's definitely something we will want to resolve before the control group can be replaced 👍 Code review + tested locally and everything related to applying the selections on reset LGTM 🎉

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@nreese nreese merged commit b87e967 into elastic:main Aug 8, 2024
19 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Embedding Embedding content via iFrame Feature:Input Control Input controls visualization project:embeddableRebuild release_note:skip Skip the PR/issue when compiling release notes v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Embeddable Rebuild] [Controls] Apply selections on reset
5 participants