-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
/ci |
@@ -93,7 +85,7 @@ export const DiscoverTopNav = ({ | |||
const editField = useMemo( | |||
() => | |||
canEditDataView | |||
? async (fieldName?: string, uiAction: 'edit' | 'add' = 'edit') => { |
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.
just a little cleanup since the second param is not in use
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] | ||
); |
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.
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:
kibana/src/plugins/discover/public/application/main/state_management/discover_state.ts
Line 415 in 2466a17
const onDataViewEdited = async (editedDataView: DataView) => { |
This has another advantage, there's unit test code coverage for the state container function
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/11779046085 |
💚 Build Succeeded
Metrics [docs]Async chunks
History
cc @kertal |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…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]>
…c#199588) Duplicating code that's triggered when a dataview is being edited
…c#199588) Duplicating code that's triggered when a dataview is being edited
Summary
When working on #199419, I noticed that we don't make use of the stateContainer
onDataViewEdited
function, but use duplicate code indiscover_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: