Skip to content

Commit

Permalink
Add Logic to Auto-populate Notebooks from Context Menu (opensearch-pr…
Browse files Browse the repository at this point in the history
…oject#30)

Signed-off-by: David Cui <[email protected]>
  • Loading branch information
davidcui1225 authored Apr 29, 2021
1 parent 4ce28a0 commit 2fca356
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
handleDataToVisualReportSourceChange,
getNotebooksOptions,
getNotebooksBaseUrlCreate,
getReportSourceFromURL,
} from './report_settings_helpers';
import { TimeRangeSelect } from './time_range';
import { converter } from '../utils';
Expand Down Expand Up @@ -489,27 +490,36 @@ export function ReportSettings(props: ReportSettingProps) {
}
}
}

const setNotebookFromInContextMenu = (response, id) => {
for (let index = 0; index < response.notebooks.length; ++index) {
if (id === response.notebooks[index].value) {
setNotebooksSourceSelect([response.notebooks[index]]);
}
}
}

const setInContextDefaultConfiguration = (response) => {
const url = window.location.href;
const source = getReportSourceFromURL(url);
const id = parseInContextUrl(url, 'id');
if (url.includes('dashboard')) {
if (source === 'dashboard') {
setReportSourceId('dashboardReportSource');
reportDefinitionRequest.report_params.report_source =
REPORT_SOURCE_RADIOS[0].label;

setDashboardFromInContextMenu(response, id);
reportDefinitionRequest.report_params.core_params.base_url =
getDashboardBaseUrlCreate(edit, id, true) + id;
} else if (url.includes('visualize')) {
} else if (source === 'visualize') {
setReportSourceId('visualizationReportSource');
reportDefinitionRequest.report_params.report_source =
REPORT_SOURCE_RADIOS[1].label;

setVisualizationFromInContextMenu(response, id);
reportDefinitionRequest.report_params.core_params.base_url =
getVisualizationBaseUrlCreate(edit, editDefinitionId, true) + id;
} else if (url.includes('discover')) {
} else if (source === 'discover') {
setReportSourceId('savedSearchReportSource');
reportDefinitionRequest.report_params.core_params.report_format = 'csv';
reportDefinitionRequest.report_params.core_params.saved_search_id = id;
Expand All @@ -519,6 +529,16 @@ export function ReportSettings(props: ReportSettingProps) {
setSavedSearchFromInContextMenu(response, id)
reportDefinitionRequest.report_params.core_params.base_url =
getSavedSearchBaseUrlCreate(edit, editDefinitionId, true) + id;
} else if (source === 'notebook') {
setReportSourceId('notebooksReportSource');
reportDefinitionRequest.report_params.report_source =
REPORT_SOURCE_RADIOS[3].label;

setNotebookFromInContextMenu(response, id);
reportDefinitionRequest.report_params.core_params.base_url =
getNotebooksBaseUrlCreate(edit, id, true) + id;
// set placeholder time range since notebooks doesn't use it
reportDefinitionRequest.report_params.core_params.time_duration = 'PT30M';
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,8 @@ export const handleDataToVisualReportSourceChange = (
delete reportDefinitionRequest.report_params.core_params.excel;
reportDefinitionRequest.report_params.core_params.report_format = 'pdf';
};

export const getReportSourceFromURL = (url: string) => {
const source = url.split('?')[1].match(/previous=(.*):/);
return source![1];
}

0 comments on commit 2fca356

Please sign in to comment.