From 2433e067c7251023646e2b7b8b89fd2671a3d6d7 Mon Sep 17 00:00:00 2001 From: sumukhswamy Date: Thu, 29 Aug 2024 11:34:48 -0700 Subject: [PATCH] changes for label Signed-off-by: sumukhswamy --- .../components/helpers/modal_containers.tsx | 8 ++++++-- public/components/notebooks/components/main.tsx | 8 ++++---- .../components/notebooks/components/note_table.tsx | 14 +++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/public/components/notebooks/components/helpers/modal_containers.tsx b/public/components/notebooks/components/helpers/modal_containers.tsx index 88879dd3c..c52d409f5 100644 --- a/public/components/notebooks/components/helpers/modal_containers.tsx +++ b/public/components/notebooks/components/helpers/modal_containers.tsx @@ -89,12 +89,16 @@ export const getSampleNotebooksModal = ( dataSourceManagement: DataSourceManagementPluginSetup, savedObjectsMDSClient: SavedObjectsStart, notifications: CoreStart['notifications'], - handleSelectedDataSourceChange: (dataSourceMDSId: string | undefined) => void + handleSelectedDataSourceChange: ( + dataSourceMDSId: string | undefined, + dataSourceMDSLabel: string | undefined + ) => void ) => { let DataSourceSelector; const onSelectedDataSource = (e) => { const dataConnectionId = e[0] ? e[0].id : undefined; - handleSelectedDataSourceChange(dataConnectionId); + const dataConnectionLabel = e[0] ? e[0].label : undefined; + handleSelectedDataSourceChange(dataConnectionId, dataConnectionLabel); }; if (dataSourceEnabled) { diff --git a/public/components/notebooks/components/main.tsx b/public/components/notebooks/components/main.tsx index a857a6e49..5837f1f10 100644 --- a/public/components/notebooks/components/main.tsx +++ b/public/components/notebooks/components/main.tsx @@ -298,7 +298,7 @@ export class Main extends React.Component { console.error(err.body.message); }); }; - addSampleNotebooks = async (dataSourceMDSId?: string) => { + addSampleNotebooks = async (dataSourceMDSId?: string, dataSourceMDSLabel?: string) => { try { this.setState({ loading: true }); const flights = await this.props.http @@ -357,7 +357,7 @@ export class Main extends React.Component { query: { type: 'visualization', search_fields: 'title', - search: '[Logs] Response Codes Over Time + Annotations', + search: `[Logs] Response Codes Over Time + Annotations_${dataSourceMDSLabel}`, }, }) .then((resp) => visIds.push(resp.saved_objects[0].id)); @@ -366,7 +366,7 @@ export class Main extends React.Component { query: { type: 'visualization', search_fields: 'title', - search: '[Logs] Unique Visitors vs. Average Bytes', + search: `[Logs] Unique Visitors vs. Average Bytes_${dataSourceMDSLabel}`, }, }) .then((resp) => visIds.push(resp.saved_objects[0].id)); @@ -375,7 +375,7 @@ export class Main extends React.Component { query: { type: 'visualization', search_fields: 'title', - search: '[Flights] Flight Count and Average Ticket Price', + search: `[Flights] Flight Count and Average Ticket Price_${dataSourceMDSLabel}`, }, }) .then((resp) => visIds.push(resp.saved_objects[0].id)); diff --git a/public/components/notebooks/components/note_table.tsx b/public/components/notebooks/components/note_table.tsx index 3f830aa41..1467c3797 100644 --- a/public/components/notebooks/components/note_table.tsx +++ b/public/components/notebooks/components/note_table.tsx @@ -58,7 +58,10 @@ const newNavigation = coreRefs.chrome?.navGroup.getNavGroupEnabled(); interface NoteTableProps { loading: boolean; fetchNotebooks: () => void; - addSampleNotebooks: (dataSourceMDSId: string | undefined) => void; + addSampleNotebooks: ( + dataSourceMDSId: string | undefined, + dataSourceLabel: string | undefined + ) => void; notebooks: NotebookType[]; createNotebook: (newNoteName: string) => void; renameNotebook: (newNoteName: string, noteId: string) => void; @@ -96,6 +99,7 @@ export function NoteTable({ const location = useLocation(); const history = useHistory(); const [_dataSourceMDSId, setDataSourceMDSId] = useState(''); + const [_dataSourceMDSLabel, setDataSourceMDSLabel] = useState(''); useEffect(() => { setNavBreadCrumbs( @@ -174,16 +178,20 @@ export function NoteTable({ const addSampleNotebooksModal = async () => { let selectedDataSourceId: string | undefined; - const handleSelectedDataSourceChange = (id?: string) => { + let selectedDataSourceLabel: string | undefined; + const handleSelectedDataSourceChange = (id?: string, label?: string) => { selectedDataSourceId = id; + selectedDataSourceLabel = label; setDataSourceMDSId(id); + setDataSourceMDSLabel(label); }; setModalLayout( getSampleNotebooksModal( closeModal, async () => { + console.log(selectedDataSourceId, selectedDataSourceLabel); closeModal(); - await addSampleNotebooks(selectedDataSourceId); + await addSampleNotebooks(selectedDataSourceId, selectedDataSourceLabel); }, dataSourceEnabled, dataSourceManagement,