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] Enable data view editing from flyout #148283

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps)
}, [props.documents$, dispatchSidebarStateAction, selectedDataViewRef]);

useEffect(() => {
if (selectedDataView !== selectedDataViewRef.current) {
if (
selectedDataView &&
selectedDataViewRef.current &&
selectedDataView?.id !== selectedDataViewRef.current?.id
) {
dispatchSidebarStateAction({
type: DiscoverSidebarReducerActionType.DATA_VIEW_SWITCHED,
payload: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ export const DiscoverTopNav = ({
]
);

const onEditDataView = async (editedDataView: DataView) => {
const dataViewId = editedDataView.id!;
if (editedDataView.isPersisted()) {
// refetch data view to force react state update
// by creating new data view reference in the state
dataViews.clearInstanceCache(dataViewId);
stateContainer.actions.setDataView(await dataViews.get(dataViewId));
} else {
await updateAdHocDataViewId(editedDataView);
}
};

const updateSavedQueryId = (newSavedQueryId: string | undefined) => {
const { appState, setAppState } = stateContainer;
if (newSavedQueryId) {
Expand Down Expand Up @@ -220,6 +232,7 @@ export const DiscoverTopNav = ({
textBasedLanguages: supportedTextBasedLanguages as DataViewPickerProps['textBasedLanguages'],
adHocDataViews,
savedDataViews,
onEditDataView,
};

const onTextBasedSavedAndExit = useCallback(
Expand Down