From 7929671447e5f5159a96ef7d0b749df0a9c5a19d Mon Sep 17 00:00:00 2001 From: David Cui Date: Thu, 29 Apr 2021 12:31:13 -0700 Subject: [PATCH 1/2] add logic to populate create page from notebooks context menu Signed-off-by: David Cui --- .../report_settings/report_settings.tsx | 26 ++++++++++++++++--- .../report_settings_helpers.tsx | 5 ++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx b/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx index 250569cb..fc8fafd7 100644 --- a/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx +++ b/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx @@ -67,6 +67,7 @@ import { handleDataToVisualReportSourceChange, getNotebooksOptions, getNotebooksBaseUrlCreate, + getReportSourceFromContextMenu, } from './report_settings_helpers'; import { TimeRangeSelect } from './time_range'; import { converter } from '../utils'; @@ -489,11 +490,20 @@ 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 = getReportSourceFromContextMenu(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; @@ -501,7 +511,7 @@ export function ReportSettings(props: ReportSettingProps) { 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; @@ -509,7 +519,7 @@ export function ReportSettings(props: ReportSettingProps) { 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; @@ -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'; } }; diff --git a/dashboards-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx b/dashboards-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx index 8348fc0e..783b6ae9 100644 --- a/dashboards-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx +++ b/dashboards-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx @@ -196,3 +196,8 @@ export const handleDataToVisualReportSourceChange = ( delete reportDefinitionRequest.report_params.core_params.excel; reportDefinitionRequest.report_params.core_params.report_format = 'pdf'; }; + +export const getReportSourceFromContextMenu = (url: string) => { + const source = url.split('?')[1].match(/previous=(.*):/); + return source![1]; +} \ No newline at end of file From d799ffc9526b2613591a9561dbc2e882ed7b249f Mon Sep 17 00:00:00 2001 From: David Cui Date: Thu, 29 Apr 2021 13:48:55 -0700 Subject: [PATCH 2/2] rename helper function to refer to URL Signed-off-by: David Cui --- .../report_definitions/report_settings/report_settings.tsx | 4 ++-- .../report_settings/report_settings_helpers.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx b/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx index fc8fafd7..18cae4bd 100644 --- a/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx +++ b/dashboards-reports/public/components/report_definitions/report_settings/report_settings.tsx @@ -67,7 +67,7 @@ import { handleDataToVisualReportSourceChange, getNotebooksOptions, getNotebooksBaseUrlCreate, - getReportSourceFromContextMenu, + getReportSourceFromURL, } from './report_settings_helpers'; import { TimeRangeSelect } from './time_range'; import { converter } from '../utils'; @@ -501,7 +501,7 @@ export function ReportSettings(props: ReportSettingProps) { const setInContextDefaultConfiguration = (response) => { const url = window.location.href; - const source = getReportSourceFromContextMenu(url); + const source = getReportSourceFromURL(url); const id = parseInContextUrl(url, 'id'); if (source === 'dashboard') { setReportSourceId('dashboardReportSource'); diff --git a/dashboards-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx b/dashboards-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx index 783b6ae9..e3ff2a80 100644 --- a/dashboards-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx +++ b/dashboards-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx @@ -197,7 +197,7 @@ export const handleDataToVisualReportSourceChange = ( reportDefinitionRequest.report_params.core_params.report_format = 'pdf'; }; -export const getReportSourceFromContextMenu = (url: string) => { +export const getReportSourceFromURL = (url: string) => { const source = url.split('?')[1].match(/previous=(.*):/); return source![1]; } \ No newline at end of file