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

[Rename] visualize plugin #160

Merged
merged 2 commits into from
Mar 12, 2021
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
@@ -1,6 +1,6 @@
{
"id": "visualize",
"version": "kibana",
"version": "opensearchDashboards",
"server": true,
"ui": true,
"requiredPlugins": [
Expand All @@ -15,8 +15,8 @@
],
"optionalPlugins": ["home", "share"],
"requiredBundles": [
"kibanaUtils",
"kibanaReact",
"opensearchDashboardsUtils",
"opensearchDashboardsReact",
"home",
"discover",
"visDefaultEditor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { i18n } from '@kbn/i18n';
import { i18n } from '@osd/i18n';
import {
createAction,
ACTION_VISUALIZE_FIELD,
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/visualize/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import './app.scss';
import React, { useEffect } from 'react';
import { Route, Switch, useLocation } from 'react-router-dom';

import { AppMountParameters } from 'kibana/public';
import { AppMountParameters } from 'opensearch-dashboards/public';
import { syncQueryStateWithUrl } from '../../../data/public';
import { useKibana } from '../../../kibana_react/public';
import { useOpenSearchDashboards } from '../../../opensearch_dashboards_react/public';
import { VisualizeServices } from './types';
import {
VisualizeEditor,
Expand All @@ -41,20 +41,20 @@ export const VisualizeApp = ({ onAppLeave }: VisualizeAppProps) => {
const {
services: {
data: { query },
kbnUrlStateStorage,
osdUrlStateStorage,
},
} = useKibana<VisualizeServices>();
} = useOpenSearchDashboards<VisualizeServices>();
const { pathname } = useLocation();

useEffect(() => {
// syncs `_g` portion of url with query services
const { stop } = syncQueryStateWithUrl(query, kbnUrlStateStorage);
const { stop } = syncQueryStateWithUrl(query, osdUrlStateStorage);

return () => stop();

// this effect should re-run when pathname is changed to preserve querystring part,
// so the global state is always preserved
}, [query, kbnUrlStateStorage, pathname]);
}, [query, osdUrlStateStorage, pathname]);

return (
<Switch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React, { memo } from 'react';
import { EuiCallOut, EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage } from '@osd/i18n/react';

export const InfoComponent = () => {
const title = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import React, { useEffect, useState } from 'react';
import { EventEmitter } from 'events';

import { VisualizeInput } from 'src/plugins/visualizations/public';
import { useKibana } from '../../../../kibana_react/public';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import {
useChromeVisibility,
useVisByValue,
Expand All @@ -36,7 +36,7 @@ import { VisualizeAppProps } from '../app';

export const VisualizeByValueEditor = ({ onAppLeave }: VisualizeAppProps) => {
const [originatingApp, setOriginatingApp] = useState<string>();
const { services } = useKibana<VisualizeServices>();
const { services } = useOpenSearchDashboards<VisualizeServices>();
const [eventEmitter] = useState(new EventEmitter());
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
const [embeddableId, setEmbeddableId] = useState<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { EventEmitter } from 'events';

import { useKibana } from '../../../../kibana_react/public';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import {
useChromeVisibility,
useSavedVisInstance,
Expand All @@ -37,7 +37,7 @@ import { VisualizeAppProps } from '../app';
export const VisualizeEditor = ({ onAppLeave }: VisualizeAppProps) => {
const { id: visualizationIdFromUrl } = useParams<{ id: string }>();
const [originatingApp, setOriginatingApp] = useState<string>();
const { services } = useKibana<VisualizeServices>();
const { services } = useOpenSearchDashboards<VisualizeServices>();
const [eventEmitter] = useState(new EventEmitter());
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(!visualizationIdFromUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
import './visualize_editor.scss';
import React, { RefObject } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage } from '@osd/i18n/react';
import { EuiScreenReaderOnly } from '@elastic/eui';
import { AppMountParameters } from 'kibana/public';
import { AppMountParameters } from 'opensearch-dashboards/public';
import { VisualizeTopNav } from './visualize_top_nav';
import { ExperimentalVisInfo } from './experimental_vis_info';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import './visualize_listing.scss';

import React, { useCallback, useRef, useMemo, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { i18n } from '@osd/i18n';
import { useUnmount, useMount } from 'react-use';
import { useLocation } from 'react-router-dom';

import { useKibana, TableListView } from '../../../../kibana_react/public';
import { useOpenSearchDashboards, TableListView } from '../../../../opensearch_dashboards_react/public';
import { VISUALIZE_ENABLE_LABS_SETTING } from '../../../../visualizations/public';
import { VisualizeServices } from '../types';
import { VisualizeConstants } from '../visualize_constants';
Expand All @@ -44,7 +44,7 @@ export const VisualizeListing = () => {
uiSettings,
visualizeCapabilities,
},
} = useKibana<VisualizeServices>();
} = useOpenSearchDashboards<VisualizeServices>();
const { pathname } = useLocation();
const closeNewVisModal = useRef(() => {});
const listingLimit = savedObjectsPublic.settings.getListingLimit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
*/

import React, { useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@osd/i18n';
import { FormattedMessage } from '@osd/i18n/react';
import { EuiCallOut, EuiLink } from '@elastic/eui';

import { useKibana, toMountPoint } from '../../../../kibana_react/public';
import { useOpenSearchDashboards, toMountPoint } from '../../../../opensearch_dashboards_react/public';
import { VisualizeServices } from '../types';
import { VisualizeConstants } from '../visualize_constants';

let bannerId: string;

export const VisualizeNoMatch = () => {
const { services } = useKibana<VisualizeServices>();
const { services } = useOpenSearchDashboards<VisualizeServices>();

useEffect(() => {
services.restorePreviousUrl();

const { navigated } = services.urlForwarding.navigateToLegacyKibanaUrl(
const { navigated } = services.urlForwarding.navigateToLegacyOpenSearchDashboardsUrl(
services.history.location.pathname
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import React, { memo, useCallback, useMemo, useState, useEffect } from 'react';

import { AppMountParameters, OverlayRef } from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { useKibana } from '../../../../kibana_react/public';
import { AppMountParameters, OverlayRef } from 'opensearch-dashboards/public';
import { i18n } from '@osd/i18n';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import {
VisualizeServices,
VisualizeAppState,
Expand Down Expand Up @@ -63,7 +63,7 @@ const TopNav = ({
embeddableId,
onAppLeave,
}: VisualizeTopNavProps) => {
const { services } = useKibana<VisualizeServices>();
const { services } = useOpenSearchDashboards<VisualizeServices>();
const { TopNavMenu } = services.navigation.ui;
const { setHeaderActionMenu, visualizeCapabilities } = services;
const { embeddableHandler, vis } = visInstance;
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/visualize/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Router } from 'react-router-dom';

import { AppMountParameters } from 'kibana/public';
import { KibanaContextProvider } from '../../../kibana_react/public';
import { AppMountParameters } from 'opensearch-dashboards/public';
import { OpenSearchDashboardsContextProvider } from '../../../opensearch_dashboards_react/public';
import { VisualizeApp } from './app';
import { VisualizeServices } from './types';
import { addHelpMenuToAppChrome, addBadgeToAppChrome } from './utils';
Expand All @@ -40,11 +40,11 @@ export const renderApp = (

const app = (
<Router history={services.history}>
<KibanaContextProvider services={services}>
<OpenSearchDashboardsContextProvider services={services}>
<services.i18n.Context>
<VisualizeApp onAppLeave={onAppLeave} />
</services.i18n.Context>
</KibanaContextProvider>
</OpenSearchDashboardsContextProvider>
</Router>
);

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/visualize/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import {
ToastsStart,
ScopedHistory,
AppMountParameters,
} from 'kibana/public';
} from 'opensearch-dashboards/public';
import { NavigationPublicPluginStart as NavigationStart } from 'src/plugins/navigation/public';
import {
Storage,
IKbnUrlStateStorage,
IOsdUrlStateStorage,
ReduxLikeStateContainer,
} from 'src/plugins/kibana_utils/public';
} from 'src/plugins/opensearch_dashboards_utils/public';
import { SharePluginStart } from 'src/plugins/share/public';
import { SavedObjectsStart, SavedObject } from 'src/plugins/saved_objects/public';
import { EmbeddableStart } from 'src/plugins/embeddable/public';
Expand Down Expand Up @@ -95,7 +95,7 @@ export interface EditorRenderProps {
export interface VisualizeServices extends CoreStart {
embeddable: EmbeddableStart;
history: History;
kbnUrlStateStorage: IKbnUrlStateStorage;
osdUrlStateStorage: IOsdUrlStateStorage;
urlForwarding: UrlForwardingStart;
pluginInitializerContext: PluginInitializerContext;
chrome: ChromeStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { i18n } from '@osd/i18n';

import { VisualizeConstants } from '../visualize_constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* under the License.
*/

import { IKbnUrlStateStorage } from 'src/plugins/kibana_utils/public';
import { IOsdUrlStateStorage } from 'src/plugins/opensearch_dashboards_utils/public';
import { createVisualizeAppState } from './create_visualize_app_state';
import { migrateAppState } from './migrate_app_state';
import { visualizeAppStateStub } from './stubs';

const mockStartStateSync = jest.fn();
const mockStopStateSync = jest.fn();

jest.mock('../../../../kibana_utils/public', () => ({
jest.mock('../../../../opensearch_dashboards_utils/public', () => ({
createStateContainer: jest.fn(() => 'stateContainer'),
syncState: jest.fn(() => ({
start: mockStartStateSync,
Expand All @@ -36,27 +36,27 @@ jest.mock('./migrate_app_state', () => ({
migrateAppState: jest.fn(() => 'migratedAppState'),
}));

const { createStateContainer, syncState } = jest.requireMock('../../../../kibana_utils/public');
const { createStateContainer, syncState } = jest.requireMock('../../../../opensearch_dashboards_utils/public');

describe('createVisualizeAppState', () => {
const kbnUrlStateStorage = ({
const osdUrlStateStorage = ({
set: jest.fn(),
get: jest.fn(() => ({ linked: false })),
} as unknown) as IKbnUrlStateStorage;
} as unknown) as IOsdUrlStateStorage;

const { stateContainer, stopStateSync } = createVisualizeAppState({
stateDefaults: visualizeAppStateStub,
kbnUrlStateStorage,
osdUrlStateStorage,
});
const transitions = createStateContainer.mock.calls[0][1];

test('should initialize visualize app state', () => {
expect(kbnUrlStateStorage.get).toHaveBeenCalledWith('_a');
expect(osdUrlStateStorage.get).toHaveBeenCalledWith('_a');
expect(migrateAppState).toHaveBeenCalledWith({
...visualizeAppStateStub,
linked: false,
});
expect(kbnUrlStateStorage.set).toHaveBeenCalledWith('_a', 'migratedAppState', {
expect(osdUrlStateStorage.set).toHaveBeenCalledWith('_a', 'migratedAppState', {
replace: true,
});
expect(createStateContainer).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import { migrateAppState } from './migrate_app_state';
import {
createStateContainer,
syncState,
IKbnUrlStateStorage,
} from '../../../../kibana_utils/public';
IOsdUrlStateStorage,
} from '../../../../opensearch_dashboards_utils/public';
import { PureVisState, VisualizeAppState, VisualizeAppStateTransitions } from '../types';

const STATE_STORAGE_KEY = '_a';

interface Arguments {
kbnUrlStateStorage: IKbnUrlStateStorage;
osdUrlStateStorage: IOsdUrlStateStorage;
stateDefaults: VisualizeAppState;
byValue?: boolean;
}
Expand Down Expand Up @@ -84,8 +84,8 @@ function createVisualizeByValueAppState(stateDefaults: VisualizeAppState) {
return { stateContainer, stopStateSync };
}

function createDefaultVisualizeAppState({ stateDefaults, kbnUrlStateStorage }: Arguments) {
const urlState = kbnUrlStateStorage.get<VisualizeAppState>(STATE_STORAGE_KEY);
function createDefaultVisualizeAppState({ stateDefaults, osdUrlStateStorage }: Arguments) {
const urlState = osdUrlStateStorage.get<VisualizeAppState>(STATE_STORAGE_KEY);
const initialState = migrateAppState({
...stateDefaults,
...urlState,
Expand All @@ -97,7 +97,7 @@ function createDefaultVisualizeAppState({ stateDefaults, kbnUrlStateStorage }: A
we update the state format at all and want to handle BWC, we must not only migrate the
data stored with saved vis, but also any old state in the url.
*/
kbnUrlStateStorage.set(STATE_STORAGE_KEY, initialState, { replace: true });
osdUrlStateStorage.set(STATE_STORAGE_KEY, initialState, { replace: true });
const stateContainer = createStateContainer<VisualizeAppState, VisualizeAppStateTransitions>(
initialState,
pureTransitions
Expand All @@ -113,16 +113,16 @@ function createDefaultVisualizeAppState({ stateDefaults, kbnUrlStateStorage }: A
}
},
},
stateStorage: kbnUrlStateStorage,
stateStorage: osdUrlStateStorage,
});
// start syncing the appState with the ('_a') url
startStateSync();
return { stateContainer, stopStateSync };
}

export function createVisualizeAppState({ stateDefaults, kbnUrlStateStorage, byValue }: Arguments) {
export function createVisualizeAppState({ stateDefaults, osdUrlStateStorage, byValue }: Arguments) {
if (byValue) {
return createVisualizeByValueAppState(stateDefaults);
}
return createDefaultVisualizeAppState({ stateDefaults, kbnUrlStateStorage });
return createDefaultVisualizeAppState({ stateDefaults, osdUrlStateStorage });
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import React from 'react';
import { History } from 'history';
import { EuiBetaBadge, EuiButton, EuiEmptyPrompt, EuiIcon, EuiLink, EuiBadge } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@osd/i18n';
import { FormattedMessage } from '@osd/i18n/react';

import { ApplicationStart } from 'kibana/public';
import { ApplicationStart } from 'opensearch-dashboards/public';
import { VisualizationListItem } from 'src/plugins/visualizations/public';

const getBadge = (item: VisualizationListItem) => {
Expand Down
Loading