[Logs+] Set default Logs Explorer columns (#162678)

## 📓 Summary

Closes #160422 

This work sets the columns for the logs explorer to the default
`@timestamp` field and to `message`, giving priority to existing columns
set by the user and applying those when accessing the log explorer with
the default columns.


39c6053b-30b8-4a29-80e4-80aa5718b072

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
This commit is contained in:
Marco Antonio Ghiani 2023-08-02 14:13:14 +02:00 committed by GitHub
parent 4dadcbb911
commit e198b5ccf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 6 deletions

View file

@ -6,3 +6,6 @@
*/
export const LOG_EXPLORER_PROFILE_ID = 'log-explorer';
// Fields constants
export const MESSAGE_FIELD = 'message';

View file

@ -27,6 +27,7 @@ import {
listenUrlChange,
subscribeControlGroup,
updateControlPanels,
updateStateContainer,
} from './url_state_storage_service';
export const createPureLogExplorerProfileStateMachine = (
@ -72,9 +73,20 @@ export const createPureLogExplorerProfileStateMachine = (
invoke: {
src: 'initializeControlPanels',
onDone: {
target: 'initialized',
target: 'initializingStateContainer',
actions: ['storeControlPanels'],
},
onError: {
target: 'initializingStateContainer',
},
},
},
initializingStateContainer: {
invoke: {
src: 'updateStateContainer',
onDone: {
target: 'initialized',
},
onError: {
target: 'initialized',
},
@ -104,6 +116,18 @@ export const createPureLogExplorerProfileStateMachine = (
updatingDataView: {
invoke: {
src: 'createDataView',
onDone: {
target: 'updatingStateContainer',
},
onError: {
target: 'updatingStateContainer',
actions: ['notifyCreateDataViewFailed'],
},
},
},
updatingStateContainer: {
invoke: {
src: 'updateStateContainer',
onDone: {
target: 'idle',
actions: ['notifyDataViewUpdate'],
@ -215,6 +239,7 @@ export const createLogExplorerProfileStateMachine = ({
listenUrlChange: listenUrlChange({ stateContainer }),
subscribeControlGroup: subscribeControlGroup({ stateContainer }),
updateControlPanels: updateControlPanels({ stateContainer }),
updateStateContainer: updateStateContainer({ stateContainer }),
},
});

View file

@ -41,17 +41,25 @@ export type LogExplorerProfileTypeState =
value: 'initializingControlPanels';
context: WithDatasetSelection;
}
| {
value: 'initializingStateContainer';
context: WithDatasetSelection & WithControlPanels;
}
| {
value: 'initialized';
context: WithDatasetSelection & WithControlPanels;
}
| {
value: 'initialized.idle';
context: WithDatasetSelection & WithControlPanelGroupAPI & WithControlPanels;
value: 'initialized.datasetSelection.idle';
context: WithDatasetSelection & WithControlPanels;
}
| {
value: 'initialized.updatingDataView';
context: WithDatasetSelection;
value: 'initialized.datasetSelection.updatingDataView';
context: WithDatasetSelection & WithControlPanels;
}
| {
value: 'initialized.datasetSelection.updatingStateContainer';
context: WithDatasetSelection & WithControlPanels;
}
| {
value: 'initialized.controlGroups.uninitialized';

View file

@ -9,6 +9,7 @@ import { pick, mapValues } from 'lodash';
import deepEqual from 'fast-deep-equal';
import { DiscoverStateContainer } from '@kbn/discover-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import { MESSAGE_FIELD } from '../../../../common/constants';
import {
AllDatasetSelection,
decodeDatasetSelectionId,
@ -169,6 +170,24 @@ export const updateControlPanels =
return controlPanelsWithId;
};
export const updateStateContainer =
({
stateContainer,
}: LogExplorerProfileUrlStateDependencies): InvokeCreator<
LogExplorerProfileContext,
LogExplorerProfileEvent
> =>
async () => {
const { columns } = stateContainer.appState.getState();
const shouldSetDefaultColumns =
stateContainer.appState.isEmptyURL() || !columns || columns.length === 0;
if (shouldSetDefaultColumns) {
stateContainer.appState.update({ columns: [MESSAGE_FIELD] }, true);
}
};
/**
* Utils
*/
@ -185,7 +204,13 @@ const constructControlPanelsWithDataViewId = (
const controlsPanelsWithId = mergeDefaultPanelsWithUrlConfig(dataView, validatedControlPanels!);
stateContainer.stateStorage.set(CONTROL_PANELS_URL_KEY, cleanControlPanels(controlsPanelsWithId));
if (!deepEqual(controlsPanelsWithId, stateContainer.stateStorage.get(CONTROL_PANELS_URL_KEY))) {
stateContainer.stateStorage.set(
CONTROL_PANELS_URL_KEY,
cleanControlPanels(controlsPanelsWithId),
{ replace: true }
);
}
return controlsPanelsWithId;
};