Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Fixed Base Url Formation for Visualizations/Saved Searches #192

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -51,18 +51,26 @@ describe('report_settings_helpers tests', () => {
});

test('getVisualizationBaseUrlCreate', () => {
const baseUrl = getVisualizationBaseUrlCreate(true, true);
const baseUrl = getVisualizationBaseUrlCreate(true, '12345', true);
davidcui1225 marked this conversation as resolved.
Show resolved Hide resolved
expect(baseUrl).toBe('/app/visualize#/edit/');

const baseUrlNotFromEdit = getVisualizationBaseUrlCreate(false, true);
const baseUrlNotFromEdit = getVisualizationBaseUrlCreate(
false,
'12345',
true
);
expect(baseUrlNotFromEdit).toBe('/app/visualize#/edit/');
});

test('getSavedSearchBaseUrlCreate', () => {
const baseUrl = getSavedSearchBaseUrlCreate(true, true);
const baseUrl = getSavedSearchBaseUrlCreate(true, '12345', true);
expect(baseUrl).toBe('/app/discover#/view/');

const baseUrlNotFromEdit = getSavedSearchBaseUrlCreate(false, true);
const baseUrlNotFromEdit = getSavedSearchBaseUrlCreate(
false,
'12345',
true
);
expect(baseUrlNotFromEdit).toBe('/app/discover#/view/');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function ReportSettings(props: ReportSettingProps) {
} else if (e === 'visualizationReportSource') {
reportDefinitionRequest.report_params.report_source = 'Visualization';
reportDefinitionRequest.report_params.core_params.base_url =
getVisualizationBaseUrlCreate(edit, fromInContext) +
getVisualizationBaseUrlCreate(edit, editDefinitionId, fromInContext) +
visualizations[0].value;

// set params to visual report params after switch from saved search
Expand All @@ -150,7 +150,7 @@ export function ReportSettings(props: ReportSettingProps) {
} else if (e === 'savedSearchReportSource') {
reportDefinitionRequest.report_params.report_source = 'Saved search';
reportDefinitionRequest.report_params.core_params.base_url =
getSavedSearchBaseUrlCreate(edit, fromInContext) +
getSavedSearchBaseUrlCreate(edit, editDefinitionId, fromInContext) +
savedSearches[0].value;
reportDefinitionRequest.report_params.core_params.saved_search_id =
savedSearches[0].value;
Expand Down Expand Up @@ -182,7 +182,8 @@ export function ReportSettings(props: ReportSettingProps) {
fromInContext = true;
}
reportDefinitionRequest.report_params.core_params.base_url =
getVisualizationBaseUrlCreate(edit, fromInContext) + e.target.value;
getVisualizationBaseUrlCreate(edit, editDefinitionId, fromInContext) +
e.target.value;
};

const handleSavedSearchSelect = (e: {
Expand All @@ -191,6 +192,14 @@ export function ReportSettings(props: ReportSettingProps) {
setSavedSearchSourceSelect(e.target.value);
reportDefinitionRequest.report_params.core_params.saved_search_id =
e.target.value;

let fromInContext = false;
if (window.location.href.includes('?')) {
fromInContext = true;
}
reportDefinitionRequest.report_params.core_params.base_url =
getSavedSearchBaseUrlCreate(edit, editDefinitionId, fromInContext) +
e.target.value;
};

const handleFileFormat = (e: React.SetStateAction<string>) => {
Expand Down Expand Up @@ -457,7 +466,7 @@ export function ReportSettings(props: ReportSettingProps) {
REPORT_SOURCE_RADIOS[1].label;
setVisualizationSourceSelect(id);
reportDefinitionRequest.report_params.core_params.base_url =
getVisualizationBaseUrlCreate(edit, true) + id;
getVisualizationBaseUrlCreate(edit, editDefinitionId, true) + id;
} else if (url.includes('discover')) {
setReportSourceId('savedSearchReportSource');
reportDefinitionRequest.report_params.core_params.report_format = 'csv';
Expand All @@ -466,7 +475,7 @@ export function ReportSettings(props: ReportSettingProps) {
REPORT_SOURCE_RADIOS[2].label;
setSavedSearchSourceSelect(id);
reportDefinitionRequest.report_params.core_params.base_url =
getSavedSearchBaseUrlCreate(edit, true) + id;
getSavedSearchBaseUrlCreate(edit, editDefinitionId, true) + id;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const getDashboardBaseUrlCreate = (

export const getVisualizationBaseUrlCreate = (
edit: boolean,
editDefinitionId: string,
fromInContext: boolean
) => {
let baseUrl;
Expand All @@ -62,7 +63,7 @@ export const getVisualizationBaseUrlCreate = (
}
if (edit) {
return baseUrl.replace(
'opendistro_kibana_reports#/edit',
`opendistro_kibana_reports#/edit/${editDefinitionId}`,
'visualize#/edit/'
);
} else if (fromInContext) {
Expand All @@ -76,6 +77,7 @@ export const getVisualizationBaseUrlCreate = (

export const getSavedSearchBaseUrlCreate = (
edit: boolean,
editDefinitionId: string,
fromInContext: boolean
) => {
let baseUrl;
Expand All @@ -86,7 +88,7 @@ export const getSavedSearchBaseUrlCreate = (
}
if (edit) {
return baseUrl.replace(
'opendistro_kibana_reports#/edit',
`opendistro_kibana_reports#/edit/${editDefinitionId}`,
'discover#/view/'
);
} else if (fromInContext) {
Expand Down
8 changes: 4 additions & 4 deletions kibana-reports/target/public/.kbn-optimizer-cache
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/context_menu/context_menu.js": 1605143590359.2415,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/main_utils.tsx": 1605048331306.86,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/main.tsx": 1605200994044.0496,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/report_definition_details/report_definition_details.tsx": 1605211619125.6868,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/report_definition_details/report_definition_details.tsx": 1605213302571.7976,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/report_definitions_table.tsx": 1605047966680.2158,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/report_details/report_details.tsx": 1605138071515.7131,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/main/reports_table.tsx": 1605047966683.0679,
Expand All @@ -99,11 +99,11 @@
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/delivery/delivery.tsx": 1605047966689.483,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/delivery/email.tsx": 1605048331312.1157,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/delivery/index.ts": 1605047966691.1199,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/edit/edit_report_definition.tsx": 1605138071517.7808,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/edit/edit_report_definition.tsx": 1605221773260.5664,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/index.ts": 1605047966697.278,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_constants.tsx": 1605047966698.8801,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx": 1605125632993.7512,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx": 1605047966698.138,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings_helpers.tsx": 1605224950291.7615,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/report_settings.tsx": 1605224964873.8975,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_settings/time_range.tsx": 1605047966700.3855,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_trigger/index.ts": 1605047966702.629,
"/Users/davidcui/kibana-master/kibana/plugins/kibana-reports/public/components/report_definitions/report_trigger/report_trigger_constants.tsx": 1605125243795.44,
Expand Down
26 changes: 17 additions & 9 deletions kibana-reports/target/public/1.plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kibana-reports/target/public/1.plugin.js.map

Large diffs are not rendered by default.