-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fleet] Only show agent dashboard links if there is more than one non-server agent and if the dashboards exist #164469
Merged
hop-dev
merged 4 commits into
elastic:main
from
hop-dev:161827-fix-ingest-dashboard-links
Aug 23, 2023
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bf82ccd
Only show ingest dashboards if one non fleet server agent and the das…
hop-dev 4370add
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine f8fe6fe
fix types
hop-dev 562799d
Merge branch 'main' into 161827-fix-ingest-dashboard-links
juliaElastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,37 @@ | |
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
|
||
import { DASHBOARD_LOCATORS_IDS } from '../../../../../../../common/constants'; | ||
|
||
import { useDashboardLocator } from '../../../../hooks'; | ||
import { useDashboardLocator, useStartServices } from '../../../../hooks'; | ||
|
||
const useDashboardExists = (dashboardId: string) => { | ||
const [dashboardExists, setDashboardExists] = React.useState<boolean>(false); | ||
const [loading, setLoading] = React.useState<boolean>(true); | ||
const { dashboard: dashboardPlugin } = useStartServices(); | ||
|
||
useEffect(() => { | ||
const fetchDashboard = async () => { | ||
try { | ||
const findDashboardsService = await dashboardPlugin.findDashboardsService(); | ||
const [dashboard] = await findDashboardsService.findByIds([dashboardId]); | ||
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. Good idea to use the dashboard service! |
||
setLoading(false); | ||
setDashboardExists(dashboard?.status === 'success'); | ||
} catch (e) { | ||
setLoading(false); | ||
setDashboardExists(false); | ||
} | ||
}; | ||
|
||
fetchDashboard(); | ||
}, [dashboardId, dashboardPlugin]); | ||
|
||
return { dashboardExists, loading }; | ||
}; | ||
|
||
export const DashboardsButtons: React.FunctionComponent = () => { | ||
const dashboardLocator = useDashboardLocator(); | ||
|
@@ -20,6 +44,14 @@ export const DashboardsButtons: React.FunctionComponent = () => { | |
return dashboardLocator?.getRedirectUrl({ dashboardId }) || ''; | ||
}; | ||
|
||
const { dashboardExists, loading: dashboardLoading } = useDashboardExists( | ||
DASHBOARD_LOCATORS_IDS.ELASTIC_AGENT_OVERVIEW | ||
); | ||
|
||
if (dashboardLoading || !dashboardExists) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<EuiFlexGroup gutterSize="s" justifyContent="flexStart"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ import { | |
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import styled from 'styled-components'; | ||
|
||
import { useIsFirstTimeAgentUserQuery } from '../../../../../integrations/sections/epm/screens/detail/hooks'; | ||
|
||
import type { Agent, AgentPolicy } from '../../../../types'; | ||
import { SearchBar } from '../../../../components'; | ||
import { AGENTS_INDEX, AGENTS_PREFIX } from '../../../../constants'; | ||
|
@@ -94,6 +96,8 @@ export const SearchAndFilterBar: React.FunctionComponent<SearchAndFilterBarProps | |
}) => { | ||
const { euiTheme } = useEuiTheme(); | ||
const { isFleetServerStandalone } = useFleetServerStandalone(); | ||
const { isFirstTimeAgentUser, isLoading: isFirstTimeAgentUserLoading } = | ||
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. isFirstTimeAgentUser checks if the user has at least one non-fleet-server agent |
||
useIsFirstTimeAgentUserQuery(); | ||
const showAddFleetServerBtn = !isFleetServerStandalone; | ||
|
||
// Policies state for filtering | ||
|
@@ -126,7 +130,9 @@ export const SearchAndFilterBar: React.FunctionComponent<SearchAndFilterBarProps | |
<EuiFlexGroup direction="column"> | ||
{/* Top Buttons and Links */} | ||
<EuiFlexGroup> | ||
<EuiFlexItem>{totalAgents > 0 && <DashboardsButtons />}</EuiFlexItem> | ||
<EuiFlexItem> | ||
{!isFirstTimeAgentUserLoading && !isFirstTimeAgentUser && <DashboardsButtons />} | ||
</EuiFlexItem> | ||
<EuiFlexGroup gutterSize="s" justifyContent="flexEnd"> | ||
<EuiFlexItem grow={false}> | ||
<AgentActivityButton | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
as this hook is only used here I kept it in the same file, happy to move it to its own file?
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.
I think it can stay in this file and can be moved if we need to reuse it elsewhere