-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -8,8 +8,8 @@ | |||
*/ | ||||
|
||||
import React, { useCallback, useEffect, useMemo, useRef } from 'react'; | ||||
import { type DataView, DataViewType } from '@kbn/data-views-plugin/public'; | ||||
import { DataViewPickerProps } from '@kbn/unified-search-plugin/public'; | ||||
import { DataViewType } from '@kbn/data-views-plugin/public'; | ||||
import type { DataViewPickerProps } from '@kbn/unified-search-plugin/public'; | ||||
import { ENABLE_ESQL } from '@kbn/esql-utils'; | ||||
import { TextBasedLanguages } from '@kbn/esql-utils'; | ||||
import { DiscoverFlyouts, dismissAllFlyoutsExceptFor } from '@kbn/discover-utils'; | ||||
|
@@ -20,7 +20,6 @@ import { useDiscoverServices } from '../../../../hooks/use_discover_services'; | |||
import type { DiscoverStateContainer } from '../../state_management/discover_state'; | ||||
import { onSaveSearch } from './on_save_search'; | ||||
import { useDiscoverCustomization } from '../../../../customizations'; | ||||
import { addLog } from '../../../../utils/add_log'; | ||||
import { useAppStateSelector } from '../../state_management/discover_app_state_container'; | ||||
import { useDiscoverTopNav } from './use_discover_topnav'; | ||||
import { useIsEsqlMode } from '../../hooks/use_is_esql_mode'; | ||||
|
@@ -47,15 +46,8 @@ export const DiscoverTopNav = ({ | |||
onCancelClick, | ||||
}: DiscoverTopNavProps) => { | ||||
const services = useDiscoverServices(); | ||||
const { | ||||
dataViewEditor, | ||||
navigation, | ||||
dataViewFieldEditor, | ||||
data, | ||||
uiSettings, | ||||
dataViews, | ||||
setHeaderActionMenu, | ||||
} = services; | ||||
const { dataViewEditor, navigation, dataViewFieldEditor, data, uiSettings, setHeaderActionMenu } = | ||||
services; | ||||
const query = useAppStateSelector((state) => state.query); | ||||
const adHocDataViews = useInternalStateSelector((state) => state.adHocDataViews); | ||||
const dataView = useInternalStateSelector((state) => state.dataView!); | ||||
|
@@ -93,7 +85,7 @@ export const DiscoverTopNav = ({ | |||
const editField = useMemo( | ||||
() => | ||||
canEditDataView | ||||
? async (fieldName?: string, uiAction: 'edit' | 'add' = 'edit') => { | ||||
? async (fieldName?: string) => { | ||||
if (dataView?.id) { | ||||
const dataViewInstance = await data.dataViews.get(dataView.id); | ||||
closeFieldEditor.current = await dataViewFieldEditor.openEditor({ | ||||
|
@@ -112,7 +104,7 @@ export const DiscoverTopNav = ({ | |||
); | ||||
|
||||
const addField = useMemo( | ||||
() => (canEditDataView && editField ? () => editField(undefined, 'add') : undefined), | ||||
() => (canEditDataView && editField ? () => editField() : undefined), | ||||
[editField, canEditDataView] | ||||
); | ||||
|
||||
|
@@ -123,23 +115,6 @@ export const DiscoverTopNav = ({ | |||
}); | ||||
}, [dataViewEditor, stateContainer]); | ||||
|
||||
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] | ||||
); | ||||
Comment on lines
-126
to
-141
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
This has another advantage, there's unit test code coverage for the state container function |
||||
|
||||
const updateSavedQueryId = (newSavedQueryId: string | undefined) => { | ||||
const { appState } = stateContainer; | ||||
if (newSavedQueryId) { | ||||
|
@@ -223,14 +198,13 @@ export const DiscoverTopNav = ({ | |||
textBasedLanguages: supportedTextBasedLanguages, | ||||
adHocDataViews, | ||||
savedDataViews, | ||||
onEditDataView, | ||||
onEditDataView: stateContainer.actions.onDataViewEdited, | ||||
}; | ||||
}, [ | ||||
adHocDataViews, | ||||
addField, | ||||
createNewDataView, | ||||
dataView, | ||||
onEditDataView, | ||||
savedDataViews, | ||||
stateContainer, | ||||
uiSettings, | ||||
|
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