Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Logic to Auto-populate Notebooks from Context Menu #30

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
}