-
Notifications
You must be signed in to change notification settings - Fork 58
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
[Log Explorer] Remove top level tabs #970
Changes from all commits
7b4ca0d
79c1551
f2d44f4
111ff62
1e93d3c
0747ad9
d63d776
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,36 +3,21 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
|
||
import { | ||
EuiIcon, | ||
EuiTabbedContent, | ||
EuiTabbedContentTab, | ||
EuiText, | ||
htmlIdGenerator, | ||
} from '@elastic/eui'; | ||
import $ from 'jquery'; | ||
import { isEmpty, map } from 'lodash'; | ||
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { isEmpty } from 'lodash'; | ||
import React, { useContext, useEffect, useRef, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { LogExplorerRouterContext } from '..'; | ||
import { | ||
APP_ANALYTICS_TAB_ID_REGEX, | ||
CREATE_TAB_PARAM_KEY, | ||
NEW_TAB, | ||
REDIRECT_TAB, | ||
SAVED_OBJECT_ID, | ||
TAB_CHART_ID, | ||
TAB_EVENT_ID, | ||
TAB_ID_TXT_PFX, | ||
TAB_TITLE, | ||
} from '../../../../common/constants/explorer'; | ||
import { ILogExplorerProps } from '../../../../common/types/explorer'; | ||
import { initializeTabData, removeTabData } from '../../application_analytics/helpers/utils'; | ||
import { selectQueryResult } from '../redux/slices/query_result_slice'; | ||
import { selectQueries } from '../redux/slices/query_slice'; | ||
import { selectQueryTabs, setSelectedQueryTab } from '../redux/slices/query_tab_slice'; | ||
import { selectQueryTabs } from '../redux/slices/query_tab_slice'; | ||
import { Explorer } from './explorer'; | ||
|
||
const searchBarConfigs = { | ||
|
@@ -60,11 +45,9 @@ export const LogExplorer = ({ | |
}: ILogExplorerProps) => { | ||
const history = useHistory(); | ||
const routerContext = useContext(LogExplorerRouterContext); | ||
const dispatch = useDispatch(); | ||
const tabIds = useSelector(selectQueryTabs).queryTabIds.filter( | ||
(tabid: string) => !tabid.match(APP_ANALYTICS_TAB_ID_REGEX) | ||
); | ||
const tabNames = useSelector(selectQueryTabs).tabNames; | ||
const queries = useSelector(selectQueries); | ||
const curSelectedTabId = useSelector(selectQueryTabs).selectedQueryTab; | ||
const explorerData = useSelector(selectQueryResult); | ||
|
@@ -79,68 +62,12 @@ export const LogExplorer = ({ | |
|
||
const [tabCreatedTypes, setTabCreatedTypes] = useState({}); | ||
|
||
// Append add-new-tab link to the end of the tab list, and remove it once tabs state changes | ||
useEffect(() => { | ||
const newLink = $( | ||
'<a class="linkNewTag" data-test-subj="eventExplorer__addNewTab">+ Add new</a>' | ||
).on('click', () => { | ||
addNewTab(NEW_TAB); | ||
}); | ||
$('.queryTabs > .euiTabs').append(newLink); | ||
return () => { | ||
$('.queryTabs > .euiTabs .linkNewTag').remove(); | ||
}; | ||
}, [tabIds]); | ||
|
||
const handleTabClick = (selectedTab: EuiTabbedContentTab) => { | ||
history.replace(`/explorer/${queryRef.current![selectedTab.id][SAVED_OBJECT_ID] || ''}`); | ||
dispatch(setSelectedQueryTab({ tabId: selectedTab.id })); | ||
}; | ||
|
||
const handleTabClose = (TabIdToBeClosed: string) => { | ||
if (tabIds.length === 1) { | ||
setToast('Cannot close last tab.', 'danger'); | ||
return; | ||
} | ||
|
||
const index: number = tabIds.indexOf(TabIdToBeClosed); | ||
const curSelectedTab = curSelectedTabIdRef.current; | ||
let newIdToFocus = ''; | ||
if (TabIdToBeClosed === curSelectedTab) { | ||
if (index === 0) { | ||
newIdToFocus = tabIds[index + 1]; | ||
} else if (index > 0) { | ||
newIdToFocus = tabIds[index - 1]; | ||
} | ||
} | ||
removeTabData(dispatch, TabIdToBeClosed, newIdToFocus); | ||
}; | ||
|
||
const addNewTab = async (where: string) => { | ||
// get a new tabId | ||
const tabId = htmlIdGenerator(TAB_ID_TXT_PFX)(); | ||
|
||
// create a new tab | ||
await initializeTabData(dispatch, tabId, where); | ||
|
||
setTabCreatedTypes((staleState) => { | ||
return { | ||
...staleState, | ||
[tabId]: where, | ||
}; | ||
}); | ||
|
||
return tabId; | ||
}; | ||
|
||
const dispatchSavedObjectId = async () => { | ||
const emptyTabId = getExistingEmptyTab({ | ||
return getExistingEmptyTab({ | ||
tabIds: tabIdsRef.current, | ||
queries: queryRef.current, | ||
explorerData: explorerDataRef.current, | ||
}); | ||
const newTabId = emptyTabId ? emptyTabId : await addNewTab(REDIRECT_TAB); | ||
return newTabId; | ||
}; | ||
|
||
useEffect(() => { | ||
|
@@ -150,7 +77,6 @@ export const LogExplorer = ({ | |
if (routerContext && routerContext.searchParams.has(CREATE_TAB_PARAM_KEY)) { | ||
// need to wait for current redux event loop to finish | ||
setImmediate(() => { | ||
addNewTab(NEW_TAB); | ||
routerContext.searchParams.delete(CREATE_TAB_PARAM_KEY); | ||
routerContext.routerProps.history.replace({ | ||
search: routerContext.searchParams.toString(), | ||
|
@@ -159,78 +85,24 @@ export const LogExplorer = ({ | |
} | ||
}, []); | ||
|
||
function getQueryTab({ | ||
tabTitle, | ||
tabId, | ||
handlesTabClose, | ||
}: { | ||
tabTitle: string; | ||
tabId: string; | ||
handlesTabClose: (TabIdToBeClosed: string) => void; | ||
}) { | ||
return { | ||
id: tabId, | ||
name: ( | ||
<> | ||
<EuiText size="s" textAlign="left" color="default"> | ||
<span className="tab-title">{tabTitle}</span> | ||
<EuiIcon | ||
type="cross" | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
handlesTabClose(tabId); | ||
}} | ||
data-test-subj="eventExplorer__tabClose" | ||
/> | ||
</EuiText> | ||
</> | ||
), | ||
content: ( | ||
<> | ||
<Explorer | ||
key={`explorer_${tabId}`} | ||
pplService={pplService} | ||
dslService={dslService} | ||
tabId={tabId} | ||
savedObjects={savedObjects} | ||
timestampUtils={timestampUtils} | ||
setToast={setToast} | ||
history={history} | ||
notifications={notifications} | ||
savedObjectId={savedObjectId} | ||
tabCreatedTypes={tabCreatedTypes} | ||
curSelectedTabId={curSelectedTabIdRef} | ||
http={http} | ||
searchBarConfigs={searchBarConfigs} | ||
queryManager={queryManager} | ||
/> | ||
</> | ||
), | ||
}; | ||
} | ||
|
||
const memorizedTabs = useMemo(() => { | ||
const res = map(tabIds, (tabId) => { | ||
return getQueryTab({ | ||
tabTitle: tabNames[tabId] || TAB_TITLE, | ||
tabId, | ||
handlesTabClose: handleTabClose, | ||
}); | ||
}); | ||
|
||
return res; | ||
}, [tabIds, tabNames, tabCreatedTypes]); | ||
|
||
return ( | ||
<> | ||
<EuiTabbedContent | ||
id="queryTabs" | ||
className="queryTabs" | ||
tabs={memorizedTabs} | ||
selectedTab={memorizedTabs.find((tab) => tab.id === curSelectedTabId)} | ||
onTabClick={(selectedTab: EuiTabbedContentTab) => handleTabClick(selectedTab)} | ||
data-test-subj="eventExplorer__topLevelTabbing" | ||
size="s" | ||
<Explorer | ||
key={`explorer_${tabIds[0]}`} | ||
pplService={pplService} | ||
dslService={dslService} | ||
tabId={tabIds[0]} | ||
savedObjects={savedObjects} | ||
timestampUtils={timestampUtils} | ||
setToast={setToast} | ||
history={history} | ||
notifications={notifications} | ||
savedObjectId={savedObjectId} | ||
tabCreatedTypes={tabCreatedTypes} | ||
curSelectedTabId={curSelectedTabIdRef} | ||
http={http} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need http to be passed here can we use import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied the entire component over for tab changes. But to your point, I've created the issue for tracking this as I saw there are around 7 - 8 references in explorer where changes required for this are kinda out of the scope of this PR. Later we can have campaign for this as I feel we need to also refactor some of the components to not |
||
searchBarConfigs={searchBarConfigs} | ||
queryManager={queryManager} | ||
/> | ||
</> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
${observabilityLogsID}
instead ofobservability-logs
?