Skip to content
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
Expand Up @@ -8,16 +8,18 @@
import { Dataset } from '../datasets';
import { DataSourceSelectionStrategy } from './types';

const SELECTION_TYPE = 'all' as const;

export class AllDatasetSelection implements DataSourceSelectionStrategy {
selectionType: 'all';
selectionType: typeof SELECTION_TYPE;
selection: {
dataset: Dataset;
};

private constructor() {
this.selectionType = 'all';
private constructor({ indices }: { indices: string }) {
this.selectionType = SELECTION_TYPE;
this.selection = {
dataset: Dataset.createAllLogsDataset(),
dataset: Dataset.createAllLogsDataset({ indices }),
};
}

Expand All @@ -30,8 +32,13 @@ export class AllDatasetSelection implements DataSourceSelectionStrategy {
selectionType: this.selectionType,
};
}
public static getLocatorPlainSelection() {
return {
selectionType: SELECTION_TYPE,
};
}

public static create() {
return new AllDatasetSelection();
public static create({ indices }: { indices: string }) {
return new AllDatasetSelection({ indices });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { SingleDatasetSelection } from './single_dataset_selection';
import { DataSourceSelectionPlain } from './types';
import { UnresolvedDatasetSelection } from './unresolved_dataset_selection';

export const hydrateDataSourceSelection = (dataSourceSelection: DataSourceSelectionPlain) => {
export const hydrateDataSourceSelection = (
Comment thread
Kerry350 marked this conversation as resolved.
dataSourceSelection: DataSourceSelectionPlain,
allSelection: AllDatasetSelection
) => {
if (dataSourceSelection.selectionType === 'all') {
return AllDatasetSelection.create();
return allSelection;
} else if (dataSourceSelection.selectionType === 'single') {
return SingleDatasetSelection.fromSelection(dataSourceSelection.selection);
} else if (dataSourceSelection.selectionType === 'dataView') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export class Dataset {
return new Dataset({ ...dataset, title: datasetTitle }, parentIntegration);
}

public static createAllLogsDataset() {
public static createAllLogsDataset({ indices }: { indices: string }) {
return new Dataset({
name: 'logs-*-*' as IndexPattern,
name: indices as IndexPattern,
title: 'All logs',
iconType: 'pagesSelect',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const KibanaReactContext = createKibanaReactContext(coreMock);

const DataSourceSelectorTemplate: Story<DataSourceSelectorProps> = (args) => {
const [dataSourceSelection, setDataSourceSelection] = useState<DataSourceSelection>(() =>
AllDatasetSelection.create()
AllDatasetSelection.create({ indices: 'logs-*-*' })
);

const [search, setSearch] = useState<DataSourceSelectorSearchParams>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { DataViewsFilter } from './sub_components/data_view_filter';
export function DataSourceSelector({
datasets,
dataSourceSelection,
allSelection,
datasetsError,
dataViews,
dataViewCount,
Expand Down Expand Up @@ -307,7 +308,11 @@ export function DataSourceSelector({
/>
<EuiHorizontalRule margin="none" />
<SelectorFooter>
<ShowAllLogsButton isSelected={isAllMode} onClick={selectAllLogs} />
<ShowAllLogsButton
isSelected={isAllMode}
onClick={selectAllLogs}
allSelection={allSelection}
/>
{isEsqlEnabled && <ESQLButton {...discoverEsqlUrlProps} />}
</SelectorFooter>
</SelectorPopover>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { AllDatasetSelection } from '../../../../common/data_source_selection';
import { DEFAULT_ALL_SELECTION } from '../../../state_machines/logs_explorer_controller';
import { HashedCache } from '../../../../common/hashed_cache';
import { INTEGRATIONS_PANEL_ID, INTEGRATIONS_TAB_ID } from '../constants';
import { DataSourceSelectorSearchParams } from '../types';
Expand All @@ -17,7 +17,8 @@ export const defaultSearch: DataSourceSelectorSearchParams = {
};

export const DEFAULT_CONTEXT: DefaultDataSourceSelectorContext = {
selection: AllDatasetSelection.create(),
selection: DEFAULT_ALL_SELECTION,
allSelection: DEFAULT_ALL_SELECTION,
searchCache: new HashedCache(),
panelId: INTEGRATIONS_PANEL_ID,
tabId: INTEGRATIONS_TAB_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { actions, assign, createMachine, raise } from 'xstate';
import {
AllDatasetSelection,
DataViewSelection,
isAllDatasetSelection,
isDataViewSelection,
Expand Down Expand Up @@ -233,7 +232,7 @@ export const createPureDataSourceSelectorStateMachine = (
return {};
}),
storeAllSelection: assign((_context) => ({
selection: AllDatasetSelection.create(),
selection: _context.allSelection,
})),
storeSingleSelection: assign((_context, event) =>
event.type === 'SELECT_DATASET'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { DataViewDescriptor } from '../../../../common/data_views/models/data_view_descriptor';
import { FilterDataViews, SearchDataViews } from '../../../hooks/use_data_views';
import {
AllDatasetSelection,
DataSourceSelection,
DataSourceSelectionChangeHandler,
} from '../../../../common/data_source_selection';
Expand All @@ -23,6 +24,7 @@ import { DataViewsFilterParams } from '../../../state_machines/data_views';

export interface DefaultDataSourceSelectorContext {
selection: DataSourceSelection;
allSelection: AllDatasetSelection;
tabId: TabId;
panelId: PanelId;
searchCache: IHashedCache<PanelId | TabId, DataSourceSelectorSearchParams>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import {
EuiFlexGroupProps,
} from '@elastic/eui';
import { getRouterLinkProps } from '@kbn/router-utils';
import { AllDatasetSelection } from '../../../../common';
import { DiscoverEsqlUrlProps } from '../../../hooks/use_esql';
import { createAllLogsItem } from '../utils';
import { showAllLogsLabel, tryEsql } from '../constants';

interface ShowAllLogsProps {
isSelected: boolean;
onClick(): void;
allSelection: AllDatasetSelection;
}

export const SelectorFooter = (props: EuiFlexGroupProps) => {
Expand All @@ -32,8 +34,8 @@ export const SelectorFooter = (props: EuiFlexGroupProps) => {
);
};

export const ShowAllLogsButton = ({ isSelected, onClick }: ShowAllLogsProps) => {
const allLogs = createAllLogsItem();
export const ShowAllLogsButton = ({ isSelected, onClick, allSelection }: ShowAllLogsProps) => {
const allLogs = createAllLogsItem(allSelection);

return (
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EuiContextMenuPanelId } from '@elastic/eui/src/components/context_menu/
import type {
DataSourceSelectionChangeHandler,
DataSourceSelection,
AllDatasetSelection,
} from '../../../common/data_source_selection';
import { SortOrder } from '../../../common/latest';
import { Dataset, Integration, IntegrationId } from '../../../common/datasets';
Expand Down Expand Up @@ -39,6 +40,8 @@ import { DataViewsFilterParams } from '../../state_machines/data_views';
export interface DataSourceSelectorProps {
/* The generic data stream list */
datasets: Dataset[] | null;
/* Class to represent the current "All logs" selection */
allSelection: AllDatasetSelection;
/* Any error occurred to show when the user preview the generic data streams */
datasetsError: Error | null;
/* The current selection instance */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import React, { RefCallback } from 'react';
import { EuiContextMenuPanelDescriptor, EuiContextMenuPanelItemDescriptor } from '@elastic/eui';
import { PackageIcon } from '@kbn/fleet-plugin/public';
import { Dataset, Integration } from '../../../common/datasets';
import { AllDatasetSelection } from '../../../common';
import { Integration } from '../../../common/datasets';
import {
DATA_SOURCE_SELECTOR_WIDTH,
noDatasetsDescriptionLabel,
Expand Down Expand Up @@ -78,12 +79,11 @@ export const buildIntegrationsTree = ({
);
};

export const createAllLogsItem = () => {
const allLogs = Dataset.createAllLogsDataset();
export const createAllLogsItem = (allSelection: AllDatasetSelection) => {
return {
'data-test-subj': 'dataSourceSelectorShowAllLogs',
iconType: allLogs.iconType,
name: allLogs.title,
iconType: allSelection.selection.dataset.iconType,
name: allSelection.selection.dataset.title,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import { getDevToolsOptions } from '@kbn/xstate-utils';
import equal from 'fast-deep-equal';
import { distinctUntilChanged, from, map, shareReplay, Subject } from 'rxjs';
import { interpret } from 'xstate';
import { AllDatasetSelection } from '../../common';
import { DatasetsService } from '../services/datasets';
import { createLogsExplorerControllerStateMachine } from '../state_machines/logs_explorer_controller';
import {
createLogsExplorerControllerStateMachine,
DEFAULT_CONTEXT,
} from '../state_machines/logs_explorer_controller';
import { LogsExplorerStartDeps } from '../types';
import { LogsExplorerCustomizations } from '../customizations/types';
import { createDataServiceProxy } from './custom_data_service';
Expand All @@ -33,7 +37,7 @@ interface Dependencies {
plugins: LogsExplorerStartDeps;
}

type InitialState = LogsExplorerPublicStateUpdate;
type InitialState = LogsExplorerPublicStateUpdate & { allSelection?: AllDatasetSelection };
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intersection here so that LogsExplorerPublicStateUpdate maintains it's tidy 1:1 with public state.


export const createLogsExplorerControllerFactory =
({ core, plugins }: Dependencies) =>
Expand Down Expand Up @@ -66,15 +70,19 @@ export const createLogsExplorerControllerFactory =
timefilter: customData.query.timefilter.timefilter,
urlStateStorage: customMemoryUrlStateStorage,
};
const allSelection = initialState?.allSelection ?? DEFAULT_CONTEXT.allSelection;

const initialContext = getContextFromPublicState(initialState ?? {});
const initialContext = getContextFromPublicState(initialState ?? {}, allSelection);
const publicEvents$ = new Subject<LogsExplorerPublicEvent>();

const machine = createLogsExplorerControllerStateMachine({
datasetsClient,
dataViews,
events: customizations.events,
initialContext,
initialContext: {
...initialContext,
allSelection,
},
query: discoverServices.data.query,
toasts: core.notifications.toasts,
uiSettings: customUiSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import {
AllDatasetSelection,
availableControlsPanels,
controlPanelConfigs,
ControlPanels,
Expand Down Expand Up @@ -37,7 +38,8 @@ export const getPublicStateFromContext = (
};

export const getContextFromPublicState = (
publicState: LogsExplorerPublicStateUpdate
publicState: LogsExplorerPublicStateUpdate,
allSelection: AllDatasetSelection
): LogsExplorerControllerContext => ({
...DEFAULT_CONTEXT,
chart: {
Expand All @@ -47,7 +49,7 @@ export const getContextFromPublicState = (
controlPanels: getControlPanelsFromPublicControlsState(publicState.controls),
dataSourceSelection:
publicState.dataSourceSelection != null
? hydrateDataSourceSelection(publicState.dataSourceSelection)
? hydrateDataSourceSelection(publicState.dataSourceSelection, allSelection)
: DEFAULT_CONTEXT.dataSourceSelection,
grid: {
...DEFAULT_CONTEXT.grid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ interface CustomDataSourceSelectorProps {
}

export const CustomDataSourceSelector = withProviders(({ logsExplorerControllerStateService }) => {
const { dataSourceSelection, handleDataSourceSelectionChange } = useDataSourceSelection(
logsExplorerControllerStateService
);
const { dataSourceSelection, handleDataSourceSelectionChange, allSelection } =
useDataSourceSelection(logsExplorerControllerStateService);

const {
error: integrationsError,
Expand Down Expand Up @@ -70,6 +69,7 @@ export const CustomDataSourceSelector = withProviders(({ logsExplorerControllerS
<DataSourceSelector
datasets={datasets}
dataSourceSelection={dataSourceSelection}
allSelection={allSelection}
datasetsError={datasetsError}
dataViews={dataViews}
dataViewCount={dataViewCount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const useDataSourceSelection = (
const dataSourceSelection = useSelector(logsExplorerControllerStateService, (state) => {
return state.context.dataSourceSelection;
});
const allSelection = useSelector(logsExplorerControllerStateService, (state) => {
return state.context.allSelection;
});

const handleDataSourceSelectionChange: DataSourceSelectionChangeHandler = useCallback(
(data) => {
Expand All @@ -24,5 +27,5 @@ export const useDataSourceSelection = (
[logsExplorerControllerStateService]
);

return { dataSourceSelection, handleDataSourceSelectionChange };
return { dataSourceSelection, allSelection, handleDataSourceSelectionChange };
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type {
LogsExplorerCustomizationEvents,
} from './customizations/types';
export type { LogsExplorerControllerContext } from './state_machines/logs_explorer_controller';
export { DEFAULT_ALL_SELECTION } from './state_machines/logs_explorer_controller/src/default_all_selection';
export type { LogsExplorerPluginSetup, LogsExplorerPluginStart } from './types';
export {
getDiscoverColumnsFromDisplayOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { AllDatasetSelection } from '../../../../common';

export const DEFAULT_ALL_SELECTION = AllDatasetSelection.create({ indices: 'logs-*-*' });
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in it's own file to make sure there aren't bundle size explosions from defaults.ts.

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
DEFAULT_ROWS_PER_PAGE,
LOG_LEVEL_FIELD,
} from '../../../../common/constants';
import { AllDatasetSelection } from '../../../../common/data_source_selection';
import { DefaultLogsExplorerControllerState } from './types';
import { DEFAULT_ALL_SELECTION } from './default_all_selection';

export const DEFAULT_CONTEXT: DefaultLogsExplorerControllerState = {
dataSourceSelection: AllDatasetSelection.create(),
dataSourceSelection: DEFAULT_ALL_SELECTION,
allSelection: DEFAULT_ALL_SELECTION,
grid: {
columns: DEFAULT_COLUMNS,
rows: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
*/

export * from './defaults';
export * from './default_all_selection';
export * from './state_machine';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { OBSERVABILITY_LOGS_EXPLORER_ALLOWED_DATA_VIEWS_ID } from '@kbn/manageme
import type { LogsExplorerCustomizations, LogsExplorerPublicEvent } from '../../../controller';
import { ControlPanelRT } from '../../../../common/control_panels';
import {
AllDatasetSelection,
isDataSourceSelection,
isDataViewSelection,
} from '../../../../common/data_source_selection';
Expand Down Expand Up @@ -271,7 +270,7 @@ export const createPureLogsExplorerControllerStateMachine = (
{
actions: {
storeDefaultSelection: actions.assign((_context) => ({
dataSourceSelection: AllDatasetSelection.create(),
dataSourceSelection: _context.allSelection,
})),
storeDataSourceSelection: actions.assign((_context, event) =>
'data' in event && isDataSourceSelection(event.data)
Expand Down
Loading