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

[8.x] [embeddable] replace Embeddable ViewMode with presentation-publishing ViewMode (#211960) #213135

Merged
merged 5 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -34,7 +34,6 @@ import {
ControlGroupRendererApi,
type ControlStateTransform,
} from '@kbn/controls-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';

const INPUT_KEY = 'kbnControls:saveExample:input';

Expand Down Expand Up @@ -210,7 +209,7 @@ export const EditExample = () => {
},
};
}}
viewMode={ViewMode.EDIT}
viewMode={'edit'}
/>
</EuiPanel>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import { CONTROL_GROUP_TYPE } from '@kbn/controls-plugin/common';
import { ControlGroupApi } from '@kbn/controls-plugin/public';
import { CoreStart } from '@kbn/core/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { ReactEmbeddableRenderer, ViewMode } from '@kbn/embeddable-plugin/public';
import { ReactEmbeddableRenderer } from '@kbn/embeddable-plugin/public';
import { AggregateQuery, Filter, Query, TimeRange } from '@kbn/es-query';
import { combineCompatibleChildrenApis } from '@kbn/presentation-containers';
import {
apiPublishesDataLoading,
HasUniqueId,
PublishesDataLoading,
useBatchedPublishingSubjects,
ViewMode as ViewModeType,
ViewMode,
} from '@kbn/presentation-publishing';
import { toMountPoint } from '@kbn/react-kibana-mount';

Expand All @@ -55,12 +55,12 @@ import {
const toggleViewButtons = [
{
id: `viewModeToggle_edit`,
value: ViewMode.EDIT,
value: 'edit',
label: 'Edit mode',
},
{
id: `viewModeToggle_view`,
value: ViewMode.VIEW,
value: 'view',
label: 'View mode',
},
];
Expand Down Expand Up @@ -95,7 +95,7 @@ export const ReactControlExample = ({
return new BehaviorSubject<[number, number] | undefined>(undefined);
}, []);
const viewMode$ = useMemo(() => {
return new BehaviorSubject<ViewModeType>(ViewMode.EDIT as ViewModeType);
return new BehaviorSubject<ViewMode>('edit');
}, []);
const saveNotification$ = useMemo(() => {
return new Subject<void>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import React, { useEffect, useState } from 'react';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import { EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
import { controlGroupStateBuilder } from '@kbn/controls-plugin/public';
Expand Down Expand Up @@ -70,7 +69,7 @@ export const DashboardWithControlsExample = ({ dataView }: { dataView: DataView
return {
getInitialInput: () => ({
timeRange: { from: 'now-30d', to: 'now' },
viewMode: ViewMode.VIEW,
viewMode: 'view',
controlGroupState,
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
EuiTitle,
} from '@elastic/eui';
import { DashboardApi, DashboardRenderer } from '@kbn/dashboard-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { useStateFromPublishingSubject } from '@kbn/presentation-publishing';

export const DualDashboardsExample = () => {
Expand All @@ -34,14 +33,14 @@ export const DualDashboardsExample = () => {
legend="View mode"
options={[
{
id: ViewMode.VIEW,
id: 'view',
label: 'View mode',
value: ViewMode.VIEW,
value: 'view',
},
{
id: ViewMode.EDIT,
id: 'edit',
label: 'Edit mode',
value: ViewMode.EDIT,
value: 'edit',
},
]}
idSelected={viewMode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { buildPhraseFilter, Filter } from '@kbn/es-query';
import type { DataView } from '@kbn/data-views-plugin/public';
import { DashboardRenderer, DashboardCreationOptions } from '@kbn/dashboard-plugin/public';
import { EuiCode, EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
import { ViewMode } from '@kbn/embeddable-plugin/public';

export const StaticByReferenceExample = ({
dashboardId,
Expand Down Expand Up @@ -51,7 +50,7 @@ export const StaticByReferenceExample = ({
const field = dataView.getFieldByName('machine.os.keyword');
let filter: Filter;
let creationOptions: DashboardCreationOptions = {
getInitialInput: () => ({ viewMode: ViewMode.VIEW }),
getInitialInput: () => ({ viewMode: 'view' }),
};
if (field) {
filter = buildPhraseFilter(field, 'win xp', dataView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import React from 'react';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
import type { DashboardPanelMap } from '@kbn/dashboard-plugin/common';
import { DashboardRenderer } from '@kbn/dashboard-plugin/public';
Expand All @@ -32,7 +31,7 @@ export const StaticByValueExample = () => {
return {
getInitialInput: () => ({
timeRange: { from: 'now-30d', to: 'now' },
viewMode: ViewMode.VIEW,
viewMode: 'view',
panels: panelsJson as DashboardPanelMap,
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
PublishesSavedSearch,
HasTimeRange,
} from '@kbn/discover-plugin/public';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import {
apiCanAccessViewMode,
Expand Down Expand Up @@ -158,7 +157,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
return false;
}

return getInheritedViewMode(embeddable) !== ViewMode.EDIT;
return getInheritedViewMode(embeddable) !== 'edit';
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@kbn/discover-utils",
"@kbn/saved-search-plugin",
"@kbn/discover-plugin",
"@kbn/embeddable-plugin",
"@kbn/ui-actions-plugin",
"@kbn/react-kibana-mount",
"@kbn/reporting-public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ViewMode } from '@kbn/embeddable-plugin/common';
import { ViewMode } from '@kbn/presentation-publishing';
import { useCallback, useEffect, useState } from 'react';

interface UseViewEditModeArgs {
initialMode?: ViewMode;
}

export const useViewEditMode = ({ initialMode = ViewMode.VIEW }: UseViewEditModeArgs) => {
export const useViewEditMode = ({ initialMode = 'view' }: UseViewEditModeArgs) => {
const [filterGroupMode, setFilterGroupMode] = useState(initialMode);

const [hasPendingChanges, setHasPendingChanges] = useState(false);
Expand All @@ -33,15 +33,15 @@ export const useViewEditMode = ({ initialMode = ViewMode.VIEW }: UseViewEditMode
}, [hasPendingChanges]);

const switchToEditMode = useCallback(() => {
setFilterGroupMode(ViewMode.EDIT);
setFilterGroupMode('edit');
}, []);

const switchToViewMode = useCallback(() => {
setHasPendingChanges(false);
setFilterGroupMode(ViewMode.VIEW);
setFilterGroupMode('view');
}, []);

const isViewMode = filterGroupMode === ViewMode.VIEW;
const isViewMode = filterGroupMode === 'view';

return {
filterGroupMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@kbn/es-query",
"@kbn/ui-theme",
"@kbn/controls-plugin",
"@kbn/embeddable-plugin",
"@kbn/core-http-browser",
"@kbn/core-notifications-browser",
"@kbn/kibana-utils-plugin",
Expand All @@ -35,5 +34,6 @@
"@kbn/core-http-browser-mocks",
"@kbn/core-notifications-browser-mocks",
"@kbn/shared-ux-table-persist",
"@kbn/presentation-publishing",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import {
apiCanAccessViewMode,
Expand All @@ -32,7 +31,7 @@ const isApiCompatible = (api: unknown | null): api is InputControlDeprecationAct
const compatibilityCheck = (api: EmbeddableApiContext['embeddable']) => {
return (
isApiCompatible(api) &&
getInheritedViewMode(api) === ViewMode.EDIT &&
getInheritedViewMode(api) === 'edit' &&
api.getVis().type.name === INPUT_CONTROL_VIS_TYPE
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
EuiIcon,
EuiToolTip,
} from '@elastic/eui';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import {
apiHasParentApi,
Expand Down Expand Up @@ -119,8 +118,8 @@ export const ControlPanel = <ApiType extends DefaultControlApi = DefaultControlA
setInitialLoadComplete(true);
}

const viewMode = (rawViewMode ?? ViewMode.VIEW) as ViewMode;
const isEditable = viewMode === ViewMode.EDIT;
const viewMode = rawViewMode ?? 'view';
const isEditable = viewMode === 'edit';
const controlWidth = width ?? DEFAULT_CONTROL_WIDTH;
const controlGrow = grow ?? DEFAULT_CONTROL_GROW;
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import React, { FC, ReactElement, useEffect, useState } from 'react';
import { v4 } from 'uuid';
import { Subscription, switchMap } from 'rxjs';

import { type ViewMode } from '@kbn/embeddable-plugin/public';
import { apiHasUniqueId } from '@kbn/presentation-publishing';
import { ViewMode, apiHasUniqueId } from '@kbn/presentation-publishing';
import { Action } from '@kbn/ui-actions-plugin/public';
import { AnyApiAction } from '@kbn/presentation-panel-plugin/public/panel_actions/types';
import { uiActionsService } from '../../services/kibana_services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { BehaviorSubject, Subject } from 'rxjs';
import { v4 as uuidv4 } from 'uuid';

import { ReactEmbeddableRenderer, ViewMode } from '@kbn/embeddable-plugin/public';
import { ReactEmbeddableRenderer } from '@kbn/embeddable-plugin/public';
import type { Filter, Query, TimeRange } from '@kbn/es-query';
import { useSearchApi, type ViewMode as ViewModeType } from '@kbn/presentation-publishing';
import { useSearchApi, type ViewMode } from '@kbn/presentation-publishing';

import type { ControlGroupApi } from '../..';
import {
Expand All @@ -38,7 +38,7 @@ export interface ControlGroupRendererProps {
initialState: Partial<ControlGroupRuntimeState>,
builder: ControlGroupStateBuilder
) => Promise<Partial<ControlGroupCreationOptions>>;
viewMode?: ViewModeType;
viewMode?: ViewMode;
filters?: Filter[];
timeRange?: TimeRange;
query?: Query;
Expand Down Expand Up @@ -70,7 +70,7 @@ export const ControlGroupRenderer = ({
});

const viewMode$ = useMemo(
() => new BehaviorSubject<ViewModeType>(viewMode ?? ViewMode.VIEW),
() => new BehaviorSubject<ViewMode>(viewMode ?? 'view'),
// viewMode only used as initial value - changes do not effect memoized value.
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { SEARCH_EMBEDDABLE_TYPE } from '@kbn/discover-utils';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/common';
import { BehaviorSubject } from 'rxjs';

Expand Down Expand Up @@ -54,7 +53,7 @@ describe('view saved search action', () => {
const action = new ViewSavedSearchAction(applicationMock, services.locator);
expect(
await action.isCompatible({
embeddable: { ...compatibleEmbeddableApi, viewMode$: new BehaviorSubject(ViewMode.EDIT) },
embeddable: { ...compatibleEmbeddableApi, viewMode$: new BehaviorSubject('edit') },
})
).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { SEARCH_EMBEDDABLE_TYPE } from '@kbn/discover-utils';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import {
apiCanAccessViewMode,
apiHasType,
Expand All @@ -28,7 +27,7 @@ export const compatibilityCheck = (
): api is ViewSavedSearchActionApi => {
return (
apiCanAccessViewMode(api) &&
getInheritedViewMode(api) === ViewMode.VIEW &&
getInheritedViewMode(api) === 'view' &&
apiHasType(api) &&
apiIsOfType(api, SEARCH_EMBEDDABLE_TYPE) &&
apiPublishesSavedSearch(api)
Expand Down
1 change: 0 additions & 1 deletion src/platform/plugins/shared/embeddable/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ export type {
EmbeddablePersistableStateService,
EmbeddableRegistryDefinition,
} from './types';
export { ViewMode } from './types';
export type { SavedObjectEmbeddableInput } from './lib';
export { isSavedObjectEmbeddableInput } from './lib';
9 changes: 1 addition & 8 deletions src/platform/plugins/shared/embeddable/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,9 @@ import type {
PersistableStateDefinition,
} from '@kbn/kibana-utils-plugin/common';

export enum ViewMode {
EDIT = 'edit',
PREVIEW = 'preview',
PRINT = 'print',
VIEW = 'view',
}

export type EmbeddableInput = {
version?: string;
viewMode?: ViewMode;
viewMode?: 'view' | 'edit' | 'print' | 'preview';
title?: string;
description?: string;
/**
Expand Down
1 change: 0 additions & 1 deletion src/platform/plugins/shared/embeddable/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export {
SELECT_RANGE_TRIGGER,
VALUE_CLICK_TRIGGER,
} from './ui_actions/triggers';
export { ViewMode } from '../common/types';
export type {
CellValueContext,
ChartActionContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"requiredBundles": [
"data",
"dataViews",
"embeddable",
"inspector",
"visualizations"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import type { TimeRange } from '@kbn/data-plugin/common';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import type { DefaultInspectorAdapters } from '@kbn/expressions-plugin/common';
import type { EmbeddableComponentProps, TypedLensByValueInput } from '@kbn/lens-plugin/public';
import { useCallback, useEffect, useState } from 'react';
Expand Down Expand Up @@ -87,7 +86,7 @@ export const getLensProps = ({
onLoad: (isLoading: boolean, adapters: Partial<DefaultInspectorAdapters> | undefined) => void;
}): LensProps => ({
id: 'unifiedHistogramLensComponent',
viewMode: ViewMode.VIEW,
viewMode: 'view',
timeRange: getTimeRange(),
attributes,
noPadding: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@kbn/test-jest-helpers",
"@kbn/i18n",
"@kbn/es-query",
"@kbn/embeddable-plugin",
"@kbn/core-ui-settings-browser",
"@kbn/datemath",
"@kbn/core-ui-settings-browser-mocks",
Expand Down
Loading