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

[ES|QL] Bypass no data views screen #174316

Merged
merged 42 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8dec605
[No Data Prompt] ES|QL direct link
clintandrewhall Jan 5, 2024
b75c9ee
Convert handler to hook; simplify services; set appropriate index
clintandrewhall Jan 5, 2024
b590f50
Merge branch 'main' into shared_ux/prompt_esql
clintandrewhall Jan 9, 2024
e8204f0
Fix query logic
clintandrewhall Jan 9, 2024
8ff3b72
Address feedback
clintandrewhall Jan 9, 2024
2a9edec
Fix locator
stratoula Jan 11, 2024
d2d4930
Merge branch 'main' into shared_ux/prompt_esql
rshen91 Jan 16, 2024
43223f3
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 16, 2024
8728346
Merge branch 'main' into shared_ux/prompt_esql
rshen91 Jan 22, 2024
7a41b25
attempt to fix
rshen91 Jan 22, 2024
8275681
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 22, 2024
7d6b599
Merge branch 'main' of github.com:elastic/kibana into shared_ux/promp…
Dosant Jan 30, 2024
a84242c
change link styling
Dosant Jan 30, 2024
3afb946
fix navigation when in Discover
Dosant Jan 31, 2024
7615e8b
esql -> ESQL
Dosant Jan 31, 2024
3c0f90c
allow creating esql panels without default data view
Dosant Jan 31, 2024
581e5ba
allow to launch dashboard without a default data view
Dosant Jan 31, 2024
8f60f8b
fix button size
Dosant Jan 31, 2024
fe0cfc0
adjust dashboard no date state to allow for incoming es|ql chart with…
Dosant Jan 31, 2024
ea7af9f
Merge branch 'main' of github.com:elastic/kibana into shared_ux/promp…
Dosant Jan 31, 2024
214ea43
clean up
Dosant Jan 31, 2024
4274c32
wip fix deps
Dosant Jan 31, 2024
af8be65
fixes
Dosant Jan 31, 2024
648c2db
Merge branch 'main' of github.com:elastic/kibana into shared_ux/promp…
Dosant Jan 31, 2024
a0c3b5f
fix
Dosant Jan 31, 2024
66e9531
move finding first index for esql to utils
Dosant Jan 31, 2024
4080e2a
fix
Dosant Feb 1, 2024
f2a649c
Merge branch 'main' of github.com:elastic/kibana into shared_ux/promp…
Dosant Feb 1, 2024
a5e8010
fix
Dosant Feb 1, 2024
c2ab32a
Merge branch 'main' into shared_ux/prompt_esql
stratoula Feb 2, 2024
2a52aea
Merge branch 'main' of github.com:elastic/kibana into shared_ux/promp…
Dosant Feb 2, 2024
af27b8e
fix merge
Dosant Feb 2, 2024
ef4d45f
don’t show “try es|ql” on data view managament page
Dosant Feb 2, 2024
379bc71
Merge branch 'shared_ux/prompt_esql' of github.com:clintandrewhall/ki…
Dosant Feb 2, 2024
57c363b
don’t show “try es|ql” on data view managament page
Dosant Feb 2, 2024
45117b8
Merge branch 'main' of github.com:elastic/kibana into shared_ux/promp…
Dosant Feb 2, 2024
672e8c9
remove unwanted change
Dosant Feb 2, 2024
790c3c4
add ftr
Dosant Feb 2, 2024
5dd1f76
Merge branch 'main' of github.com:elastic/kibana into shared_ux/promp…
Dosant Feb 5, 2024
641acdc
add esql doc link
Dosant Feb 5, 2024
757d820
fix link
Dosant Feb 5, 2024
60df991
fix dashboard esql link
Dosant Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/deeplinks/analytics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export const DISCOVER_APP_ID = 'discover';
export const DASHBOARD_APP_ID = 'dashboards';

export const VISUALIZE_APP_ID = 'visualize';

export const DISCOVER_ESQL_LOCATOR = 'DISCOVER_ESQL_LOCATOR';
9 changes: 8 additions & 1 deletion packages/deeplinks/analytics/deep_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
* Side Public License, v 1.
*/

import { DASHBOARD_APP_ID, DISCOVER_APP_ID, VISUALIZE_APP_ID } from './constants';
import {
DASHBOARD_APP_ID,
DISCOVER_APP_ID,
DISCOVER_ESQL_LOCATOR,
VISUALIZE_APP_ID,
} from './constants';

export type AppId = typeof DISCOVER_APP_ID | typeof DASHBOARD_APP_ID | typeof VISUALIZE_APP_ID;

export type DeepLinkId = AppId;

export type LocatorId = typeof DISCOVER_ESQL_LOCATOR;
7 changes: 6 additions & 1 deletion packages/deeplinks/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
* Side Public License, v 1.
*/

export { DASHBOARD_APP_ID, DISCOVER_APP_ID, VISUALIZE_APP_ID } from './constants';
export {
DASHBOARD_APP_ID,
DISCOVER_APP_ID,
VISUALIZE_APP_ID,
DISCOVER_ESQL_LOCATOR,
} from './constants';

export type { AppId, DeepLinkId } from './deep_links';
1 change: 1 addition & 0 deletions packages/kbn-es-query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export {
migrateFilter,
fromCombinedFilter,
isOfQueryType,
isOfEsqlQueryType,
isOfAggregateQueryType,
getAggregateQueryMode,
getIndexPatternFromSQLQuery,
Expand Down
9 changes: 9 additions & 0 deletions packages/kbn-es-query/src/es_query/es_aggregate_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export function isOfAggregateQueryType(
return Boolean(query && ('sql' in query || 'esql' in query));
}

/**
* True if the query is of type AggregateQuery and is of type esql, false otherwise.
*/
export function isOfEsqlQueryType(
query?: AggregateQuery | Query | { [key: string]: any }
): query is AggregateQuery {
return Boolean(query && 'esql' in query && !('sql' in query));
}

// returns the language of the aggregate Query, sql, esql etc
export function getAggregateQueryMode(query: AggregateQuery): Language {
return Object.keys(query)[0] as Language;
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es-query/src/es_query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { decorateQuery } from './decorate_query';
export {
isOfQueryType,
isOfAggregateQueryType,
isOfEsqlQueryType,
getAggregateQueryMode,
getIndexPatternFromSQLQuery,
getLanguageDisplayName,
Expand Down
10 changes: 8 additions & 2 deletions packages/shared-ux/page/kibana_no_data/mocks/src/storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
NoDataCardStorybookParams,
} from '@kbn/shared-ux-card-no-data-mocks';

type PropArguments = Pick<NoDataPageProps, 'solution' | 'logo'>;
type PropArguments = Pick<NoDataPageProps, 'solution' | 'logo' | 'esqlLink'>;
type ServiceArguments = Pick<KibanaNoDataPageServices, 'hasUserDataView' | 'hasESData'>;

export type Params = ArgumentParams<PropArguments, ServiceArguments> &
Expand All @@ -51,6 +51,10 @@ export class StorybookMock extends AbstractStorybookMock<
options: ['logoElastic', 'logoKibana', 'logoCloud', undefined],
defaultValue: undefined,
},
esqlLink: {
control: 'text',
defaultValue: 'elastic.co',
},
};

serviceArguments = {
Expand All @@ -67,7 +71,7 @@ export class StorybookMock extends AbstractStorybookMock<
dependencies = [noDataViewsMock, noDataCardMock];

getProps(params: Params) {
const { logo, solution } = params;
const { logo, solution, esqlLink } = params;
const noDataConfig = {
solution: solution || 'Analytics',
logo: logo || 'logoKibana',
Expand All @@ -77,12 +81,14 @@ export class StorybookMock extends AbstractStorybookMock<
},
},
docsLink: 'http://docs.elastic.dev',
esqlLink: esqlLink || 'http://elastic.co',
};

return {
showPlainSpinner: false,
noDataConfig,
onDataViewCreated: action('onDataViewCreated'),
esqlLink,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/shared-ux/prompt/no_data_views/impl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { NoDataViewsPrompt } from './src/no_data_views';
export { NoDataViewsPrompt as NoDataViewsPromptComponent } from './src/no_data_views.component';
export { NoDataViewsPromptKibanaProvider, NoDataViewsPromptProvider } from './src/services';
export { DataViewIllustration } from './src/data_view_illustration';
export { useOnTryEsql } from './src/hooks';
78 changes: 78 additions & 0 deletions packages/shared-ux/prompt/no_data_views/impl/src/actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { EuiButton, EuiLink, EuiSpacer, EuiText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';

interface NoDataButtonProps {
onClickCreate: (() => void) | undefined;
canCreateNewDataView: boolean;
onTryEsql?: () => void;
}

const createDataViewText = i18n.translate('sharedUXPackages.noDataViewsPrompt.addDataViewText', {
defaultMessage: 'Create data view',
});

export const NoDataButtonLink = ({
onClickCreate,
canCreateNewDataView,
onTryEsql,
}: NoDataButtonProps) => {
if (!onTryEsql && !canCreateNewDataView) {
return null;
}

let tryEsqlPrompt = null;
let createDataViewButton = null;
let orDivider = null;

if (onTryEsql) {
tryEsqlPrompt = (
<EuiText size="s">
<FormattedMessage
id="sharedUXPackages.no_data_views.button"
defaultMessage="Query your data directly with ES|QL (Beta). "
/>
<EuiLink onClick={onTryEsql}>Try ES|QL</EuiLink>
</EuiText>
);
}

if (canCreateNewDataView) {
createDataViewButton = (
<EuiButton
onClick={onClickCreate}
iconType="plusInCircle"
fill={true}
data-test-subj="createDataViewButton"
>
{createDataViewText}
</EuiButton>
);
}

if (canCreateNewDataView && onTryEsql) {
orDivider = (
<>
<EuiSpacer size="m" />- OR -
<EuiSpacer size="m" />
</>
);
}

return (
<>
{createDataViewButton}
{orDivider}
{tryEsqlPrompt}
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { useOnTryEsql, type UseOnTryEsqlParams } from './use_on_try_esql';
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { useEffect, useState } from 'react';
import { DISCOVER_ESQL_LOCATOR } from '@kbn/deeplinks-analytics';
import { DiscoverEsqlLocatorParams } from '@kbn/discover-plugin/common';

import { NavigateToAppFn, LocatorClient } from '@kbn/shared-ux-prompt-no-data-views-types';

export interface UseOnTryEsqlParams {
locatorClient?: LocatorClient;
navigateToApp: NavigateToAppFn;
}

export const useOnTryEsql = ({ locatorClient, navigateToApp }: UseOnTryEsqlParams) => {
const [onTryEsql, setOnTryEsql] = useState<(() => void) | undefined>();

useEffect(() => {
(async () => {
const location = await locatorClient
?.get<DiscoverEsqlLocatorParams>(DISCOVER_ESQL_LOCATOR)
?.getLocation({});

if (!location) {
return;
}

const { app, path, state } = location;

setOnTryEsql(() => () => navigateToApp(app, { path, state }));
})();
}, [locatorClient, navigateToApp]);

return onTryEsql;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
import React from 'react';
import { css } from '@emotion/react';

import { EuiButton, EuiEmptyPrompt, EuiPanel } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { EuiEmptyPrompt, EuiPanel } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { withSuspense } from '@kbn/shared-ux-utility';
import { NoDataViewsPromptComponentProps } from '@kbn/shared-ux-prompt-no-data-views-types';

import { DocumentationLink } from './documentation_link';

const createDataViewText = i18n.translate('sharedUXPackages.noDataViewsPrompt.addDataViewText', {
defaultMessage: 'Create data view',
});
import { NoDataButtonLink } from './actions';

// Using raw value because it is content dependent
const MAX_WIDTH = 830;
Expand All @@ -31,19 +27,9 @@ export const NoDataViewsPrompt = ({
onClickCreate,
canCreateNewDataView,
dataViewsDocLink,
onTryEsql,
emptyPromptColor = 'plain',
}: NoDataViewsPromptComponentProps) => {
const actions = canCreateNewDataView && (
<EuiButton
onClick={onClickCreate}
iconType="plusInCircle"
fill={true}
data-test-subj="createDataViewButton"
>
{createDataViewText}
</EuiButton>
);

const title = canCreateNewDataView ? (
<h2>
<FormattedMessage
Expand Down Expand Up @@ -94,6 +80,7 @@ export const NoDataViewsPrompt = ({
);

const icon = <Illustration />;
const actions = <NoDataButtonLink {...{ onClickCreate, canCreateNewDataView, onTryEsql }} />;

return (
<EuiEmptyPrompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const NoDataViewsPrompt = ({
onDataViewCreated,
allowAdHocDataView = false,
}: NoDataViewsPromptProps) => {
const { canCreateNewDataView, openDataViewEditor, dataViewsDocLink } = useServices();
const { canCreateNewDataView, openDataViewEditor, dataViewsDocLink, onTryEsql } = useServices();
const closeDataViewEditor = useRef<CloseDataViewEditorFn>();

useEffect(() => {
Expand Down Expand Up @@ -72,6 +72,8 @@ export const NoDataViewsPrompt = ({
]);

return (
<NoDataViewsPromptComponent {...{ onClickCreate, canCreateNewDataView, dataViewsDocLink }} />
<NoDataViewsPromptComponent
{...{ onClickCreate, canCreateNewDataView, dataViewsDocLink, onTryEsql }}
/>
);
};
20 changes: 18 additions & 2 deletions packages/shared-ux/prompt/no_data_views/impl/src/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
*/

import React, { FC, useContext } from 'react';

import type {
NoDataViewsPromptServices,
NoDataViewsPromptKibanaDependencies,
} from '@kbn/shared-ux-prompt-no-data-views-types';
import { useOnTryEsql } from './hooks';

const NoDataViewsPromptContext = React.createContext<NoDataViewsPromptServices | null>(null);

Expand All @@ -23,11 +25,16 @@ export const NoDataViewsPromptProvider: FC<NoDataViewsPromptServices> = ({
}) => {
// Typescript types are widened to accept more than what is needed. Take only what is necessary
// so the context remains clean.
const { canCreateNewDataView, dataViewsDocLink, openDataViewEditor } = services;
const { canCreateNewDataView, dataViewsDocLink, openDataViewEditor, onTryEsql } = services;

return (
<NoDataViewsPromptContext.Provider
value={{ canCreateNewDataView, dataViewsDocLink, openDataViewEditor }}
value={{
canCreateNewDataView,
dataViewsDocLink,
openDataViewEditor,
onTryEsql,
}}
>
{children}
</NoDataViewsPromptContext.Provider>
Expand All @@ -41,12 +48,21 @@ export const NoDataViewsPromptKibanaProvider: FC<NoDataViewsPromptKibanaDependen
children,
...services
}) => {
const {
share,
coreStart: {
application: { navigateToApp },
},
} = services;
const onTryEsql = useOnTryEsql({ locatorClient: share?.url.locators, navigateToApp });

return (
<NoDataViewsPromptContext.Provider
value={{
dataViewsDocLink: services.coreStart.docLinks.links.indexPatterns?.introduction,
canCreateNewDataView: services.dataViewEditor.userPermissions.editDataView(),
openDataViewEditor: services.dataViewEditor.openEditor,
onTryEsql,
}}
>
{children}
Expand Down
2 changes: 2 additions & 0 deletions packages/shared-ux/prompt/no_data_views/impl/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"@kbn/test-jest-helpers",
"@kbn/shared-ux-prompt-no-data-views-types",
"@kbn/shared-ux-prompt-no-data-views-mocks",
"@kbn/deeplinks-analytics",
"@kbn/discover-plugin",
],
"exclude": [
"target/**/*",
Expand Down
Loading