Skip to content

Commit

Permalink
edge cases for migration
Browse files Browse the repository at this point in the history
Signed-off-by: sumukhswamy <[email protected]>
  • Loading branch information
sumukhswamy committed Jul 20, 2024
1 parent 295ca95 commit b1b8f25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
34 changes: 29 additions & 5 deletions public/components/notebooks/components/notebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ interface NotebookState {
savedObjectNotebook: boolean;
dataSourceMDSId: string | undefined | null;
dataSourceMDSLabel: string | undefined | null;
dataSourceMDSEnabled: boolean;
}
export class Notebook extends Component<NotebookProps, NotebookState> {
constructor(props: Readonly<NotebookProps>) {
Expand All @@ -138,6 +139,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
savedObjectNotebook: true,
dataSourceMDSId: null,
dataSourceMDSLabel: null,
dataSourceMDSEnabled: false,
};
}

Expand Down Expand Up @@ -530,8 +532,8 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
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
Expand Down Expand Up @@ -628,6 +630,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
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}`
Expand All @@ -639,11 +642,32 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
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);
Expand All @@ -670,7 +694,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
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;
Expand Down Expand Up @@ -1132,7 +1156,7 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
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}
Expand Down
4 changes: 2 additions & 2 deletions server/saved_objects/observability_saved_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit b1b8f25

Please sign in to comment.