From eccf1e396e8ce736210a462922e0bc06b5799448 Mon Sep 17 00:00:00 2001 From: Elias Soares Date: Fri, 14 May 2021 09:20:56 -0300 Subject: [PATCH 1/4] Remove unnecessary dependencies and add uiSettings as dependency --- dashboards-reports/public/application.tsx | 5 ++--- dashboards-reports/public/components/app.tsx | 7 +++---- dashboards-reports/public/plugin.ts | 4 +++- dashboards-reports/public/types.ts | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dashboards-reports/public/application.tsx b/dashboards-reports/public/application.tsx index 32563cb7..08e363f1 100644 --- a/dashboards-reports/public/application.tsx +++ b/dashboards-reports/public/application.tsx @@ -31,8 +31,7 @@ import { AppPluginStartDependencies } from './types'; import { ReportsDashboardsApp } from './components/app'; export const renderApp = ( - { notifications, http, chrome }: CoreStart, - { navigation }: AppPluginStartDependencies, + { notifications, http, chrome, uiSettings }: CoreStart, { appBasePath, element }: AppMountParameters ) => { ReactDOM.render( @@ -40,7 +39,7 @@ export const renderApp = ( basename={appBasePath} notifications={notifications} http={http} - navigation={navigation} + uiSettings={uiSettings} chrome={chrome} />, element diff --git a/dashboards-reports/public/components/app.tsx b/dashboards-reports/public/components/app.tsx index a82711ef..0a7056c1 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'; @@ -60,8 +59,8 @@ interface ReportsDashboardsAppDeps { basename: string; notifications: CoreStart['notifications']; http: CoreStart['http']; - navigation: NavigationPublicPluginStart; chrome: CoreStart['chrome']; + uiSettings: IUiSettingsClient } const styles: CSS.Properties = { @@ -72,10 +71,9 @@ const styles: CSS.Properties = { export const ReportsDashboardsApp = ({ basename, - notifications, http, - navigation, chrome, + uiSettings }: ReportsDashboardsAppDeps) => { // Render the application DOM. return ( @@ -128,6 +126,7 @@ export const ReportsDashboardsApp = ({ 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; } From 4cfc9e6a91041d067a77b86914603188ed6da806 Mon Sep 17 00:00:00 2001 From: Elias Soares Date: Fri, 14 May 2021 09:31:09 -0300 Subject: [PATCH 2/4] Update time_range component to use `commonlyUsedRanges`from uiSettings --- .../create/create_report_definition.tsx | 2 ++ .../edit/edit_report_definition.tsx | 4 +++- .../report_settings/report_settings.tsx | 3 +++ .../report_settings_constants.tsx | 23 ------------------- .../report_settings/time_range.tsx | 14 +++++++++-- 5 files changed, 20 insertions(+), 26 deletions(-) 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) { { + return { + start: from, + end: to, + label: display, + }; + }); return (
@@ -220,7 +230,7 @@ export function TimeRangeSelect(props) { end={end} onTimeChange={onTimeChange} showUpdateButton={false} - commonlyUsedRanges={commonTimeRanges} + commonlyUsedRanges={commonlyUsedRanges} />
From f9d3e0f427ec7b0c4fe36d1519583fc93c1410dd Mon Sep 17 00:00:00 2001 From: Elias Soares Date: Fri, 14 May 2021 09:32:15 -0300 Subject: [PATCH 3/4] Remove unused notifications dependency --- dashboards-reports/public/application.tsx | 3 +-- dashboards-reports/public/components/app.tsx | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/dashboards-reports/public/application.tsx b/dashboards-reports/public/application.tsx index 08e363f1..94aa0c65 100644 --- a/dashboards-reports/public/application.tsx +++ b/dashboards-reports/public/application.tsx @@ -31,13 +31,12 @@ import { AppPluginStartDependencies } from './types'; import { ReportsDashboardsApp } from './components/app'; export const renderApp = ( - { notifications, http, chrome, uiSettings }: CoreStart, + { http, chrome, uiSettings }: CoreStart, { appBasePath, element }: AppMountParameters ) => { ReactDOM.render( Date: Fri, 14 May 2021 09:38:31 -0300 Subject: [PATCH 4/4] Test if time_range uses `uiSettings` to get `commonlyUsedRanges` --- .../__tests__/report_settings.test.tsx | 58 ++++++++++++++++++- .../report_settings/time_range.tsx | 3 +- dashboards-reports/test/uiSettingsMock.js | 31 ++++++++++ 3 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 dashboards-reports/test/uiSettingsMock.js diff --git a/dashboards-reports/public/components/report_definitions/report_settings/__tests__/report_settings.test.tsx b/dashboards-reports/public/components/report_definitions/report_settings/__tests__/report_settings.test.tsx index e61f377a..4e098bdd 100644 --- a/dashboards-reports/public/components/report_definitions/report_settings/__tests__/report_settings.test.tsx +++ b/dashboards-reports/public/components/report_definitions/report_settings/__tests__/report_settings.test.tsx @@ -30,6 +30,7 @@ import { ReportSettings } from '../report_settings'; import 'babel-polyfill'; import 'regenerator-runtime'; import httpClientMock from '../../../../../test/httpMockClient'; +import uiSettingsMock from '../../../../../test/uiSettingsMock'; import { configure, mount, shallow } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import { act } from 'react-dom/test-utils'; @@ -114,6 +115,7 @@ describe(' 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/time_range.tsx b/dashboards-reports/public/components/report_definitions/report_settings/time_range.tsx index 1fd29bd3..58a93094 100644 --- a/dashboards-reports/public/components/report_definitions/report_settings/time_range.tsx +++ b/dashboards-reports/public/components/report_definitions/report_settings/time_range.tsx @@ -33,7 +33,6 @@ import { EuiGlobalToastList, EuiSuperDatePicker, } from '@elastic/eui'; -import { UI_SETTINGS } from '../../../../../../src/plugins/data/common'; export function TimeRangeSelect(props) { const { @@ -205,7 +204,7 @@ export function TimeRangeSelect(props) { }; const commonlyUsedRanges = uiSettings! - .get(UI_SETTINGS.TIMEPICKER_QUICK_RANGES) + .get('timepicker:quickRanges') .map(({ from, to, display }: { from: string; to: string; display: string }) => { return { start: from, 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;