diff --git a/dashboards-reports/public/application.tsx b/dashboards-reports/public/application.tsx index 32563cb7..94aa0c65 100644 --- a/dashboards-reports/public/application.tsx +++ b/dashboards-reports/public/application.tsx @@ -31,16 +31,14 @@ import { AppPluginStartDependencies } from './types'; import { ReportsDashboardsApp } from './components/app'; export const renderApp = ( - { notifications, http, chrome }: CoreStart, - { navigation }: AppPluginStartDependencies, + { http, chrome, uiSettings }: CoreStart, { appBasePath, element }: AppMountParameters ) => { ReactDOM.render( , element diff --git a/dashboards-reports/public/components/app.tsx b/dashboards-reports/public/components/app.tsx index a82711ef..6bc12324 100644 --- a/dashboards-reports/public/components/app.tsx +++ b/dashboards-reports/public/components/app.tsx @@ -42,7 +42,6 @@ import { ChromeBreadcrumb, IUiSettingsClient, } from '../../../../src/core/public'; -import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public'; import { CreateReport } from './report_definitions/create/create_report_definition'; import { Main } from './main/main'; @@ -58,10 +57,9 @@ export interface CoreInterface { interface ReportsDashboardsAppDeps { basename: string; - notifications: CoreStart['notifications']; http: CoreStart['http']; - navigation: NavigationPublicPluginStart; chrome: CoreStart['chrome']; + uiSettings: IUiSettingsClient } const styles: CSS.Properties = { @@ -72,10 +70,9 @@ const styles: CSS.Properties = { export const ReportsDashboardsApp = ({ basename, - notifications, http, - navigation, chrome, + uiSettings }: ReportsDashboardsAppDeps) => { // Render the application DOM. return ( @@ -128,6 +125,7 @@ export const ReportsDashboardsApp = ({ diff --git a/dashboards-reports/public/components/report_definitions/create/create_report_definition.tsx b/dashboards-reports/public/components/report_definitions/create/create_report_definition.tsx index a8841cda..fd6f13bf 100644 --- a/dashboards-reports/public/components/report_definitions/create/create_report_definition.tsx +++ b/dashboards-reports/public/components/report_definitions/create/create_report_definition.tsx @@ -133,6 +133,7 @@ export function CreateReport(props) { const [toasts, setToasts] = useState([]); const [comingFromError, setComingFromError] = useState(false); const [preErrorData, setPreErrorData] = useState({}); + const {uiSettings} = props; const [ showSettingsReportNameError, @@ -322,6 +323,7 @@ export function CreateReport(props) { panel', () => { const { container } = render( panel', () => { const { container } = render( panel', () => { const { container } = render( panel', () => { const { container } = render( panel', () => { const { container } = render( panel', () => { const { container } = render( panel', () => { expect(container.firstChild).toMatchSnapshot(); await act(() => promise); }); - test('dashboard create from in-context', async () => { window = Object.create(window); @@ -403,6 +409,7 @@ describe(' panel', () => { const { container } = render( panel', () => { const { container } = render( panel', () => { const { container } = render( panel', () => { const component = shallow( panel', () => { const component = mount( panel', () => { act(() => { comboBox.props().onChange([{ value: 'test', label: 'test' }]); - }); + }); component.update(); await act(() => promise); @@ -674,6 +685,7 @@ describe(' panel', () => { const component = mount( panel', () => { const { container } = render( panel', () => { expect(container.firstChild).toMatchSnapshot(); await act(() => promise); }); + + test('load commonlyUsedRanges from uiSettings service', async () => { + const promise = Promise.resolve(); + uiSettingsMock.get = jest.fn((key) => [ + { + from: 'now/d', + to: 'now/d', + display: 'Foo' + } + ]); + + const component = mount( + + ); + await act(() => promise); + + const superDatePicker = component.find('EuiSuperDatePicker').at(0); + + expect(superDatePicker.prop('commonlyUsedRanges')).toEqual( + [ + { + start: 'now/d', + end: 'now/d', + label: 'Foo' + } + ] + ); + + expect(uiSettingsMock.get.mock.calls.length).toBeGreaterThan(0); + expect(uiSettingsMock.get.mock.calls[0][0]).toBe('timepicker:quickRanges'); + + await act(() => promise); + }); }); diff --git a/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx b/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx index 6fbd3c5d..f0bedb6e 100644 --- a/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx +++ b/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx @@ -81,6 +81,7 @@ type ReportSettingProps = { showSettingsReportSourceError: boolean; settingsReportSourceErrorMessage: string; showTimeRangeError: boolean; + uiSettings: any; }; export function ReportSettings(props: ReportSettingProps) { @@ -95,6 +96,7 @@ export function ReportSettings(props: ReportSettingProps) { showSettingsReportSourceError, settingsReportSourceErrorMessage, showTimeRangeError, + uiSettings, } = props; const [reportName, setReportName] = useState(''); @@ -738,6 +740,7 @@ export function ReportSettings(props: ReportSettingProps) { {displaySavedSearchSelect} { + return { + start: from, + end: to, + label: display, + }; + }); return (
@@ -220,7 +229,7 @@ export function TimeRangeSelect(props) { end={end} onTimeChange={onTimeChange} showUpdateButton={false} - commonlyUsedRanges={commonTimeRanges} + commonlyUsedRanges={commonlyUsedRanges} />
diff --git a/dashboards-reports/public/plugin.ts b/dashboards-reports/public/plugin.ts index 707e9dd4..afe7da10 100644 --- a/dashboards-reports/public/plugin.ts +++ b/dashboards-reports/public/plugin.ts @@ -42,7 +42,9 @@ export class ReportsDashboardsPlugin implements Plugin< ReportsDashboardsPluginSetup, - ReportsDashboardsPluginStart + ReportsDashboardsPluginStart, + AppPluginStartDependencies, + any > { public setup(core: CoreSetup): ReportsDashboardsPluginSetup { // Register an application into the side navigation menu diff --git a/dashboards-reports/public/types.ts b/dashboards-reports/public/types.ts index 4c1c9b71..cdba3fb1 100644 --- a/dashboards-reports/public/types.ts +++ b/dashboards-reports/public/types.ts @@ -24,7 +24,7 @@ * permissions and limitations under the License. */ -import { NavigationPublicPluginStart } from '../../../src/plugins/navigation/public'; +import { DataPublicPluginStart } from '../../../src/plugins/data/public'; export interface ReportsDashboardsPluginSetup {} @@ -32,5 +32,5 @@ export interface ReportsDashboardsPluginSetup {} export interface ReportsDashboardsPluginStart {} export interface AppPluginStartDependencies { - navigation: NavigationPublicPluginStart; + data: DataPublicPluginStart; } diff --git a/dashboards-reports/test/uiSettingsMock.js b/dashboards-reports/test/uiSettingsMock.js new file mode 100644 index 00000000..14fd3a09 --- /dev/null +++ b/dashboards-reports/test/uiSettingsMock.js @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +const uiSettingsMock = jest.fn(); + +uiSettingsMock.get = jest.fn((key) => ([])); + +export default uiSettingsMock;