Skip to content

Commit

Permalink
Merge branch '8.x' into recover/backport/8.x/pr-202848
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Dec 16, 2024
2 parents 7931a63 + 7f97a3e commit 65b4b5a
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,15 @@ export function getDashboardApi({
controlGroupApi$,
panelsManager.api.children$
);
const settingsManager = initializeSettingsManager(initialState);
const unifiedSearchManager = initializeUnifiedSearchManager(
initialState,
controlGroupApi$,
settingsManager.api.timeRestore$,
dataLoadingManager.internalApi.waitForPanelsToLoad$,
() => unsavedChangesManager.internalApi.getLastSavedState(),
creationOptions
);
const settingsManager = initializeSettingsManager({
initialState,
setTimeRestore: unifiedSearchManager.internalApi.setTimeRestore,
timeRestore$: unifiedSearchManager.internalApi.timeRestore$,
});
const unsavedChangesManager = initializeUnsavedChangesManager({
creationOptions,
controlGroupApi$,
Expand Down
54 changes: 14 additions & 40 deletions src/plugins/dashboard/public/dashboard_api/settings_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,12 @@
*/

import fastIsEqual from 'fast-deep-equal';
import {
PublishingSubject,
StateComparators,
initializeTitles,
} from '@kbn/presentation-publishing';
import { StateComparators, initializeTitles } from '@kbn/presentation-publishing';
import { BehaviorSubject } from 'rxjs';
import { DashboardState } from './types';
import { DashboardSettings, DashboardState } from './types';
import { DEFAULT_DASHBOARD_INPUT } from '../dashboard_constants';
import { DashboardStateFromSettingsFlyout } from '../dashboard_container/types';

export function initializeSettingsManager({
initialState,
setTimeRestore,
timeRestore$,
}: {
initialState?: DashboardState;
setTimeRestore: (timeRestore: boolean) => void;
timeRestore$: PublishingSubject<boolean | undefined>;
}) {
export function initializeSettingsManager(initialState?: DashboardState) {
const syncColors$ = new BehaviorSubject<boolean>(
initialState?.syncColors ?? DEFAULT_DASHBOARD_INPUT.syncColors
);
Expand All @@ -50,6 +37,12 @@ export function initializeSettingsManager({
if (!fastIsEqual(tags, tags$.value)) tags$.next(tags);
}
const titleManager = initializeTitles(initialState ?? {});
const timeRestore$ = new BehaviorSubject<boolean | undefined>(
initialState?.timeRestore ?? DEFAULT_DASHBOARD_INPUT.timeRestore
);
function setTimeRestore(timeRestore: boolean) {
if (timeRestore !== timeRestore$.value) timeRestore$.next(timeRestore);
}
const useMargins$ = new BehaviorSubject<boolean>(
initialState?.useMargins ?? DEFAULT_DASHBOARD_INPUT.useMargins
);
Expand All @@ -69,7 +62,7 @@ export function initializeSettingsManager({
};
}

function setSettings(settings: DashboardStateFromSettingsFlyout) {
function setSettings(settings: DashboardSettings) {
setSyncColors(settings.syncColors);
setSyncCursor(settings.syncCursor);
setSyncTooltips(settings.syncTooltips);
Expand Down Expand Up @@ -100,35 +93,16 @@ export function initializeSettingsManager({
syncColors: [syncColors$, setSyncColors],
syncCursor: [syncCursor$, setSyncCursor],
syncTooltips: [syncTooltips$, setSyncTooltips],
timeRestore: [timeRestore$, setTimeRestore],
useMargins: [useMargins$, setUseMargins],
} as StateComparators<
Pick<
DashboardState,
| 'description'
| 'hidePanelTitles'
| 'syncColors'
| 'syncCursor'
| 'syncTooltips'
| 'title'
| 'useMargins'
>
>,
} as StateComparators<Omit<DashboardSettings, 'tags'>>,
internalApi: {
getState: (): Pick<
DashboardState,
| 'description'
| 'hidePanelTitles'
| 'syncColors'
| 'syncCursor'
| 'syncTooltips'
| 'tags'
| 'title'
| 'useMargins'
> => {
getState: (): DashboardSettings => {
const settings = getSettings();
return {
...settings,
title: settings.title ?? '',
timeRestore: settings.timeRestore ?? DEFAULT_DASHBOARD_INPUT.timeRestore,
hidePanelTitles: settings.hidePanelTitles ?? DEFAULT_DASHBOARD_INPUT.hidePanelTitles,
};
},
Expand Down
31 changes: 12 additions & 19 deletions src/plugins/dashboard/public/dashboard_api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@ import { PublishesReload } from '@kbn/presentation-publishing/interfaces/fetch/p
import { PublishesSearchSession } from '@kbn/presentation-publishing/interfaces/fetch/publishes_search_session';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { DashboardPanelMap, DashboardPanelState } from '../../common';
import type { DashboardOptions } from '../../server/content_management';
import type { DashboardAttributes, DashboardOptions } from '../../server/content_management';
import {
LoadDashboardReturn,
SaveDashboardReturn,
} from '../services/dashboard_content_management_service/types';
import {
DashboardLocatorParams,
DashboardStateFromSettingsFlyout,
} from '../dashboard_container/types';
import { DashboardLocatorParams } from '../dashboard_container/types';

export const DASHBOARD_API_TYPE = 'dashboard';

Expand Down Expand Up @@ -93,23 +90,19 @@ export interface DashboardCreationOptions {
getEmbeddableAppContext?: (dashboardId?: string) => EmbeddableAppContext;
}

export interface DashboardState extends DashboardOptions {
// filter context to be passed to children
export type DashboardSettings = DashboardOptions & {
description?: DashboardAttributes['description'];
tags: string[];
timeRestore: DashboardAttributes['timeRestore'];
title: DashboardAttributes['description'];
};

export interface DashboardState extends DashboardSettings {
query: Query;
filters: Filter[];
timeRestore: boolean;
timeRange?: TimeRange;
refreshInterval?: RefreshInterval;

// dashboard meta info
title: string;
tags: string[];
viewMode: ViewMode;
description?: string;

// settings from DashboardOptions

// dashboard contents
panels: DashboardPanelMap;

/**
Expand Down Expand Up @@ -152,8 +145,8 @@ export type DashboardApi = CanExpandPanels &
fullScreenMode$: PublishingSubject<boolean>;
focusedPanelId$: PublishingSubject<string | undefined>;
forceRefresh: () => void;
getSettings: () => DashboardStateFromSettingsFlyout;
getDashboardPanelFromId: (id: string) => Promise<DashboardPanelState>;
getSettings: () => DashboardSettings;
hasOverlays$: PublishingSubject<boolean>;
hasUnsavedChanges$: PublishingSubject<boolean>;
highlightPanel: (panelRef: HTMLDivElement) => void;
Expand All @@ -173,7 +166,7 @@ export type DashboardApi = CanExpandPanels &
setPanels: (panels: DashboardPanelMap) => void;
setQuery: (query?: Query | undefined) => void;
setScrollToPanelId: (id: string | undefined) => void;
setSettings: (settings: DashboardStateFromSettingsFlyout) => void;
setSettings: (settings: DashboardSettings) => void;
setTags: (tags: string[]) => void;
setTimeRange: (timeRange?: TimeRange | undefined) => void;
unifiedSearchFilters$: PublishesUnifiedSearch['filters$'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { DEFAULT_DASHBOARD_INPUT, GLOBAL_STATE_STORAGE_KEY } from '../dashboard_
export function initializeUnifiedSearchManager(
initialState: DashboardState,
controlGroupApi$: PublishingSubject<ControlGroupApi | undefined>,
timeRestore$: PublishingSubject<boolean | undefined>,
waitForPanelsToLoad$: Observable<void>,
getLastSavedState: () => DashboardState | undefined,
creationOptions?: DashboardCreationOptions
Expand Down Expand Up @@ -97,12 +98,6 @@ export function initializeUnifiedSearchManager(
timefilterService.setTime(timeRangeOrDefault);
}
}
const timeRestore$ = new BehaviorSubject<boolean | undefined>(
initialState?.timeRestore ?? DEFAULT_DASHBOARD_INPUT.timeRestore
);
function setTimeRestore(timeRestore: boolean) {
if (timeRestore !== timeRestore$.value) timeRestore$.next(timeRestore);
}
const timeslice$ = new BehaviorSubject<[number, number] | undefined>(undefined);
const unifiedSearchFilters$ = new BehaviorSubject<Filter[] | undefined>(initialState.filters);
// setAndSyncUnifiedSearchFilters method not needed since filters synced with 2-way data binding
Expand Down Expand Up @@ -312,9 +307,8 @@ export function initializeUnifiedSearchManager(
return true;
},
],
timeRestore: [timeRestore$, setTimeRestore],
} as StateComparators<
Pick<DashboardState, 'filters' | 'query' | 'refreshInterval' | 'timeRange' | 'timeRestore'>
Pick<DashboardState, 'filters' | 'query' | 'refreshInterval' | 'timeRange'>
>,
internalApi: {
controlGroupReload$,
Expand All @@ -325,7 +319,6 @@ export function initializeUnifiedSearchManager(
...lastSavedState.filters,
]);
setQuery(lastSavedState.query);
setTimeRestore(lastSavedState.timeRestore);
if (lastSavedState.timeRestore) {
setAndSyncRefreshInterval(lastSavedState.refreshInterval);
setAndSyncTimeRange(lastSavedState.timeRange);
Expand All @@ -341,8 +334,6 @@ export function initializeUnifiedSearchManager(
timeRange: timeRange$.value,
timeRestore: timeRestore$.value ?? DEFAULT_DASHBOARD_INPUT.timeRestore,
}),
setTimeRestore,
timeRestore$,
},
cleanup: () => {
controlGroupSubscriptions.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { DashboardSettings } from './settings_flyout';
export { DashboardSettingsFlyout } from './settings_flyout';
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { DashboardContainerInput } from '../../../../common';
import { DashboardSettings } from '../../../dashboard_api/types';
import { useDashboardApi } from '../../../dashboard_api/use_dashboard_api';
import { getDashboardContentManagementService } from '../../../services/dashboard_content_management_service';
import { savedObjectsTaggingService } from '../../../services/kibana_services';
Expand All @@ -42,7 +42,7 @@ interface DashboardSettingsProps {

const DUPLICATE_TITLE_CALLOUT_ID = 'duplicateTitleCallout';

export const DashboardSettings = ({ onClose }: DashboardSettingsProps) => {
export const DashboardSettingsFlyout = ({ onClose }: DashboardSettingsProps) => {
const dashboardApi = useDashboardApi();

const [localSettings, setLocalSettings] = useState(dashboardApi.getSettings());
Expand Down Expand Up @@ -81,7 +81,7 @@ export const DashboardSettings = ({ onClose }: DashboardSettingsProps) => {
}
};

const updateDashboardSetting = useCallback((newSettings: Partial<DashboardContainerInput>) => {
const updateDashboardSetting = useCallback((newSettings: Partial<DashboardSettings>) => {
setLocalSettings((prevSettings) => {
return {
...prevSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { toMountPoint } from '@kbn/react-kibana-mount';
import { DashboardApi } from '../../../dashboard_api/types';
import { DashboardContext } from '../../../dashboard_api/use_dashboard_api';
import { coreServices } from '../../../services/kibana_services';
import { DashboardSettings } from '../../component/settings/settings_flyout';
import { DashboardSettingsFlyout } from '../../component/settings/settings_flyout';

export function openSettingsFlyout(dashboardApi: DashboardApi) {
dashboardApi.openOverlay(
coreServices.overlays.openFlyout(
toMountPoint(
<DashboardContext.Provider value={dashboardApi}>
<DashboardSettings
<DashboardSettingsFlyout
onClose={() => {
dashboardApi.clearOverlays();
}}
Expand Down
11 changes: 1 addition & 10 deletions src/plugins/dashboard/public/dashboard_container/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SerializableRecord } from '@kbn/utility-types';

import { ControlGroupRuntimeState } from '@kbn/controls-plugin/public';
import type { DashboardContainerInput } from '../../common';
import type { DashboardOptions, DashboardPanel } from '../../server/content_management';
import type { DashboardPanel } from '../../server/content_management';

export interface UnsavedPanelState {
[key: string]: object | undefined;
Expand All @@ -23,13 +23,6 @@ export type RedirectToProps =
| { destination: 'dashboard'; id?: string; useReplace?: boolean; editMode?: boolean }
| { destination: 'listing'; filter?: string; useReplace?: boolean };

export type DashboardStateFromSaveModal = Pick<
DashboardContainerInput,
'title' | 'description' | 'tags' | 'timeRestore'
>;

export type DashboardStateFromSettingsFlyout = DashboardStateFromSaveModal & DashboardOptions;

export type DashboardLoadType =
| 'sessionFirstLoad'
| 'dashboardFirstLoad'
Expand All @@ -41,8 +34,6 @@ export interface DashboardRenderPerformanceStats {
panelsRenderStartTime: number;
}

export type DashboardContainerInputWithoutId = Omit<DashboardContainerInput, 'id'>;

export interface DashboardContainerOutput extends ContainerOutput {
usedDataViewIds?: string[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ info:
title: Auto Import Analyze Logs API endpoint
version: "1"
paths:
/api/integration_assistant/analyzelogs:
/internal/automatic_import/analyzelogs:
post:
summary: Analyzes log samples and processes them.
operationId: AnalyzeLogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ info:
title: Integration Assistatnt Build Integrarion API endpoint
version: "1"
paths:
/api/integration_assistant/build:
/internal/automatic_import/build:
post:
summary: Builds Integration with the given input samples
operationId: BuildIntegration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ info:
title: Integration Assistatnt Categorization API endpoint
version: "1"
paths:
/api/integration_assistant/categorization:
/internal/automatic_import/categorization:
post:
summary: Builds Categorization processors based on the samples
operationId: Categorization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ info:
title: Automatic Import CEL Input API endpoint
version: "1"
paths:
/api/integration_assistant/cel:
/internal/automatic_import/cel:
post:
summary: Builds CEL input configuration
operationId: CelInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ info:
title: Integration Assistatnt Check Pipeline API endpoint
version: "1"
paths:
/api/integration_assistant/pipeline:
/internal/automatic_import/pipeline:
post:
summary: Checks if the pipeline is valid for the given samples
operationId: CheckPipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ info:
title: Integration Assistatnt ECS Mapping API endpoint
version: "1"
paths:
/api/integration_assistant/ecs:
/internal/automatic_import/ecs:
post:
summary: Builds ECS Mapping based on the input samples
operationId: EcsMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ info:
title: Integration Assistatnt Related API endpoint
version: "1"
paths:
/api/integration_assistant/related:
/internal/automatic_import/related:
post:
summary: Builds related.* fields for integration with the given input samples
operationId: Related
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const PLUGIN_ID = 'integrationAssistant';
export const INTEGRATION_ASSISTANT_APP_ROUTE = '/app/integration_assistant';

// Server API Routes
export const INTEGRATION_ASSISTANT_BASE_PATH = '/api/integration_assistant';
export const INTEGRATION_ASSISTANT_BASE_PATH = '/internal/automatic_import';

export const ECS_GRAPH_PATH = `${INTEGRATION_ASSISTANT_BASE_PATH}/ecs`;
export const CATEGORIZATION_GRAPH_PATH = `${INTEGRATION_ASSISTANT_BASE_PATH}/categorization`;
Expand Down
Loading

0 comments on commit 65b4b5a

Please sign in to comment.