diff --git a/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx b/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx index 9ab053441..35b707ae8 100644 --- a/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx +++ b/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx @@ -4,20 +4,20 @@ */ import React, { useCallback, useEffect, useState } from "react"; -import { EuiBadge, EuiDescriptionList, EuiFlexGroup, EuiFlexItem, EuiHorizontalRule, EuiLink, EuiLoadingContent, EuiPanel, EuiSmallButtonEmpty, EuiText, EuiTitle } from "@elastic/eui"; +import { EuiBadge, EuiDescriptionList, EuiEmptyPrompt, EuiFlexGroup, EuiFlexItem, EuiHorizontalRule, EuiLink, EuiLoadingContent, EuiPanel, EuiText, EuiTitle } from "@elastic/eui"; import { DataSourceManagementPluginSetup, DataSourceOption } from "../../../../../src/plugins/data_source_management/public"; import { getApplication, getClient, getNotifications, getSavedObjectsClient } from "../../services"; import { dataSourceFilterFn, getSeverityColor, getSeverityBadgeText, getTruncatedText } from "../../utils/helpers"; import { renderTime } from "../../pages/Dashboard/utils/tableUtils"; -import { ALERTS_NAV_ID } from "../../../utils/constants"; -import { DEFAULT_EMPTY_DATA } from "../../utils/constants"; +import { ALERTS_NAV_ID, MONITORS_NAV_ID } from "../../../utils/constants"; +import { APP_PATH, DEFAULT_EMPTY_DATA } from "../../utils/constants"; export interface DataSourceAlertsCardProps { - getDataSourceMenu: DataSourceManagementPluginSetup['ui']['getDataSourceMenu']; + getDataSourceMenu?: DataSourceManagementPluginSetup['ui']['getDataSourceMenu']; } export const DataSourceAlertsCard: React.FC = ({ getDataSourceMenu }) => { - const DataSourceSelector = getDataSourceMenu(); + const DataSourceSelector = getDataSourceMenu?.(); const [loading, setLoading] = useState(false); const [dataSource, setDataSource] = useState({ label: 'Local cluster', @@ -109,34 +109,45 @@ export const DataSourceAlertsCard: React.FC = ({ get - - - + {DataSourceSelector && ( + + + + )} {loading ? ( - ) : ( + ) : alertsListItems.length > 0 ? ( + ) : ( + +
There are no existing alerts.
+ Create a monitor to add triggers and actions. + + )} + /> )}
- View all + View all diff --git a/public/services/services.ts b/public/services/services.ts index 15e7308e6..8d098463e 100644 --- a/public/services/services.ts +++ b/public/services/services.ts @@ -13,6 +13,7 @@ import { DataPublicPluginStart } from '../../../../src/plugins/data/public'; import { EmbeddableStart } from '../../../../src/plugins/embeddable/public'; import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public'; import { ContentManagementPluginStart } from '../../../../src/plugins/content_management/public'; +import { createNullableGetterSetter } from './utils/helper'; const ServicesContext = createContext(null); @@ -41,8 +42,7 @@ export const [getQueryService, setQueryService] = createGetterSetter< export const [getSavedObjectsClient, setSavedObjectsClient] = createGetterSetter('SavedObjectsClient'); -export const [getDataSourceManagementPlugin, setDataSourceManagementPlugin] = - createGetterSetter('DataSourceManagement'); +export const [getDataSourceManagementPlugin, setDataSourceManagementPlugin] = createNullableGetterSetter(); export const [getDataSourceEnabled, setDataSourceEnabled] = createGetterSetter('DataSourceEnabled'); diff --git a/public/services/utils/helper.ts b/public/services/utils/helper.ts index d68a9fc1c..d3937b2a2 100644 --- a/public/services/utils/helper.ts +++ b/public/services/utils/helper.ts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { Get, Set } from '../../../../../src/plugins/opensearch_dashboards_utils/common'; import { ChannelItemType, // NotificationItem, @@ -23,6 +24,20 @@ export const configListToChannels = (configs: any[]): ChannelItemType[] => { return configs?.map((config) => configToChannel(config)) || []; }; +export function createNullableGetterSetter(): [Get, Set] { + let value: T; + + const get = () => { + return value; + }; + + const set = (newValue: T) => { + value = newValue; + }; + + return [get, set]; +} + // export const configToSender = (config: any): SenderItemType => { // return { // name: config.config.name, diff --git a/public/utils/helpers.js b/public/utils/helpers.js index 0f606f34a..f95f3b6fc 100644 --- a/public/utils/helpers.js +++ b/public/utils/helpers.js @@ -206,7 +206,7 @@ export function registerAlertsCard() { order: 10, render: () => ( ), }),