[No Data] Allow access to the app if there are user created data views (#134068) (#134264)

* [No Data] Allow access to the app if there are user created data views

* Update the checks

* Merge main

* Simplify boolean logic

* Fix Discover test

* Move call to top in Discover

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 247876ad92)

# Conflicts:
#	src/plugins/discover/public/application/main/discover_main_route.tsx
This commit is contained in:
Maja Grubic 2022-06-13 21:54:10 +02:00 committed by GitHub
parent d131787716
commit 9ed61a17ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 20 deletions

View file

@ -48,10 +48,6 @@ export const KibanaNoDataPage = ({ onDataViewCreated, noDataConfig }: Props) =>
return <EuiLoadingElastic css={{ margin: 'auto' }} size="xxl" />;
}
if (!dataExists) {
return <NoDataConfigPage noDataConfig={noDataConfig} />;
}
/*
TODO: clintandrewhall - the use and population of `NoDataViewPromptProvider` here is temporary,
until `KibanaNoDataPage` is moved to a package of its own.
@ -60,7 +56,7 @@ export const KibanaNoDataPage = ({ onDataViewCreated, noDataConfig }: Props) =>
with `KibanaNoDataPageProvider`, creating a single Provider that manages contextual dependencies
throughout the React tree from the top-level of composition and consumption.
*/
if (!hasUserDataViews) {
if (!hasUserDataViews && dataExists) {
const services: NoDataViewsPromptServices = {
canCreateNewDataView,
dataViewsDocLink,
@ -74,5 +70,9 @@ export const KibanaNoDataPage = ({ onDataViewCreated, noDataConfig }: Props) =>
);
}
if (!dataExists) {
return <NoDataConfigPage noDataConfig={noDataConfig} />;
}
return null;
};

View file

@ -42,6 +42,5 @@ export const isDashboardAppInNoDataState = async (
dataViews: DataPublicPluginStart['dataViews']
) => {
const hasUserDataView = await dataViews.hasData.hasUserDataView().catch(() => false);
const hasEsData = await dataViews.hasData.hasESData().catch(() => true);
return !hasUserDataView || !hasEsData;
return !hasUserDataView;
};

View file

@ -69,12 +69,15 @@ export function DiscoverMainRoute() {
const loadDefaultOrCurrentIndexPattern = useCallback(
async (searchSource: ISearchSource) => {
try {
const hasUserDataView = await data.dataViews.hasData.hasUserDataView().catch(() => false);
const hasEsData = await data.dataViews.hasData.hasESData().catch(() => false);
if (!hasUserDataView || !hasEsData) {
const hasUserDataViewValue = await data.dataViews.hasData
.hasUserDataView()
.catch(() => false);
if (!hasUserDataViewValue) {
setShowNoDataPage(true);
return;
}
const defaultDataView = await data.dataViews.getDefaultDataView();
if (!defaultDataView) {
setShowNoDataPage(true);

View file

@ -90,15 +90,17 @@ export const VisualizeApp = ({ onAppLeave }: VisualizeAppProps) => {
const checkESOrDataViewExist = async () => {
// check if there is any data view or data source
const hasUserDataView = await dataViews.hasData.hasUserDataView().catch(() => false);
const hasEsData = await dataViews.hasData.hasESData().catch(() => false);
if (!hasUserDataView || !hasEsData) {
setShowNoDataPage(true);
}
// Adding this check as TSVB asks for the default dataview on initialization
const defaultDataView = await dataViews.getDefaultDataView();
if (!defaultDataView) {
setShowNoDataPage(true);
if (hasUserDataView) {
// Adding this check as TSVB asks for the default dataview on initialization
const defaultDataView = await dataViews.getDefaultDataView();
if (!defaultDataView) {
setShowNoDataPage(true);
}
setIsLoading(false);
return;
}
setShowNoDataPage(true);
setIsLoading(false);
};

View file

@ -243,8 +243,7 @@ export async function mountApp(
useEffect(() => {
(async () => {
const hasUserDataView = await data.dataViews.hasData.hasUserDataView().catch(() => false);
const hasEsData = await data.dataViews.hasData.hasESData().catch(() => true);
if (!hasUserDataView || !hasEsData) {
if (!hasUserDataView) {
setEditorState('no_data');
return;
}