Skip to content

Commit

Permalink
[Logs+] Replace Monitoring usages of link-to routes (#158367)
Browse files Browse the repository at this point in the history
part of #157985

## 📝  Summary

After implementing [infra
locators](#155156) to allow
navigation to the logs UI we need to replace all usages of the old
link-to routes so that we have strongly typed navigation to the logs UI.

This PR focuses on replacing `link-to` usages in the Monitoring plugin.

## ✅  Testing

1. Navigate to Stack Monitoring
2. Choose any of the clusters from the list
3. Click logs under Elasticsearch
4. Scroll to the Recent Log Entries section 
5. click on the Logs link `Visit Logs to dive deeper.`



https://github.com/elastic/kibana/assets/11225826/b54da395-4693-4588-a8a3-6b05fdfed1c5

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
mohamedhamed-ahmed and kibanamachine authored May 25, 2023
1 parent 0b93a95 commit 43d751e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions x-pack/plugins/monitoring/public/components/logs/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { PureComponent } from 'react';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { upperFirst } from 'lodash';
import { Legacy } from '../../legacy_shims';
import { EuiBasicTable, EuiTitle, EuiSpacer, EuiText, EuiCallOut, EuiLink } from '@elastic/eui';
Expand Down Expand Up @@ -110,8 +111,6 @@ const clusterColumns = [
];

function getLogsUiLink(clusterUuid, nodeId, indexUuid) {
const base = `${Legacy.shims.getBasePath()}/app/logs/link-to/${INFRA_SOURCE_ID}/logs`;

const params = [];
if (clusterUuid) {
params.push(`elasticsearch.cluster.uuid:${clusterUuid}`);
Expand All @@ -123,11 +122,12 @@ function getLogsUiLink(clusterUuid, nodeId, indexUuid) {
params.push(`elasticsearch.index.name:${indexUuid}`);
}

if (params.length === 0) {
return base;
}
const base = Legacy.shims.infra.locators.logsLocator.getRedirectUrl({
logView: { logViewId: INFRA_SOURCE_ID, type: 'log-view-reference' },
...(params.length ? { filter: params.join(' and ') } : {}),
});

return `${base}?filter=${params.join(' and ')}`;
return base;
}

export class Logs extends PureComponent {
Expand Down Expand Up @@ -158,7 +158,7 @@ export class Logs extends PureComponent {
}

renderCallout() {
const uiCapabilities = Legacy.shims.capabilities;
const { capabilities: uiCapabilities, infra, kibanaServices } = Legacy.shims;
const show = uiCapabilities.logs && uiCapabilities.logs.show;
const {
logs: { enabled },
Expand All @@ -170,15 +170,15 @@ export class Logs extends PureComponent {
return null;
}

return (
return infra ? (
<EuiCallOut
size="m"
title={i18n.translate('xpack.monitoring.logs.listing.calloutTitle', {
defaultMessage: 'Want to see more log entries?',
})}
iconType="logsApp"
>
<p>
<RedirectAppLinks coreStart={kibanaServices}>
<FormattedMessage
id="xpack.monitoring.logs.listing.linkText"
defaultMessage="Visit {link} to dive deeper."
Expand All @@ -192,9 +192,9 @@ export class Logs extends PureComponent {
),
}}
/>
</p>
</RedirectAppLinks>
</EuiCallOut>
);
) : null;
}

render() {
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/monitoring/public/components/logs/logs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ jest.mock('../../legacy_shims', () => ({
shims: {
getBasePath: () => '',
capabilities: { logs: { show: true } },
infra: {
locators: {
logsLocator: {
getRedirectUrl: () => '',
},
},
},
},
},
}));
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/monitoring/public/legacy_shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { TriggersAndActionsUIPublicPluginStart } from '@kbn/triggers-actions-ui-
import { TypeRegistry } from '@kbn/triggers-actions-ui-plugin/public/application/type_registry';
import { ActionTypeModel, RuleTypeModel } from '@kbn/triggers-actions-ui-plugin/public/types';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import type { InfraClientStartExports } from '@kbn/infra-plugin/public';
import {
MonitoringStartPluginDependencies,
LegacyMonitoringStartPluginDependencies,
Expand Down Expand Up @@ -73,6 +74,7 @@ export interface IShims {
usageCollection: UsageCollectionSetup;
kibanaServices: CoreStart & { usageCollection: UsageCollectionSetup };
appMountParameters: AppMountParameters;
infra?: InfraClientStartExports;
}

export class Legacy {
Expand All @@ -85,6 +87,7 @@ export class Legacy {
triggersActionsUi,
usageCollection,
appMountParameters,
infra,
}: LegacyMonitoringStartPluginDependencies) {
this._shims = {
toastNotifications: core.notifications.toasts,
Expand Down Expand Up @@ -143,6 +146,7 @@ export class Legacy {
usageCollection,
},
appMountParameters,
infra,
};
}

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/monitoring/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class MonitoringPlugin
usageCollection: plugins.usageCollection,
appMountParameters: params,
dataViews: pluginsStart.dataViews,
infra: pluginsStart.infra,
};

Legacy.init({
Expand All @@ -122,6 +123,7 @@ export class MonitoringPlugin
usageCollection: deps.usageCollection,
appMountParameters: deps.appMountParameters,
dataViews: deps.dataViews,
infra: deps.infra,
});

const config = Object.fromEntries(externalConfig);
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/monitoring/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type { MLJobs } from '../server/lib/elasticsearch/get_ml_jobs';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { DashboardStart } from '@kbn/dashboard-plugin/public';
import { FleetStart } from '@kbn/fleet-plugin/public';
import type { InfraClientStartExports } from '@kbn/infra-plugin/public';

export interface MonitoringStartPluginDependencies {
navigation: NavigationStart;
Expand All @@ -24,6 +25,7 @@ export interface MonitoringStartPluginDependencies {
dataViews: DataViewsPublicPluginStart;
dashboard?: DashboardStart;
fleet?: FleetStart;
infra?: InfraClientStartExports;
}

interface LegacyStartDependencies {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@kbn/fleet-plugin",
"@kbn/shared-ux-router",
"@kbn/observability-shared-plugin",
"@kbn/shared-ux-link-redirect-app",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit 43d751e

Please sign in to comment.