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

[SharedUX] Allow creation of adHoc data views from no data page #144596

Merged
merged 5 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,21 @@ describe('AnalyticsNoDataPageComponent', () => {
expect(noDataConfig.docsLink).toEqual('http://www.test.com');
expect(noDataConfig.action.elasticAgent).not.toBeNull();
});

it('allows ad-hoc data view creation', async () => {
const component = mountWithIntl(
<AnalyticsNoDataPageProvider {...services}>
<AnalyticsNoDataPage
onDataViewCreated={onDataViewCreated}
kibanaGuideDocLink={'http://www.test.com'}
allowAdHocDataView={true}
/>
</AnalyticsNoDataPageProvider>
);

await act(() => new Promise(setImmediate));

expect(component.find(KibanaNoDataPage).length).toBe(1);
expect(component.find(KibanaNoDataPage).props().allowAdHocDataView).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface Props {
kibanaGuideDocLink: string;
/** Handler for successfully creating a new data view. */
onDataViewCreated: (dataView: unknown) => void;
/** if set to true allows creation of an ad-hoc dataview from data view editor */
allowAdHocDataView?: boolean;
}

const solution = i18n.translate('sharedUXPackages.noDataConfig.analytics', {
Expand All @@ -41,7 +43,11 @@ const addIntegrationsDescription = i18n.translate(
/**
* A pure component of an entire page that can be displayed when Kibana "has no data", specifically for Analytics.
*/
export const AnalyticsNoDataPage = ({ kibanaGuideDocLink, onDataViewCreated }: Props) => {
export const AnalyticsNoDataPage = ({
kibanaGuideDocLink,
onDataViewCreated,
allowAdHocDataView,
}: Props) => {
const noDataConfig = {
solution,
pageTitle,
Expand All @@ -55,6 +61,5 @@ export const AnalyticsNoDataPage = ({ kibanaGuideDocLink, onDataViewCreated }: P
},
docsLink: kibanaGuideDocLink,
};

return <KibanaNoDataPage {...{ noDataConfig, onDataViewCreated }} />;
return <KibanaNoDataPage {...{ noDataConfig, onDataViewCreated, allowAdHocDataView }} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('AnalyticsNoDataPage', () => {
it('renders correctly', async () => {
const component = mountWithIntl(
<AnalyticsNoDataPageProvider {...services}>
<AnalyticsNoDataPage onDataViewCreated={onDataViewCreated} />
<AnalyticsNoDataPage onDataViewCreated={onDataViewCreated} allowAdHocDataView={true} />
</AnalyticsNoDataPageProvider>
);

Expand All @@ -36,5 +36,6 @@ describe('AnalyticsNoDataPage', () => {
expect(component.find(Component).length).toBe(1);
expect(component.find(Component).props().kibanaGuideDocLink).toBe(services.kibanaGuideDocLink);
expect(component.find(Component).props().onDataViewCreated).toBe(onDataViewCreated);
expect(component.find(Component).props().allowAdHocDataView).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ import { AnalyticsNoDataPage as Component } from './analytics_no_data_page.compo
* An entire page that can be displayed when Kibana "has no data", specifically for Analytics. Uses
* services from a Provider to supply props to a pure component.
*/
export const AnalyticsNoDataPage = ({ onDataViewCreated }: AnalyticsNoDataPageProps) => {
export const AnalyticsNoDataPage = ({
onDataViewCreated,
allowAdHocDataView,
}: AnalyticsNoDataPageProps) => {
const services = useServices();
const { kibanaGuideDocLink } = services;

return (
<Component
{...{
onDataViewCreated,
allowAdHocDataView,
kibanaGuideDocLink,
}}
/>
Expand Down
2 changes: 2 additions & 0 deletions packages/shared-ux/page/analytics_no_data/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ export type AnalyticsNoDataPageKibanaDependencies = KibanaDependencies &
export interface AnalyticsNoDataPageProps {
/** Handler for successfully creating a new data view. */
onDataViewCreated: (dataView: unknown) => void;
/** if set to true allows creation of an ad-hoc data view from data view editor */
allowAdHocDataView?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { useServices } from './services';
/**
* A page to display when Kibana has no data, prompting a person to add integrations or create a new data view.
*/
export const KibanaNoDataPage = ({ onDataViewCreated, noDataConfig }: KibanaNoDataPageProps) => {
export const KibanaNoDataPage = ({
onDataViewCreated,
noDataConfig,
allowAdHocDataView,
}: KibanaNoDataPageProps) => {
// These hooks are temporary, until this component is moved to a package.
const services = useServices();
const { hasESData, hasUserDataView } = services;
Expand All @@ -43,7 +47,12 @@ export const KibanaNoDataPage = ({ onDataViewCreated, noDataConfig }: KibanaNoDa
}

if (!hasUserDataViews && dataExists) {
return <NoDataViewsPrompt onDataViewCreated={onDataViewCreated} />;
return (
<NoDataViewsPrompt
onDataViewCreated={onDataViewCreated}
allowAdHocDataView={allowAdHocDataView}
/>
);
}

if (!dataExists) {
Expand Down
4 changes: 4 additions & 0 deletions packages/shared-ux/page/kibana_no_data/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface Services {
hasESData: () => Promise<boolean>;
/** True if Kibana instance contains user-created data view, false otherwise. */
hasUserDataView: () => Promise<boolean>;
/** if set to true allows creation of an ad-hoc data view from data view editor */
allowAdHocDataView?: boolean;
}

/**
Expand Down Expand Up @@ -53,4 +55,6 @@ export interface KibanaNoDataPageProps {
onDataViewCreated: (dataView: unknown) => void;
/** `NoDataPage` configuration; see `NoDataPageProps`. */
noDataConfig: NoDataPageProps;
/** if set to true allows creation of an ad-hoc dataview from data view editor */
allowAdHocDataView?: boolean;
}
14 changes: 12 additions & 2 deletions packages/shared-ux/prompt/no_data_views/impl/src/no_data_views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ type CloseDataViewEditorFn = ReturnType<NoDataViewsPromptServices['openDataViewE
*
* Use of this component requires both the `EuiTheme` context as well as a `NoDataViewsPrompt` provider.
*/
export const NoDataViewsPrompt = ({ onDataViewCreated }: NoDataViewsPromptProps) => {
export const NoDataViewsPrompt = ({
onDataViewCreated,
allowAdHocDataView = false,
}: NoDataViewsPromptProps) => {
const { canCreateNewDataView, openDataViewEditor, dataViewsDocLink } = useServices();
const closeDataViewEditor = useRef<CloseDataViewEditorFn>();

Expand Down Expand Up @@ -54,12 +57,19 @@ export const NoDataViewsPrompt = ({ onDataViewCreated }: NoDataViewsPromptProps)
onSave: (dataView) => {
onDataViewCreated(dataView);
},
allowAdHocDataView,
});

if (setDataViewEditorRef) {
setDataViewEditorRef(ref);
}
}, [canCreateNewDataView, openDataViewEditor, setDataViewEditorRef, onDataViewCreated]);
}, [
canCreateNewDataView,
openDataViewEditor,
allowAdHocDataView,
setDataViewEditorRef,
onDataViewCreated,
]);

return (
<NoDataViewsPromptComponent {...{ onClickCreate, canCreateNewDataView, dataViewsDocLink }} />
Expand Down
4 changes: 4 additions & 0 deletions packages/shared-ux/prompt/no_data_views/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type DataView = unknown;
interface DataViewEditorOptions {
/** Handler to be invoked when the Data View Editor completes a save operation. */
onSave: (dataView: DataView) => void;
/** if set to true allows creation of an ad-hoc data view from data view editor */
allowAdHocDataView?: boolean;
}

/**
Expand Down Expand Up @@ -75,4 +77,6 @@ export interface NoDataViewsPromptComponentProps {
export interface NoDataViewsPromptProps {
/** Handler for successfully creating a new data view. */
onDataViewCreated: (dataView: unknown) => void;
/** if set to true allows creation of an ad-hoc data view from data view editor */
allowAdHocDataView?: boolean;
}