diff --git a/public/components/notebooks/components/notebook.tsx b/public/components/notebooks/components/notebook.tsx index 3b1ad3ed78..7b2ff28c78 100644 --- a/public/components/notebooks/components/notebook.tsx +++ b/public/components/notebooks/components/notebook.tsx @@ -113,6 +113,7 @@ interface NotebookState { savedObjectNotebook: boolean; dataSourceMDSId: string | undefined | null; dataSourceMDSLabel: string | undefined | null; + dataSourceMDSEnabled: boolean; } export class Notebook extends Component { constructor(props: Readonly) { @@ -138,6 +139,7 @@ export class Notebook extends Component { savedObjectNotebook: true, dataSourceMDSId: null, dataSourceMDSLabel: null, + dataSourceMDSEnabled: false, }; } @@ -530,8 +532,8 @@ export class Notebook extends Component { paragraphId: para.uniqueId, paragraphInput: para.inp, paragraphType: paraType || '', - dataSourceMDSId: this.state.dataSourceMDSId, - dataSourceMDSLabel: this.state.dataSourceMDSLabel, + dataSourceMDSId: this.state.dataSourceMDSId || '', + dataSourceMDSLabel: this.state.dataSourceMDSLabel || '', }; const isValid = isValidUUID(this.props.openedNoteId); const route = isValid @@ -628,6 +630,7 @@ export class Notebook extends Component { const isValid = isValidUUID(this.props.openedNoteId); this.setState({ savedObjectNotebook: isValid, + dataSourceMDSEnabled: isValid && this.props.dataSourceEnabled, }); const route = isValid ? `${NOTEBOOKS_API_PREFIX}/note/savedNotebook/${this.props.openedNoteId}` @@ -639,11 +642,32 @@ export class Notebook extends Component { let index = 0; for (index = 0; index < res.paragraphs.length; ++index) { // if the paragraph is a query, load the query output - if (res.paragraphs[index].output[0]?.outputType === 'QUERY') { + if ( + res.paragraphs[index].output[0]?.outputType === 'QUERY' && + this.props.dataSourceEnabled && + res.paragraphs[index].dataSourceMDSId + ) { await this.loadQueryResultsFromInput( res.paragraphs[index], res.paragraphs[index].dataSourceMDSId ); + } else if ( + res.paragraphs[index].output[0]?.outputType === 'QUERY' && + !this.props.dataSourceEnabled && + res.paragraphs[index].dataSourceMDSId + ) { + res.paragraphs[index].output[0] = []; + this.props.setToast( + `Data source ${res.paragraphs[index].dataSourceMDSLabel} is not available. Please configure your dataSources`, + 'danger' + ); + } else if ( + res.paragraphs[index].output[0]?.outputType === 'QUERY' && + !this.state.savedObjectNotebook + ) { + await this.loadQueryResultsFromInput(res.paragraphs[index]); + } else if (res.paragraphs[index].output[0]?.outputType === 'QUERY') { + await this.loadQueryResultsFromInput(res.paragraphs[index], ''); } } this.setState(res, this.parseAllParagraphs); @@ -670,7 +694,7 @@ export class Notebook extends Component { await this.props.http .post(`/api/sql/${queryType}`, { body: JSON.stringify(paragraph.output[0].result), - query, + ...(this.props.dataSourceEnabled && { query }), }) .then((response) => { paragraph.output[0].result = response.data.resp; @@ -1132,7 +1156,7 @@ export class Notebook extends Component { dataSourceManagement={this.props.dataSourceManagement} setActionMenu={this.props.setActionMenu} notifications={this.props.notifications} - dataSourceEnabled={this.props.dataSourceEnabled} + dataSourceEnabled={this.state.dataSourceMDSEnabled} savedObjectsMDSClient={this.props.savedObjectsMDSClient} handleSelectedDataSourceChange={this.handleSelectedDataSourceChange} paradataSourceMDSId={this.state.parsedPara[index].dataSourceMDSId} diff --git a/server/saved_objects/observability_saved_object.ts b/server/saved_objects/observability_saved_object.ts index 5085e6d448..eb37003011 100644 --- a/server/saved_objects/observability_saved_object.ts +++ b/server/saved_objects/observability_saved_object.ts @@ -4,6 +4,7 @@ */ import { SavedObjectsType } from '../../../../src/core/server'; +import { NOTEBOOKS_API_PREFIX } from '../../common/constants/notebooks'; import { observabilityLogsID } from '../../common/constants/shared'; import { NOTEBOOK_SAVED_OBJECT, @@ -93,8 +94,7 @@ export const notebookSavedObject: SavedObjectsType = { return obj.attributes.title; }, getInAppUrl(obj) { - const editPath = `#/explorer/${NOTEBOOK_SAVED_OBJECT}:${obj.id}`; - const editUrl = `/app/${observabilityLogsID}${editPath}`; + const editUrl = `/app/${NOTEBOOKS_API_PREFIX}#/${obj.id}?view=view_both`; return { path: editUrl, uiCapabilitiesPath: 'observability.show',