Skip to content

Commit

Permalink
Refactor: Use uiSettings directly from services prop (#174170)
Browse files Browse the repository at this point in the history
Refactors according to this
[comment](#172498 (comment))

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
mgiota and kibanamachine authored Jan 4, 2024
1 parent af4dcb4 commit aa372f4
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function AlertsOverview() {
timefilter: { timefilter: timeFilterService },
},
},
uiSettings,
} = services;

const useToasts = () => notifications!.toasts;
Expand Down Expand Up @@ -98,7 +99,12 @@ export function AlertsOverview() {
rangeTo={rangeTo}
rangeFrom={rangeFrom}
status={alertStatusFilter}
services={{ timeFilterService, AlertsSearchBar, useToasts }}
services={{
timeFilterService,
AlertsSearchBar,
useToasts,
uiSettings,
}}
/>
</EuiFlexItem>
</EuiFlexItem>
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { UiActionsSetup, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { UsageCollectionStart } from '@kbn/usage-collection-plugin/public';
import { DashboardStart } from '@kbn/dashboard-plugin/public';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser';
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
import type { ConfigSchema } from '.';
Expand All @@ -84,6 +85,7 @@ import { getLazyAPMPolicyEditExtension } from './components/fleet_integration/la
import { featureCatalogueEntry } from './feature_catalogue_entry';
import { APMServiceDetailLocator } from './locator/service_detail_locator';
import { ITelemetryClient, TelemetryService } from './services/telemetry';

export type ApmPluginSetup = ReturnType<ApmPlugin['setup']>;
export type ApmPluginStart = void;

Expand Down Expand Up @@ -137,6 +139,7 @@ export interface ApmPluginStartDeps {
observabilityAIAssistant: ObservabilityAIAssistantPluginStart;
dashboard: DashboardStart;
metricsDataAccess: MetricsDataPluginStart;
uiSettings: IUiSettingsClient;
}

const servicesTitle = i18n.translate('xpack.apm.navigation.servicesTitle', {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"@kbn/elastic-agent-utils",
"@kbn/shared-ux-link-redirect-app",
"@kbn/observability-get-padded-alert-time-range-util",
"@kbn/core-lifecycle-server"
"@kbn/core-lifecycle-server",
"@kbn/core-ui-settings-browser"
],
"exclude": ["target/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import React from 'react';
import { waitFor } from '@testing-library/react';
import { timefilterServiceMock } from '@kbn/data-plugin/public/query/timefilter/timefilter_service.mock';
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-browser-mocks';

import { ObservabilityAlertSearchBarProps, Services } from './types';
import { ObservabilityAlertSearchBar } from './alert_search_bar';
import { observabilityAlertFeatureIds } from '../../../common/constants';
Expand All @@ -33,6 +35,7 @@ describe('ObservabilityAlertSearchBar', () => {
rangeFrom: 'now-15m',
status: 'all',
services: {
uiSettings: uiSettingsServiceMock.createStartContract(),
timeFilterService: timefilterServiceMock.createStartContract().timefilter,
AlertsSearchBar: getAlertsSearchBarMock.mockReturnValue(
<div data-test-subj={ALERT_SEARCH_BAR_DATA_TEST_SUBJ} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { ALERT_STATUS_QUERY, DEFAULT_QUERIES, DEFAULT_QUERY_STRING } from './con
import { ObservabilityAlertSearchBarProps } from './types';
import { buildEsQuery } from '../../utils/build_es_query';
import { AlertStatus } from '../../../common/typings';
import { useKibana } from '../../utils/kibana_react';

const getAlertStatusQuery = (status: string): Query[] => {
return ALERT_STATUS_QUERY[status]
Expand All @@ -39,11 +38,10 @@ export function ObservabilityAlertSearchBar({
kuery,
rangeFrom,
rangeTo,
services: { AlertsSearchBar, timeFilterService, useToasts },
services: { AlertsSearchBar, timeFilterService, useToasts, uiSettings },
status,
}: ObservabilityAlertSearchBarProps) {
const toasts = useToasts();
const { uiSettings } = useKibana().services;

const onAlertStatusChange = useCallback(
(alertStatus: AlertStatus) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ function AlertSearchbarWithUrlSync(props: AlertSearchBarWithUrlSyncProps) {
},
},
triggersActionsUi: { getAlertsSearchBar: AlertsSearchBar },
uiSettings,
} = useKibana().services;

return (
<ObservabilityAlertSearchBar
{...stateProps}
{...searchBarProps}
services={{ timeFilterService, AlertsSearchBar, useToasts }}
services={{ timeFilterService, AlertsSearchBar, useToasts, uiSettings }}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { ToastsStart } from '@kbn/core-notifications-browser';
import { TimefilterContract } from '@kbn/data-plugin/public';
import { AlertsSearchBarProps } from '@kbn/triggers-actions-ui-plugin/public/application/sections/alerts_search_bar';
import { BoolQuery, Query } from '@kbn/es-query';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser';
import { AlertStatus } from '../../../common/typings';

export interface AlertStatusFilterProps {
status: AlertStatus;
onChange: (id: AlertStatus) => void;
Expand All @@ -37,6 +37,7 @@ export interface Services {
timeFilterService: TimefilterContract;
AlertsSearchBar: (props: AlertsSearchBarProps) => ReactElement<AlertsSearchBarProps>;
useToasts: () => ToastsStart;
uiSettings: IUiSettingsClient;
}

export interface ObservabilityAlertSearchBarProps
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/observability/public/pages/alerts/alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function InternalAlertsPage() {
getAlertsStateTable: AlertsStateTable,
getAlertSummaryWidget: AlertSummaryWidget,
},
uiSettings,
} = kibanaServices;
const { ObservabilityPageTemplate } = usePluginContext();
const alertSearchBarStateProps = useAlertSearchBarStateContainer(ALERTS_URL_STORAGE_KEY, {
Expand Down Expand Up @@ -198,7 +199,7 @@ function InternalAlertsPage() {
{...alertSearchBarStateProps}
appName={ALERTS_SEARCH_BAR_ID}
onEsQueryChange={setEsQuery}
services={{ timeFilterService, AlertsSearchBar, useToasts }}
services={{ timeFilterService, AlertsSearchBar, useToasts, uiSettings }}
/>
</EuiFlexItem>
<EuiFlexItem>
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/observability/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"@kbn/task-manager-plugin",
"@kbn/core-elasticsearch-client-server-mocks",
"@kbn/ingest-pipelines-plugin",
"@kbn/core-saved-objects-api-server-mocks"
"@kbn/core-saved-objects-api-server-mocks",
"@kbn/core-ui-settings-browser-mocks"
],
"exclude": [
"target/**/*"
Expand Down

0 comments on commit aa372f4

Please sign in to comment.