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

[embeddable] replace embeddablePlugin.viewMode with presenatation-publishing.viewMode #204820

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions x-pack/examples/embedded_lens_example/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import type {
DateHistogramIndexPatternColumn,
} from '@kbn/lens-plugin/public';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { ActionExecutionContext } from '@kbn/ui-actions-plugin/public';
import type { StartDependencies } from './plugin';

Expand Down Expand Up @@ -268,7 +267,7 @@ export const App = (props: {
onTableRowClick={(_data) => {
// call back event for on table row click event
}}
viewMode={ViewMode.VIEW}
viewMode={'view'}
extraActions={[
{
id: 'testAction',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
import type { CoreStart } from '@kbn/core/public';
import type { LensEmbeddableInput, FormulaPublicApi } from '@kbn/lens-plugin/public';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { ActionExecutionContext } from '@kbn/ui-actions-plugin/public';
import { LensConfig, LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder';
import { DataViewsContract } from '@kbn/data-views-plugin/public';
Expand Down Expand Up @@ -128,7 +127,7 @@ export const App = (props: {
onTableRowClick={(_data) => {
// call back event for on table row click event
}}
viewMode={ViewMode.VIEW}
viewMode={'view'}
extraActions={[
{
id: 'testAction',
Expand Down
3 changes: 1 addition & 2 deletions x-pack/examples/testing_embedded_lens/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type { CoreStart } from '@kbn/core/public';
import useDebounce from 'react-use/lib/useDebounce';
import { DOCUMENT_FIELD_NAME } from '@kbn/lens-plugin/common/constants';
import type { DataView } from '@kbn/data-views-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import type {
TypedLensByValueInput,
PersistedIndexPatternLayer,
Expand Down Expand Up @@ -631,7 +630,7 @@ export const App = (props: {
// call back event for on table row click event
}}
disableTriggers={!enableTriggers}
viewMode={ViewMode.VIEW}
viewMode={'view'}
withDefaultActions={enableDefaultAction}
extraActions={
enableExtraAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useMemo } from 'react';
import type { DashboardStart } from '@kbn/dashboard-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import type { ViewMode } from '@kbn/presentation-publishing';
import { useMlKibana } from '../contexts/kibana';

export type DashboardService = ReturnType<typeof dashboardServiceProvider>;
Expand Down Expand Up @@ -38,10 +38,10 @@ export function dashboardServiceProvider(dashboardService: DashboardStart) {
/**
* Generates dashboard url
*/
async getDashboardUrl(dashboardId: string, viewMode: ViewMode = ViewMode.EDIT) {
async getDashboardUrl(dashboardId: string, viewMode: ViewMode = 'edit') {
return await dashboardService.locator?.getUrl({
dashboardId,
viewMode: ViewMode.EDIT,
viewMode: 'edit',
useHash: false,
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '@elastic/eui';
import { useEuiTheme } from '@elastic/eui';
import { asyncForEach } from '@kbn/std';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import type { Module } from '../../../../common/types/modules';
import { useDashboardService } from '../../services/dashboard_service';
import { useMlKibana } from '../../contexts/kibana';
Expand Down Expand Up @@ -53,7 +52,7 @@ export const KibanaTabContent: FC<Props> = ({ module, selectedKibanaSubTab }) =>
const result = await dashboardService.fetchDashboardsById(dashboardIds);

await asyncForEach(result, async ({ id }) => {
const url = await dashboardService.getDashboardUrl(id, ViewMode.VIEW);
const url = await dashboardService.getDashboardUrl(id, 'view');
if (url) {
allUrls[id] = url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { CoreStart } from '@kbn/core/public';
import { DiscoverAppLocatorParams } from '@kbn/discover-plugin/common';
import { DiscoverStart } from '@kbn/discover-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import { StartServicesGetter } from '@kbn/kibana-utils-plugin/public';
import { DOC_TYPE as LENS_DOC_TYPE } from '@kbn/lens-plugin/common/constants';
Expand Down Expand Up @@ -51,7 +50,7 @@ const isApiCompatible = (api: unknown | null): api is AbstractExploreDataActionA
const compatibilityCheck = (api: EmbeddableApiContext['embeddable']) => {
return (
isApiCompatible(api) &&
getInheritedViewMode(api) === ViewMode.VIEW &&
getInheritedViewMode(api) === 'view' &&
!apiIsOfType(api, LENS_DOC_TYPE)
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
EuiLoadingLogo,
} from '@elastic/eui';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import {
DashboardApi,
DashboardCreationOptions,
Expand Down Expand Up @@ -104,7 +103,7 @@ export function ServiceDashboards() {

const getCreationOptions = useCallback((): Promise<DashboardCreationOptions> => {
const getInitialInput = () => ({
viewMode: ViewMode.VIEW,
viewMode: 'view',
timeRange: { from: rangeFrom, to: rangeTo },
});
return Promise.resolve<DashboardCreationOptions>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/
import React from 'react';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { useEuiTheme } from '@elastic/eui';
import { useKibanaContextForPlugin } from '../../../../../../hooks/use_kibana';
import {
Expand Down Expand Up @@ -56,7 +55,7 @@ export function LogThresholdCountChart({
style={{ height }}
timeRange={timeRange}
attributes={lensDef}
viewMode={ViewMode.VIEW}
viewMode={'view'}
noPadding
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/
import React from 'react';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { useEuiTheme } from '@elastic/eui';
import { useKibanaContextForPlugin } from '../../../../../../hooks/use_kibana';
import {
Expand Down Expand Up @@ -59,7 +58,7 @@ export function LogThresholdRatioChart({
style={{ height }}
timeRange={timeRange}
attributes={lensDef}
viewMode={ViewMode.VIEW}
viewMode={'view'}
noPadding
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
EuiLoadingLogo,
} from '@elastic/eui';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import {
DashboardApi,
DashboardCreationOptions,
Expand Down Expand Up @@ -132,7 +131,7 @@ export function Dashboards() {

const getCreationOptions = useCallback((): Promise<DashboardCreationOptions> => {
const getInitialInput = () => ({
viewMode: ViewMode.VIEW,
viewMode: 'view',
timeRange: { from: dateRange.from, to: dateRange.to },
});
return Promise.resolve<DashboardCreationOptions>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/
import React, { useEffect, useState, useRef, useCallback } from 'react';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { TypedLensByValueInput } from '@kbn/lens-plugin/public';
import { css } from '@emotion/react';
import { useEuiTheme } from '@elastic/eui';
Expand Down Expand Up @@ -115,7 +114,7 @@ export const LensWrapper = ({
onLoad={handleOnLoad}
query={state.query}
timeRange={dateRange}
viewMode={ViewMode.VIEW}
viewMode={'view'}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { SLOWithSummaryResponse } from '@kbn/slo-schema';
import moment from 'moment';
import React from 'react';
Expand Down Expand Up @@ -58,7 +57,7 @@ export function ErrorRateChart({
to,
}}
attributes={lensDef}
viewMode={ViewMode.VIEW}
viewMode={'view'}
onBrushEnd={({ range }) => {
onBrushed?.({
from: moment(range[0]).toDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import React, { useCallback, useMemo, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import {
CountIndexPatternColumn,
PersistedIndexPatternLayer,
Expand Down Expand Up @@ -97,7 +96,7 @@ export function VisitorBreakdownChart({
from: start ?? '',
to: end ?? '',
}}
viewMode={ViewMode.VIEW}
viewMode={'view'}
onFilter={filterHandler}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React, { useCallback, useMemo } from 'react';
import { useDispatch } from 'react-redux';

import { FormattedMessage } from '@kbn/i18n-react';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import styled from 'styled-components';
import { EuiEmptyPrompt, EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
import type { RangeFilterParams } from '@kbn/es-query';
Expand Down Expand Up @@ -256,7 +255,7 @@ const LensEmbeddableComponent: React.FC<LensEmbeddableComponentProps> = ({
syncCursor={false}
syncTooltips={false}
timeRange={timerange}
viewMode={ViewMode.VIEW}
viewMode={'view'}
withDefaultActions={false}
/>
</LensComponentWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
import { render } from '@testing-library/react';
import React from 'react';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { DashboardRenderer as DashboardContainerRenderer } from '@kbn/dashboard-plugin/public';

import { TestProviders } from '../../common/mock';
Expand Down Expand Up @@ -57,7 +56,7 @@ describe('DashboardRenderer', () => {
expect(input).toEqual(
expect.objectContaining({
timeRange: props.timeRange,
viewMode: ViewMode.VIEW,
viewMode: 'view',
query: undefined,
filters: undefined,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
DashboardLocatorParams,
} from '@kbn/dashboard-plugin/public';
import { DashboardRenderer as DashboardContainerRenderer } from '@kbn/dashboard-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import type { ViewMode } from '@kbn/presentation-publishing';
import type { Filter, Query } from '@kbn/es-query';

import { useDispatch } from 'react-redux';
Expand All @@ -40,7 +40,7 @@ const DashboardRendererComponent = ({
query,
savedObjectId,
timeRange,
viewMode = ViewMode.VIEW,
viewMode = 'view',
}: {
canReadDashboard: boolean;
dashboardContainer?: DashboardApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { DashboardToolBar } from './dashboard_tool_bar';
import type { DashboardApi } from '@kbn/dashboard-plugin/public';
import { coreMock } from '@kbn/core/public/mocks';
import { DashboardTopNav } from '@kbn/dashboard-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { APP_NAME } from '../../../common/constants';
import { NavigationProvider, SecurityPageName } from '@kbn/security-solution-navigation';
import { TestProviders } from '../../common/mock';
Expand Down Expand Up @@ -60,7 +59,7 @@ describe('DashboardToolBar', () => {
});

it('should render the DashboardToolBar component with the correct props for view mode', () => {
expect(mockOnLoad).toHaveBeenCalledWith(ViewMode.VIEW);
expect(mockOnLoad).toHaveBeenCalledWith('view');
});

it('should render the DashboardTopNav component with the correct redirect to listing url', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { useCallback, useEffect, useMemo } from 'react';
import type { DashboardApi } from '@kbn/dashboard-plugin/public';
import { DashboardTopNav, LEGACY_DASHBOARD_APP_ID } from '@kbn/dashboard-plugin/public';
import type { ViewMode } from '@kbn/embeddable-plugin/public';
import type { ViewMode } from '@kbn/presentation-publishing';

import type { ChromeBreadcrumb } from '@kbn/core/public';
import type { DashboardCapabilities } from '@kbn/dashboard-plugin/common';
Expand Down Expand Up @@ -56,7 +56,7 @@ const DashboardToolBarComponent = ({
);

useEffect(() => {
onLoad?.((viewMode as ViewMode) ?? 'view');
onLoad?.(viewMode ?? 'view');
}, [onLoad, viewMode]);

const embedSettings = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Router } from '@kbn/shared-ux-router';
import { DashboardView } from '.';
import { useCapabilities } from '../../../common/lib/kibana';
import { TestProviders } from '../../../common/mock';
import { ViewMode } from '@kbn/embeddable-plugin/public';

jest.mock('react-router-dom', () => {
const actual = jest.requireActual('react-router-dom');
Expand Down Expand Up @@ -69,7 +68,7 @@ describe('DashboardView', () => {
test('render when no error state', () => {
const { queryByTestId } = render(
<Router history={mockHistory}>
<DashboardView initialViewMode={ViewMode.VIEW} />
<DashboardView initialViewMode={'view'} />
</Router>,
{ wrapper: TestProviders }
);
Expand All @@ -84,7 +83,7 @@ describe('DashboardView', () => {
});
const { queryByTestId } = render(
<Router history={mockHistory}>
<DashboardView initialViewMode={ViewMode.VIEW} />
<DashboardView initialViewMode={view} />
</Router>,
{ wrapper: TestProviders }
);
Expand All @@ -96,7 +95,7 @@ describe('DashboardView', () => {
test('render dashboard view with height', () => {
const { queryByTestId } = render(
<Router history={mockHistory}>
<DashboardView initialViewMode={ViewMode.VIEW} />
<DashboardView initialViewMode={'view'} />
</Router>,
{ wrapper: TestProviders }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { DashboardCapabilities } from '@kbn/dashboard-plugin/common/types';
import { useParams } from 'react-router-dom';
import { pick } from 'lodash/fp';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import type { ViewMode } from '@kbn/embeddable-plugin/common';
import type { ViewMode } from '@kbn/presentation-publishing';
import { SecurityPageName } from '../../../../common/constants';
import { SpyRoute } from '../../../common/utils/route/spy_routes';
import { useCapabilities } from '../../../common/lib/kibana';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import React from 'react';
import { Routes, Route } from '@kbn/shared-ux-router';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { DashboardsLandingPage } from './landing_page';
import { DashboardView } from './details';
import { DASHBOARDS_PATH } from '../../../common/constants';
Expand All @@ -18,13 +17,13 @@ const DashboardsContainerComponent = () => {
<DashboardContextProvider>
<Routes>
<Route strict path={`${DASHBOARDS_PATH}/create`}>
<DashboardView initialViewMode={ViewMode.EDIT} />
<DashboardView initialViewMode={'edit'} />
</Route>
<Route strict path={`${DASHBOARDS_PATH}/:detailName/edit`}>
<DashboardView initialViewMode={ViewMode.EDIT} />
<DashboardView initialViewMode={'edit'} />
</Route>
<Route strict path={`${DASHBOARDS_PATH}/:detailName`}>
<DashboardView initialViewMode={ViewMode.VIEW} />
<DashboardView initialViewMode={'view'} />
</Route>
<Route path={`${DASHBOARDS_PATH}`}>
<DashboardsLandingPage />
Expand Down