From aed439731a357a8aa3fcc65feefcc9f5365de033 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Wed, 4 Sep 2024 13:40:25 -0700 Subject: [PATCH 1/2] check for multi data source enabled Signed-off-by: Amardeepsingh Siglani --- .../DataSourceAlertsCard.tsx | 32 ++++++++++--------- public/services/services.ts | 4 +-- public/services/utils/helper.ts | 15 +++++++++ public/utils/helpers.js | 2 +- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx b/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx index 9ab053441..669709956 100644 --- a/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx +++ b/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx @@ -13,11 +13,11 @@ import { ALERTS_NAV_ID } from "../../../utils/constants"; import { 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,19 +109,21 @@ export const DataSourceAlertsCard: React.FC = ({ get - - - + {DataSourceSelector && ( + + + + )} 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: () => ( ), }), From 98b7fafe1896e84f92dd4d2721ff49328fca0df1 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Wed, 4 Sep 2024 13:40:55 -0700 Subject: [PATCH 2/2] added empty state Signed-off-by: Amardeepsingh Siglani --- .../DataSourceAlertsCard.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx b/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx index 669709956..35b707ae8 100644 --- a/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx +++ b/public/components/DataSourceAlertsCard/DataSourceAlertsCard.tsx @@ -4,13 +4,13 @@ */ 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']; @@ -129,16 +129,25 @@ export const DataSourceAlertsCard: React.FC = ({ get {loading ? ( - ) : ( + ) : alertsListItems.length > 0 ? ( + ) : ( + +
There are no existing alerts.
+ Create a monitor to add triggers and actions. + + )} + /> )}
- View all + View all