Skip to content

Commit

Permalink
[Bug fix] in-context menu download UI (opendistro-for-elasticsearch#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongnansu committed Dec 7, 2020
1 parent 9572199 commit 45d42c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 50 deletions.
31 changes: 6 additions & 25 deletions kibana-reports/public/components/context_menu/context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,18 @@ import {

const replaceQueryURL = () => {
let url = location.pathname + location.hash;
let timeString = url.substring(
url.lastIndexOf('time:'),
url.lastIndexOf('))')
let [, fromDateString, toDateString] = url.match(
/time:\(from:(.+),to:(.+?)\)/
);
if (url.includes('visualize') || url.includes('discover')) {
timeString = url.substring(url.lastIndexOf('time:'), url.indexOf('))'));
}

let fromDateString = timeString.substring(
timeString.lastIndexOf('from:') + 5,
timeString.lastIndexOf(',')
);

fromDateString = fromDateString.replace(/[']+/g, '');
let fromDateFormat = dateMath.parse(fromDateString);

let toDateString = timeString.substring(
timeString.lastIndexOf('to:') + 3,
timeString.length
);
// convert time range to from date format in case time range is relative
const fromDateFormat = dateMath.parse(fromDateString);
toDateString = toDateString.replace(/[']+/g, '');
let toDateFormat = dateMath.parse(toDateString);

// replace to and from dates with absolute date

url = url.replace(
fromDateString + '))',
"'" + fromDateFormat.toISOString() + "'"
);

url = url.replace(fromDateString, "'" + fromDateFormat.toISOString() + "'");
url = url.replace(
toDateString + '))',
"'" + toDateFormat.toISOString() + "'))"
Expand Down Expand Up @@ -139,8 +121,7 @@ const generateInContextReport = (
} else {
if (response.status === 403) {
addSuccessOrFailureToast('permissionsFailure');
}
else {
} else {
addSuccessOrFailureToast('failure');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
reportGenerationInProgressModal,
reportGenerationSuccess,
reportGenerationFailure,
permissionsMissingOnGeneration
permissionsMissingOnGeneration,
} from './context_menu_ui';

const getReportSourceURL = (baseURI) => {
Expand Down Expand Up @@ -51,31 +51,14 @@ export const contextMenuViewReports = () =>
window.location.assign('opendistro_kibana_reports#/');

export const getTimeFieldsFromUrl = () => {
let url = window.location.href;
let timeString = url.substring(
url.lastIndexOf('time:'),
url.lastIndexOf('))')
);
if (url.includes('visualize') || url.includes('discover')) {
timeString = url.substring(url.lastIndexOf('time:'), url.indexOf('))'));
}
const url = window.location.href;

let fromDateString = timeString.substring(
timeString.lastIndexOf('from:') + 5,
timeString.lastIndexOf(',')
let [, fromDateString, toDateString] = url.match(
/time:\(from:(.+),to:(.+?)\)/
);

// remove extra quotes if the 'from' date is absolute time
fromDateString = fromDateString.replace(/[']+/g, '');

// convert time range to from date format in case time range is relative
let fromDateFormat = dateMath.parse(fromDateString);

let toDateString = timeString.substring(
timeString.lastIndexOf('to:') + 3,
timeString.length
);

const fromDateFormat = dateMath.parse(fromDateString);
toDateString = toDateString.replace(/[']+/g, '');
let toDateFormat = dateMath.parse(toDateString);

Expand Down Expand Up @@ -121,7 +104,9 @@ export const addSuccessOrFailureToast = (status) => {
} else if (status === 'permissionsFailure') {
generateInProgressToast.innerHTML = permissionsMissingOnGeneration();
setTimeout(function () {
document.getElementById('permissionsMissingErrorToast').style.display = 'none';
document.getElementById(
'permissionsMissingErrorToast'
).style.display = 'none';
}, 6000);
}
generateToast[0].appendChild(generateInProgressToast.children[0]);
Expand Down
2 changes: 1 addition & 1 deletion kibana-reports/server/routes/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export enum DELIVERY_TYPE {

export enum SELECTOR {
dashboard = '#dashboardViewport',
visualization = '.visEditor__visualization',
visualization = '.visEditor__content',
topNavBar = '#globalHeaderBars',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const createVisualReport = async (
return { timeCreated, dataUrl: buffer.toString('base64'), fileName };
};

export const composeReportHtml = (
const composeReportHtml = (
header: string,
footer: string,
screenshot: string
Expand Down

0 comments on commit 45d42c9

Please sign in to comment.