From dfa2d45d347fc51f2a7e653b30190ab581b75b48 Mon Sep 17 00:00:00 2001 From: keskami Date: Fri, 24 Nov 2023 09:07:55 -0500 Subject: [PATCH 1/4] -s --- .../opensearch_dashboards.json | 3 +- .../public/drilldown_options.tsx | 71 ++++++++++++++++++- .../vis_type_drilldown/public/types.ts | 7 +- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/plugins/vis_type_drilldown/opensearch_dashboards.json b/src/plugins/vis_type_drilldown/opensearch_dashboards.json index c7cb6af3f0fa..c309b8fc8d2e 100644 --- a/src/plugins/vis_type_drilldown/opensearch_dashboards.json +++ b/src/plugins/vis_type_drilldown/opensearch_dashboards.json @@ -13,5 +13,6 @@ "data", "visDefaultEditor" ], - "optionalPlugins": [] + "optionalPlugins": [], + "requiredBundles": ["opensearchDashboardsUtils", "opensearchDashboardsReact", "home"] } diff --git a/src/plugins/vis_type_drilldown/public/drilldown_options.tsx b/src/plugins/vis_type_drilldown/public/drilldown_options.tsx index 6060414ba4d0..07f97f568f1c 100644 --- a/src/plugins/vis_type_drilldown/public/drilldown_options.tsx +++ b/src/plugins/vis_type_drilldown/public/drilldown_options.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useCallback, useState } from 'react'; +import React, { useCallback, Fragment, useState, useEffect } from 'react'; import { EuiPanel, EuiTitle, @@ -12,11 +12,13 @@ import { EuiFlexItem, EuiFieldText, EuiAccordion, + EuiSuperSelect, + EuiText, } from '@elastic/eui'; -import { FormattedMessage } from '@osd/i18n/react'; import { VisOptionsProps } from 'src/plugins/vis_default_editor/public'; -import { DrilldownVisParams } from './types'; +import { useOpenSearchDashboards } from 'src/plugins/opensearch_dashboards_react/public'; +import { DrilldownServices, DrilldownVisParams } from './types'; function DrilldownOptions({ stateParams, setValue }: VisOptionsProps) { const onMarkdownUpdate = useCallback( @@ -24,11 +26,58 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps(); + + useEffect(() => { + const savedObject = savedObjectsClient.find({ + type: 'dashboard', + }); + }); + const onDescriptionUpdate = useCallback( (value: DrilldownVisParams['cardDescription']) => setValue('cardDescription', value), [setValue] ); + const activeVisName = ''; + const handleVisTypeChange = () => {}; + const options = [ + { + value: '1', + inputDisplay: 'Option 1', + dropdownDisplay: ( + + Name + +

+ id +
+ text +

+
+
+ ), + }, + { + value: '2', + inputDisplay: 'Option 2', + dropdownDisplay: ( + + Name + +

+ id +
+ text +

+
+
+ ), + }, + ]; + return ( @@ -70,6 +119,22 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps + + + +

+ +

+
+
+ +
diff --git a/src/plugins/vis_type_drilldown/public/types.ts b/src/plugins/vis_type_drilldown/public/types.ts index b147c2745027..54a63f10e845 100644 --- a/src/plugins/vis_type_drilldown/public/types.ts +++ b/src/plugins/vis_type_drilldown/public/types.ts @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { SavedObjectsClientContract } from 'src/core/public/saved_objects/saved_objects_client'; +import { CoreStart } from 'src/core/server'; import { NavigationPublicPluginStart } from '../../navigation/public'; import { VisualizationsSetup } from '../../visualizations/public'; -import { Arguments } from '../../vis_type_markdown/public/types'; export interface VisDrilldownPluginSetup { getGreeting: () => string; @@ -39,3 +40,7 @@ export interface DrilldownVisParams { cardName: DrilldownArguments['cardName']; cardDescription: DrilldownArguments['cardDescription']; } + +export interface DrilldownServices extends CoreStart { + savedObjectsClient: SavedObjectsClientContract; +} From f2ed6f5f4cc593b8080601a24e866ac39af94a05 Mon Sep 17 00:00:00 2001 From: keskami Date: Fri, 24 Nov 2023 09:13:16 -0500 Subject: [PATCH 2/4] Module Issue for useOpensearchDashboard Signed-off-by: keskami --- src/plugins/vis_type_drilldown/public/drilldown_options.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_type_drilldown/public/drilldown_options.tsx b/src/plugins/vis_type_drilldown/public/drilldown_options.tsx index 07f97f568f1c..f40b61edd6d7 100644 --- a/src/plugins/vis_type_drilldown/public/drilldown_options.tsx +++ b/src/plugins/vis_type_drilldown/public/drilldown_options.tsx @@ -31,7 +31,7 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps(); useEffect(() => { - const savedObject = savedObjectsClient.find({ + const saved = savedObjectsClient.find({ type: 'dashboard', }); }); From d50a5a90ceb28d45d5910c587aded27a5e593f23 Mon Sep 17 00:00:00 2001 From: keskami Date: Wed, 29 Nov 2023 11:00:41 -0500 Subject: [PATCH 3/4] Added Super Select and Grabbed URL of Saved Object with Type 'Dashboards' Signed-off-by: keskami --- .../saved_objects/saved_objects_client.ts | 2 +- .../saved_objects/simple_saved_object.ts | 4 ++-- .../opensearch_dashboards.json | 3 +-- .../public/drilldown_options.tsx | 22 ++++++++++++++----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 6e5482614e40..88495e2c2bef 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -491,7 +491,7 @@ export class SavedObjectsClient { return new SimpleSavedObject(this, options); } - private getPath(path: Array): string { + public getPath(path: Array): string { return resolveUrl(API_BASE_URL, join(...path)); } diff --git a/src/core/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts index 71b1445e95aa..159d59926d5c 100644 --- a/src/core/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -31,7 +31,7 @@ import { set } from '@elastic/safer-lodash-set'; import { get, has } from 'lodash'; import { SavedObject as SavedObjectType } from '../../server'; -import { SavedObjectsClientContract } from './saved_objects_client'; +import { SavedObjectsClient } from './saved_objects_client'; /** * This class is a very simple wrapper for SavedObjects loaded from the server @@ -54,7 +54,7 @@ export class SimpleSavedObject { public updated_at: SavedObjectType['updated_at']; constructor( - private client: SavedObjectsClientContract, + private client: SavedObjectsClient, { id, type, diff --git a/src/plugins/vis_type_drilldown/opensearch_dashboards.json b/src/plugins/vis_type_drilldown/opensearch_dashboards.json index c309b8fc8d2e..c7cb6af3f0fa 100644 --- a/src/plugins/vis_type_drilldown/opensearch_dashboards.json +++ b/src/plugins/vis_type_drilldown/opensearch_dashboards.json @@ -13,6 +13,5 @@ "data", "visDefaultEditor" ], - "optionalPlugins": [], - "requiredBundles": ["opensearchDashboardsUtils", "opensearchDashboardsReact", "home"] + "optionalPlugins": [] } diff --git a/src/plugins/vis_type_drilldown/public/drilldown_options.tsx b/src/plugins/vis_type_drilldown/public/drilldown_options.tsx index f40b61edd6d7..06d4fa875df2 100644 --- a/src/plugins/vis_type_drilldown/public/drilldown_options.tsx +++ b/src/plugins/vis_type_drilldown/public/drilldown_options.tsx @@ -17,7 +17,7 @@ import { } from '@elastic/eui'; import { VisOptionsProps } from 'src/plugins/vis_default_editor/public'; -import { useOpenSearchDashboards } from 'src/plugins/opensearch_dashboards_react/public'; +import { useOpenSearchDashboards } from '../../opensearch_dashboards_react/public'; import { DrilldownServices, DrilldownVisParams } from './types'; function DrilldownOptions({ stateParams, setValue }: VisOptionsProps) { @@ -27,14 +27,24 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps(); + let saved; + useEffect(() => { - const saved = savedObjectsClient.find({ - type: 'dashboard', - }); - }); + const fetchData = async () => { + saved = savedObjects?.client.find({ + type: 'dashboard', + + }); + const path = (await saved).savedObjects[0]['client'].getPath(['dashboard', (await saved).savedObjects[0].id]).substring(28,); + console.log(path); + console.log(http.basePath.prepend('/app/dashboards#/view/'+ path)); + console.log((await saved).savedObjects[0]) + }; + fetchData() + }, []); const onDescriptionUpdate = useCallback( (value: DrilldownVisParams['cardDescription']) => setValue('cardDescription', value), From 0921a718269bdbee987900d8f92848d1b0175b4f Mon Sep 17 00:00:00 2001 From: keskami Date: Wed, 29 Nov 2023 13:11:46 -0500 Subject: [PATCH 4/4] Added SuperSelect and Grabbed URL of SavedObject with Type 'Dashboard' Signed-off-by: keskami --- .../saved_objects/simple_saved_object.ts | 2 +- .../public/drilldown_options.tsx | 93 ++++++++++--------- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/src/core/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts index 159d59926d5c..42268e02f26f 100644 --- a/src/core/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -51,7 +51,7 @@ export class SimpleSavedObject { public migrationVersion: SavedObjectType['migrationVersion']; public error: SavedObjectType['error']; public references: SavedObjectType['references']; - public updated_at: SavedObjectType['updated_at']; + public updated_at: SavedObjectType['updated_at'] constructor( private client: SavedObjectsClient, diff --git a/src/plugins/vis_type_drilldown/public/drilldown_options.tsx b/src/plugins/vis_type_drilldown/public/drilldown_options.tsx index 06d4fa875df2..adfa134bc82b 100644 --- a/src/plugins/vis_type_drilldown/public/drilldown_options.tsx +++ b/src/plugins/vis_type_drilldown/public/drilldown_options.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useCallback, Fragment, useState, useEffect } from 'react'; +import React, { useCallback, Fragment, useState, useEffect, useRef } from 'react'; import { EuiPanel, EuiTitle, @@ -30,30 +30,13 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps(); - let saved; + interface List { + value: string; + inputDisplay: string; + dropdownDisplay: JSX.Element; // Adjust the type based on the actual type of dropdownDisplay + } - useEffect(() => { - const fetchData = async () => { - saved = savedObjects?.client.find({ - type: 'dashboard', - - }); - const path = (await saved).savedObjects[0]['client'].getPath(['dashboard', (await saved).savedObjects[0].id]).substring(28,); - console.log(path); - console.log(http.basePath.prepend('/app/dashboards#/view/'+ path)); - console.log((await saved).savedObjects[0]) - }; - fetchData() - }, []); - - const onDescriptionUpdate = useCallback( - (value: DrilldownVisParams['cardDescription']) => setValue('cardDescription', value), - [setValue] - ); - - const activeVisName = ''; - const handleVisTypeChange = () => {}; - const options = [ + const options = useRef([ { value: '1', inputDisplay: 'Option 1', @@ -70,23 +53,49 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps ), }, - { - value: '2', - inputDisplay: 'Option 2', - dropdownDisplay: ( - - Name - -

- id -
- text -

-
-
- ), - }, - ]; + ]); + + const saved = useRef(); + const index = useRef(); + + useEffect(() => { + const fetchData = async () => { + saved.current = savedObjects?.client.find({ + type: 'dashboard', + }); + const path = (await saved.current).savedObjects[0]['client'] + .getPath(['dashboard', (await saved.current).savedObjects[0].id]) + .substring(28); + const savedObjectURL = http.basePath.prepend('/app/dashboards#/view/' + path); + options.current = [ + { + value: savedObjectURL, + inputDisplay: 'yes', + dropdownDisplay: ( + + Name + +

+ id +
+ text +

+
+
+ ), + }, + ]; + }; + fetchData(); + }, []); + + const onDescriptionUpdate = useCallback( + (value: DrilldownVisParams['cardDescription']) => setValue('cardDescription', value), + [setValue] + ); + + const activeVisName = ''; + const handleVisTypeChange = () => {}; return ( @@ -139,7 +148,7 @@ function DrilldownOptions({ stateParams, setValue }: VisOptionsProps