Skip to content

Commit

Permalink
[Refactoring] Explorer sidebar refactoring (opensearch-project#326) (o…
Browse files Browse the repository at this point in the history
…pensearch-project#328)

* move fields toggle from explorer to under sidebar

Signed-off-by: Eric Wei <[email protected]>

* fix the bug when switching index seeing fields from old index

Signed-off-by: Eric Wei <[email protected]>

* update tests/snapshots

Signed-off-by: Eric Wei <[email protected]>

---------

Signed-off-by: Eric Wei <[email protected]>
(cherry picked from commit 13eccbb)

Co-authored-by: Eric Wei <[email protected]>
(cherry picked from commit bc71ed3)
  • Loading branch information
opensearch-trigger-bot[bot] authored and A9 Swift Project User committed Mar 25, 2023
1 parent c670bdb commit dd80cf3
Show file tree
Hide file tree
Showing 7 changed files with 7,386 additions and 7,338 deletions.
4 changes: 2 additions & 2 deletions auto_sync_commit_metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"last_github_commit": "8ad82c9836a48922e2729a36e9108b0e88a4839c",
"last_gitfarm_commit": "99622218593b8104c4cd70529f21d3d446f956b5"
"last_github_commit": "bc71ed3f402d8dfa4fa804220346d2b79e6b7561",
"last_gitfarm_commit": "79aecb05294c689bbabafa8428c643d8123d0afc"
}
50 changes: 4 additions & 46 deletions public/components/event_analytics/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@osd/i18n/react';
import classNames from 'classnames';
import { cloneDeep, has, isEmpty, isEqual, reduce } from 'lodash';
import { has, isEmpty, isEqual, reduce } from 'lodash';
import React, { ReactElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { batch, useDispatch, useSelector } from 'react-redux';
import {
AVAILABLE_FIELDS,
DATE_PICKER_FORMAT,
DEFAULT_AVAILABILITY_QUERY,
EVENT_ANALYTICS_DOCUMENTATION_URL,
Expand All @@ -33,7 +32,6 @@ import {
PATTERNS_EXTRACTOR_REGEX,
PATTERNS_REGEX,
PATTERN_REGEX,
PPL_DEFAULT_PATTERN_REGEX_FILETER,
RAW_QUERY,
SAVED_OBJECT_ID,
SAVED_OBJECT_TYPE,
Expand Down Expand Up @@ -74,8 +72,7 @@ import { Search } from '../../common/search/search';
import { getVizContainerProps } from '../../visualizations/charts/helpers';
import { TabContext, useFetchEvents, useFetchPatterns, useFetchVisualizations } from '../hooks';
import { selectCountDistribution } from '../redux/slices/count_distribution_slice';
import { selectFields, sortFields, updateFields } from '../redux/slices/field_slice';
import { selectPatterns } from '../redux/slices/patterns_slice';
import { selectFields, updateFields } from '../redux/slices/field_slice';
import { selectQueryResult } from '../redux/slices/query_result_slice';
import { changeDateRange, changeQuery, selectQueries } from '../redux/slices/query_slice';
import { updateTabName } from '../redux/slices/query_tab_slice';
Expand Down Expand Up @@ -129,11 +126,11 @@ export const Explorer = ({
}: IExplorerProps) => {
const dispatch = useDispatch();
const requestParams = { tabId };
const { getLiveTail, getEvents, getAvailableFields, isEventsLoading } = useFetchEvents({
const { getLiveTail, getEvents } = useFetchEvents({
pplService,
requestParams,
});
const { getVisualizations, getCountVisualizations, isVisLoading } = useFetchVisualizations({
const { getCountVisualizations } = useFetchVisualizations({
pplService,
requestParams,
});
Expand Down Expand Up @@ -512,11 +509,6 @@ export const Explorer = ({
}
}, [savedObjectId]);

const handleAddField = (field: IField) => toggleFields(field, AVAILABLE_FIELDS, SELECTED_FIELDS);

const handleRemoveField = (field: IField) =>
toggleFields(field, SELECTED_FIELDS, AVAILABLE_FIELDS);

const handleTimePickerChange = async (timeRange: string[]) => {
if (appLogEvents) {
setStartTime(timeRange[0]);
Expand Down Expand Up @@ -564,36 +556,6 @@ export const Explorer = ({
}
};

/**
* Toggle fields between selected and unselected sets
* @param field field to be toggled
* @param FieldSetToRemove set where this field to be removed from
* @param FieldSetToAdd set where this field to be added
*/
const toggleFields = (field: IField, FieldSetToRemove: string, FieldSetToAdd: string) => {
const nextFields = cloneDeep(explorerFields);
const thisFieldSet = nextFields[FieldSetToRemove];
const nextFieldSet = thisFieldSet.filter((fd: IField) => fd.name !== field.name);
nextFields[FieldSetToRemove] = nextFieldSet;
nextFields[FieldSetToAdd].push(field);
batch(() => {
dispatch(
updateFields({
tabId,
data: {
...nextFields,
},
})
);
dispatch(
sortFields({
tabId,
data: [FieldSetToAdd],
})
);
});
};

const sidebarClassName = classNames({
closed: isSidebarClosed,
});
Expand Down Expand Up @@ -692,8 +654,6 @@ export const Explorer = ({
selectedPattern={query[SELECTED_PATTERN_FIELD]}
handleOverrideTimestamp={handleOverrideTimestamp}
handleOverridePattern={handleOverridePattern}
handleAddField={(field: IField) => handleAddField(field)}
handleRemoveField={(field: IField) => handleRemoveField(field)}
isOverridingTimestamp={isOverridingTimestamp}
isOverridingPattern={isOverridingPattern}
isFieldToggleButtonDisabled={
Expand Down Expand Up @@ -897,8 +857,6 @@ export const Explorer = ({
explorerFields={explorerFields}
explorerVis={explorerVisualizations}
explorerData={explorerData}
handleAddField={handleAddField}
handleRemoveField={handleRemoveField}
visualizations={visualizations}
handleOverrideTimestamp={handleOverrideTimestamp}
callback={callbackForConfig}
Expand Down
Loading

0 comments on commit dd80cf3

Please sign in to comment.