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

[Discover] Make use of stateContainer action onDataViewEdited #199588

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

kertal
Copy link
Member

@kertal kertal commented Nov 11, 2024

Summary

When working on #199419, I noticed that we don't make use of the stateContainer onDataViewEdited function, but use duplicate code in discover_topnav.tsx

This PR applies this change, deduplicating our code in this area, containing more smallish cleanups in the edited file.

Testing

This is just a code cleanup and it should be covered pretty well by functional testing. Now even the unit test coverage increased. win-win. But if there's interest which part of Discover this code is being used: When users edit a DataView in a flyout, it's triggered when they finish and save:

CleanShot 2024-11-11 at 10 08 57

@kertal
Copy link
Member Author

kertal commented Nov 11, 2024

/ci

@@ -93,7 +85,7 @@ export const DiscoverTopNav = ({
const editField = useMemo(
() =>
canEditDataView
? async (fieldName?: string, uiAction: 'edit' | 'add' = 'edit') => {
Copy link
Member Author

Choose a reason for hiding this comment

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

just a little cleanup since the second param is not in use

Comment on lines -126 to -141
const onEditDataView = useCallback(
async (editedDataView: DataView) => {
if (editedDataView.isPersisted()) {
// Clear the current data view from the cache and create a new instance
// of it, ensuring we have a new object reference to trigger a re-render
dataViews.clearInstanceCache(editedDataView.id);
stateContainer.actions.setDataView(await dataViews.create(editedDataView.toSpec(), true));
} else {
await stateContainer.actions.updateAdHocDataViewId();
}
stateContainer.actions.loadDataViewList();
addLog('[DiscoverTopNav] onEditDataView triggers data fetching');
stateContainer.dataState.fetch();
},
[dataViews, stateContainer.actions, stateContainer.dataState]
);
Copy link
Member Author

@kertal kertal Nov 11, 2024

Choose a reason for hiding this comment

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

Removed for code-deduplication, because this function is provided by our state container, but it seems it never has been used. so we're switching to make use of this part of the code:

const onDataViewEdited = async (editedDataView: DataView) => {

This has another advantage, there's unit test code coverage for the state container function

@kertal kertal self-assigned this Nov 11, 2024
@kertal kertal added Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. backport:skip This commit does not require backporting backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes and removed backport:skip This commit does not require backporting labels Nov 11, 2024
@kertal kertal marked this pull request as ready for review November 11, 2024 09:11
@kertal kertal requested a review from a team as a code owner November 11, 2024 09:11
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@kertal kertal enabled auto-merge (squash) November 11, 2024 11:15
@kertal kertal merged commit 8136bcc into elastic:main Nov 11, 2024
24 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11779046085

@elasticmachine
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
discover 805.3KB 805.0KB -332.0B

History

cc @kertal

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 11, 2024
…c#199588)

Duplicating code that's triggered when a dataview is being edited

(cherry picked from commit 8136bcc)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@kertal kertal deleted the discover-remove-code-duplication branch November 11, 2024 13:16
kibanamachine added a commit that referenced this pull request Nov 11, 2024
…199588) (#199641)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Discover] Make use of stateContainer action onDataViewEdited
(#199588)](#199588)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Matthias
Wilhelm","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-11T13:00:08Z","message":"[Discover]
Make use of stateContainer action onDataViewEdited
(#199588)\n\nDuplicating code that's triggered when a dataview is being
edited","sha":"8136bcc0e43a682dfa4484f112a287210936f817","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:skip","v9.0.0","Team:DataDiscovery","backport:prev-minor"],"title":"[Discover]
Make use of stateContainer action
onDataViewEdited","number":199588,"url":"https://github.com/elastic/kibana/pull/199588","mergeCommit":{"message":"[Discover]
Make use of stateContainer action onDataViewEdited
(#199588)\n\nDuplicating code that's triggered when a dataview is being
edited","sha":"8136bcc0e43a682dfa4484f112a287210936f817"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199588","number":199588,"mergeCommit":{"message":"[Discover]
Make use of stateContainer action onDataViewEdited
(#199588)\n\nDuplicating code that's triggered when a dataview is being
edited","sha":"8136bcc0e43a682dfa4484f112a287210936f817"}}]}]
BACKPORT-->

Co-authored-by: Matthias Wilhelm <[email protected]>
tkajtoch pushed a commit to tkajtoch/kibana that referenced this pull request Nov 12, 2024
…c#199588)

Duplicating code that's triggered when a dataview is being edited
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Nov 18, 2024
…c#199588)

Duplicating code that's triggered when a dataview is being edited
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants