Skip to content

Commit

Permalink
[8.10] [Fleet] Only show agent dashboard links if there is more than …
Browse files Browse the repository at this point in the history
…one non-server agent and if the dashboards exist (#164469) (#164539)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Fleet] Only show agent dashboard links if there is more than one
non-server agent and if the dashboards exist
(#164469)](#164469)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Mark
Hopkin","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-23T08:53:49Z","message":"[Fleet]
Only show agent dashboard links if there is more than one non-server
agent and if the dashboards exist (#164469)\n\n## Summary\r\n\r\nCloses
#161827\r\n\r\nThese buttons were showing in cloud when there was only
the cloud agent\r\nadded:\r\n\r\n<img width=\"647\" alt=\"Screenshot
2023-08-22 at 16 18
51\"\r\nsrc=\"https://github.com/elastic/kibana/assets/3315046/baaff9b9-17fc-49b5-bad9-980f91a5ae15\">\r\n\r\nThe
ingest dashboard links will now only show if:\r\n\r\n- the user has one
agent that is not part of a policy containing fleet\r\nserver (I have
re-used an existing hook we have to check this here)\r\n- the agent
ingest metrics dashaboard exists in the current space\r\n\r\nTest
Scenarios\r\n\r\n1. Setup fleet with ONLY a fleet server connected, the
dashboard links\r\nshould not show\r\n2. Setup fleet with fleet server
and another non-fleet server agent, the\r\ndashboard links should
show\r\n3. With the same setup as test case 2, now create another space,
visit\r\nfleet in the new space, the links should not show as the
dashboards are\r\nnot installed in the current space.\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] Any UI touched in this PR is usable by keyboard only (learn
more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"805c974ed0c6f30be9153734859e0a28fa95eae1","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.11.0"],"number":164469,"url":"https://github.com/elastic/kibana/pull/164469","mergeCommit":{"message":"[Fleet]
Only show agent dashboard links if there is more than one non-server
agent and if the dashboards exist (#164469)\n\n## Summary\r\n\r\nCloses
#161827\r\n\r\nThese buttons were showing in cloud when there was only
the cloud agent\r\nadded:\r\n\r\n<img width=\"647\" alt=\"Screenshot
2023-08-22 at 16 18
51\"\r\nsrc=\"https://github.com/elastic/kibana/assets/3315046/baaff9b9-17fc-49b5-bad9-980f91a5ae15\">\r\n\r\nThe
ingest dashboard links will now only show if:\r\n\r\n- the user has one
agent that is not part of a policy containing fleet\r\nserver (I have
re-used an existing hook we have to check this here)\r\n- the agent
ingest metrics dashaboard exists in the current space\r\n\r\nTest
Scenarios\r\n\r\n1. Setup fleet with ONLY a fleet server connected, the
dashboard links\r\nshould not show\r\n2. Setup fleet with fleet server
and another non-fleet server agent, the\r\ndashboard links should
show\r\n3. With the same setup as test case 2, now create another space,
visit\r\nfleet in the new space, the links should not show as the
dashboards are\r\nnot installed in the current space.\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] Any UI touched in this PR is usable by keyboard only (learn
more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"805c974ed0c6f30be9153734859e0a28fa95eae1"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164469","number":164469,"mergeCommit":{"message":"[Fleet]
Only show agent dashboard links if there is more than one non-server
agent and if the dashboards exist (#164469)\n\n## Summary\r\n\r\nCloses
#161827\r\n\r\nThese buttons were showing in cloud when there was only
the cloud agent\r\nadded:\r\n\r\n<img width=\"647\" alt=\"Screenshot
2023-08-22 at 16 18
51\"\r\nsrc=\"https://github.com/elastic/kibana/assets/3315046/baaff9b9-17fc-49b5-bad9-980f91a5ae15\">\r\n\r\nThe
ingest dashboard links will now only show if:\r\n\r\n- the user has one
agent that is not part of a policy containing fleet\r\nserver (I have
re-used an existing hook we have to check this here)\r\n- the agent
ingest metrics dashaboard exists in the current space\r\n\r\nTest
Scenarios\r\n\r\n1. Setup fleet with ONLY a fleet server connected, the
dashboard links\r\nshould not show\r\n2. Setup fleet with fleet server
and another non-fleet server agent, the\r\ndashboard links should
show\r\n3. With the same setup as test case 2, now create another space,
visit\r\nfleet in the new space, the links should not show as the
dashboards are\r\nnot installed in the current space.\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] Any UI touched in this PR is usable by keyboard only (learn
more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"805c974ed0c6f30be9153734859e0a28fa95eae1"}}]}]
BACKPORT-->

Co-authored-by: Mark Hopkin <[email protected]>
  • Loading branch information
kibanamachine and hop-dev authored Aug 23, 2023
1 parent 7b1731d commit 92e708f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/fleet/.storybook/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { I18nProvider } from '@kbn/i18n-react';
import { CoreScopedHistory } from '@kbn/core/public';
import { getStorybookContextProvider } from '@kbn/custom-integrations-plugin/storybook';

import type { DashboardStart } from '@kbn/dashboard-plugin/public';

import { IntegrationsAppContext } from '../../public/applications/integrations/app';
import type { FleetConfigType, FleetStartServices } from '../../public/plugin';
import { ExperimentalFeaturesService } from '../../public/services';
Expand Down Expand Up @@ -76,6 +78,7 @@ export const StorybookContext: React.FC<{ storyContext?: Parameters<DecoratorFn>
languageClientsUiComponents: {},
},
customBranding: getCustomBranding(),
dashboard: {} as unknown as DashboardStart,
docLinks: getDocLinks(),
http: getHttp(),
i18n: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"taskManager",
"guidedOnboarding",
"files",
"uiActions"
"uiActions",
"dashboard"
],
"optionalPlugins": [
"features",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
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();
Expand All @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -94,6 +96,8 @@ export const SearchAndFilterBar: React.FunctionComponent<SearchAndFilterBarProps
}) => {
const { euiTheme } = useEuiTheme();
const { isFleetServerStandalone } = useFleetServerStandalone();
const { isFirstTimeAgentUser, isLoading: isFirstTimeAgentUserLoading } =
useIsFirstTimeAgentUserQuery();
const showAddFleetServerBtn = !isFleetServerStandalone;

// Policies state for filtering
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/public/mock/fleet_start_services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const createStartServices = (basePath: string = '/mock'): MockedFleetStar
...cloudStart,
...cloudSetup,
},
dashboard: {} as unknown as MockedFleetStartServices['dashboard'],
storage: new Storage(createMockStore()) as jest.Mocked<Storage>,
authz: fleetAuthzMock,
guidedOnboarding: guidedOnboardingMock.createStart(),
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import type { SendRequestResponse } from '@kbn/es-ui-shared-plugin/public';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import type { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/public';

import type { DashboardStart } from '@kbn/dashboard-plugin/public';

import { PLUGIN_ID, INTEGRATIONS_PLUGIN_ID, setupRouteService, appRoutesService } from '../common';
import { calculateAuthz, calculatePackagePrivilegesFromCapabilities } from '../common/authz';
import { parseExperimentalConfigValue } from '../common/experimental_features';
Expand Down Expand Up @@ -115,6 +117,7 @@ export interface FleetSetupDeps {
export interface FleetStartDeps {
licensing: LicensingPluginStart;
data: DataPublicPluginStart;
dashboard: DashboardStart;
dataViews: DataViewsPublicPluginStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
navigation: NavigationPublicPluginStart;
Expand All @@ -128,6 +131,7 @@ export interface FleetStartDeps {
export interface FleetStartServices extends CoreStart, Exclude<FleetStartDeps, 'cloud'> {
storage: Storage;
share: SharePluginStart;
dashboard: DashboardStart;
cloud?: CloudSetup & CloudStart;
discover?: DiscoverStart;
spaces?: SpacesPluginStart;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@
"@kbn/core-http-router-server-mocks",
"@kbn/core-application-browser",
"@kbn/core-saved-objects-base-server-internal",
"@kbn/dashboard-plugin",
]
}

0 comments on commit 92e708f

Please sign in to comment.