Skip to content

Commit

Permalink
Merge pull request #2534 from reportportal/Attachment-improvements-5.3.4
Browse files Browse the repository at this point in the history
Attachment improvements 5.3.4
  • Loading branch information
AmsterGet authored Dec 4, 2020
2 parents 93ea3ea + 3a4e0e6 commit 2a3e08f
Show file tree
Hide file tree
Showing 27 changed files with 558 additions and 149 deletions.
2 changes: 2 additions & 0 deletions app/localization/translated/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
"AsyncAutocomplete.notFound": "Нічога не знойдзена",
"AttachmentModal.errorFileStructure": "Няправільная структура файла",
"AttachmentModal.title": "Укладанне",
"Common.openInNewTab": "Адкрыць у новай ўкладцы",
"Common.download": "Спампаваць",
"Attachments.noAttachmentsMessage": "Няма ўкладанняў для адлюстравання",
"AttributeEditor.attributeKeyLengthHint": "Ключ атрыбуту павінен мець памер ад 1 да 128",
"AttributeEditor.attributeValueLengthHint": "Значэнне атрыбуту павінна мець памер ад 1 да 128",
Expand Down
3 changes: 2 additions & 1 deletion app/localization/translated/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"AsyncAutocomplete.notFound": "Ничего не найдено",
"AttachmentModal.errorFileStructure": "Неверная структура файла",
"AttachmentModal.title": "Вложение",
"Attachments.noAttachmentsMessage": "Нет вложений для отображения",
"Common.openInNewTab": "Открыть в новой вкладке",
"Common.download": "Скачать",
"AttributeEditor.attributeKeyLengthHint": "Ключ атрибута должен быть длиной от 1 до 128",
"AttributeEditor.attributeValueLengthHint": "Значение атрибута должно быть длиной от 1 до 128",
"AttributeEditor.uniqueAttributeKeyHint": "Ключ атрибута должен быть уникальным",
Expand Down
2 changes: 2 additions & 0 deletions app/localization/translated/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
"AsyncAutocomplete.notFound": "Нічого не знайдено",
"AttachmentModal.errorFileStructure": "Некоректна структура файлу",
"AttachmentModal.title": "Вкладення",
"Common.openInNewTab": "Відкрити в новій вкладці",
"Common.download": "Завантажити",
"Attachments.noAttachmentsMessage": "Немає вкладень для відображення",
"AttributeEditor.attributeKeyLengthHint": "Ключ атрибута повинен бути довжиною від 1 до 128",
"AttributeEditor.attributeValueLengthHint": "Значення атрибута повинно бути довжиною від 1 до 128",
Expand Down
1 change: 1 addition & 0 deletions app/src/common/constants/fileTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const CSV = 'csv';
export const PHP = 'php';
export const HAR = 'har';
export const TXT = 'txt';
export const PDF = 'pdf';
export const ZIP = 'zip';
export const RAR = 'rar';
export const TGZ = 'tgz';
Expand Down
8 changes: 8 additions & 0 deletions app/src/common/constants/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,12 @@ export const COMMON_LOCALE_KEYS = defineMessages({
id: 'Common.proceedValidItems',
defaultMessage: 'Proceed Valid Items',
},
DOWNLOAD: {
id: 'Common.download',
defaultMessage: 'Download',
},
OPEN_IN_NEW_TAB: {
id: 'Common.openInNewTab',
defaultMessage: 'Open in new tab',
},
});
13 changes: 13 additions & 0 deletions app/src/common/img/open-in-inline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions app/src/common/utils/downloadFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

import { fetch } from 'common/utils/fetch';

export const downloadFile = (url) => {
export const downloadFile = (url, fileNameFallback) => {
fetch(url, { responseType: 'blob' }, true).then((response) => {
const data = response.data;
const attachmentHeader = response.headers['content-disposition'];
const fileName = /filename=(.*?)(?:\s|$)/.exec(attachmentHeader)[1];
const extractedFileName = /filename=(.*?)(?:\s|$)/.exec(attachmentHeader);
const fileName = extractedFileName ? extractedFileName[1] : fileNameFallback;
const objectURL = URL.createObjectURL(data);
if ('msSaveOrOpenBlob' in navigator) {
navigator.msSaveOrOpenBlob(data, fileName);
Expand Down
45 changes: 32 additions & 13 deletions app/src/components/main/analytics/events/logPageEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,38 @@ export const LOG_PAGE_EVENTS = {
label: 'Sort logs',
},
ATTACHMENT_IN_LOG_MSG: {
category: LOG_PAGE,
action: 'Click on Attachment in Log Message',
label: 'Open Attachment',
OPEN_IN_MODAL: {
category: LOG_PAGE,
action: 'Click on Attachment in Log Message',
label: 'Open Attachment in modal',
},
DOWNLOAD: {
category: LOG_PAGE,
action: 'Click on Download Attachment icon in Log Message',
label: 'Download Attachment',
},
OPEN_IN_NEW_TAB: {
category: LOG_PAGE,
action: 'Click on Open Attachment in new tab icon in Log Message',
label: 'Open Attachment in new browser tab',
},
},
ATTACHMENT_IN_CAROUSEL: {
OPEN_IN_MODAL: {
category: LOG_PAGE,
action: 'Click on Attachment in Attachments section',
label: 'Open Attachment in modal',
},
DOWNLOAD: {
category: LOG_PAGE,
action: 'Click on Download Attachment icon in Attachments section',
label: 'Download Attachment',
},
OPEN_IN_NEW_TAB: {
category: LOG_PAGE,
action: 'Click on Open Attachment in new tab icon in Attachments section',
label: 'Open Attachment in new browser tab',
},
},
EXPAND_LOG_MSG: {
category: LOG_PAGE,
Expand Down Expand Up @@ -159,11 +188,6 @@ export const LOG_PAGE_EVENTS = {
action: 'Click on icon Next Attachment',
label: 'Show Next Attachment',
},
ATTACHMENT_CLICK: {
category: LOG_PAGE,
action: 'Click on opened Attachment',
label: 'Arise modal with Attachment',
},
ATTACHMENT_THUMBNAIL: {
category: LOG_PAGE,
action: 'Click on thumbnail of Attachment',
Expand All @@ -174,11 +198,6 @@ export const LOG_PAGE_EVENTS = {
action: 'Click on icon Close on Modal Attachment',
label: 'Close Modal Attachment',
},
ROTATE_ICON_ATTACHMENT_MODAL: {
category: LOG_PAGE,
action: 'Click on icon Rotate on Modal Attachment',
label: 'Rotate Attachment',
},
CLOSE_BTN_ATTACHMENT_MODAL: {
category: LOG_PAGE,
action: 'Click on Btn Close on Modal Attachment',
Expand Down
24 changes: 18 additions & 6 deletions app/src/controllers/log/attachments/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

import {
FETCH_ATTACHMENTS_CONCAT_ACTION,
OPEN_ATTACHMENT_ACTION,
CLEAR_ATTACHMENTS_ACTION,
FETCH_FIRST_ATTACHMENTS_ACTION,
SET_ACTIVE_ATTACHMENT_ACTION,
DOWNLOAD_ATTACHMENT_ACTION,
OPEN_ATTACHMENT_IN_MODAL_ACTION,
OPEN_ATTACHMENT_IN_BROWSER_ACTION,
} from './constants';

export const fetchAttachmentsConcatAction = (payload) => ({
Expand All @@ -36,12 +38,22 @@ export const clearAttachmentsAction = () => ({
type: CLEAR_ATTACHMENTS_ACTION,
});

export const openAttachmentAction = (payload) => ({
type: OPEN_ATTACHMENT_ACTION,
payload,
});

export const setActiveAttachmentAction = (attachmentId) => ({
type: SET_ACTIVE_ATTACHMENT_ACTION,
payload: attachmentId,
});

export const openAttachmentInModalAction = (payload) => ({
type: OPEN_ATTACHMENT_IN_MODAL_ACTION,
payload,
});

export const downloadAttachmentAction = (payload) => ({
type: DOWNLOAD_ATTACHMENT_ACTION,
payload,
});

export const openAttachmentInBrowserAction = (id) => ({
type: OPEN_ATTACHMENT_IN_BROWSER_ACTION,
payload: id,
});
33 changes: 32 additions & 1 deletion app/src/controllers/log/attachments/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ import txt from 'common/img/attachments/txt.svg';
import archive from 'common/img/attachments/archive.svg';
import * as FILE_TYPES from 'common/constants/fileTypes';

export const ALL_ALLOWED = '*';
export const ATTACHMENTS_NAMESPACE = 'log/attachments';
export const FETCH_ATTACHMENTS_CONCAT_ACTION = 'fetchAttachmentsConcatAction';
export const CLEAR_ATTACHMENTS_ACTION = 'clearAttachmentsAction';
export const OPEN_ATTACHMENT_ACTION = 'openAttachmentAction';
export const ATTACHMENT_HAR_FILE_MODAL_ID = 'attachmentHarFileModal';
export const ATTACHMENT_CODE_MODAL_ID = 'attachmentCodeModal';
export const FETCH_FIRST_ATTACHMENTS_ACTION = 'fetchFirstAttachments';
export const SET_ACTIVE_ATTACHMENT_ACTION = 'setActiveAttachment';

export const DOWNLOAD_ATTACHMENT_ACTION = 'downloadAttachmentAction';
export const OPEN_ATTACHMENT_IN_MODAL_ACTION = 'openAttachmentInModalAction';
export const OPEN_ATTACHMENT_IN_BROWSER_ACTION = 'openAttachmentInBrowserAction';

export const FILE_PREVIEWS_MAP = {
[FILE_TYPES.XML]: xml,
[FILE_TYPES.JAVASCRIPT]: js,
Expand Down Expand Up @@ -68,5 +72,32 @@ export const FILE_MODAL_IDS_MAP = {
[FILE_TYPES.PHP]: ATTACHMENT_CODE_MODAL_ID,
[FILE_TYPES.HAR]: ATTACHMENT_HAR_FILE_MODAL_ID,
};

export const FILE_ACTIONS_MAP = {
[DOWNLOAD_ATTACHMENT_ACTION]: ALL_ALLOWED,
[OPEN_ATTACHMENT_IN_BROWSER_ACTION]: [
FILE_TYPES.XML,
FILE_TYPES.JAVASCRIPT,
FILE_TYPES.JSON,
FILE_TYPES.CSS,
FILE_TYPES.PHP,
FILE_TYPES.HAR,
FILE_TYPES.TXT,
FILE_TYPES.PLAIN,
FILE_TYPES.HTML,
FILE_TYPES.CSV,
FILE_TYPES.PDF,
FILE_TYPES.IMAGE,
],
[OPEN_ATTACHMENT_IN_MODAL_ACTION]: [
FILE_TYPES.XML,
FILE_TYPES.JAVASCRIPT,
FILE_TYPES.JSON,
FILE_TYPES.CSS,
FILE_TYPES.PHP,
FILE_TYPES.HAR,
],
};

export const DEFAULT_PAGE_SIZE = 6;
export const DEFAULT_LOADED_PAGES = 2;
14 changes: 12 additions & 2 deletions app/src/controllers/log/attachments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@
*/

export {
openAttachmentAction,
fetchAttachmentsConcatAction,
clearAttachmentsAction,
fetchFirstAttachmentsAction,
setActiveAttachmentAction,
openAttachmentInModalAction,
downloadAttachmentAction,
openAttachmentInBrowserAction,
} from './actionCreators';
export {
FILE_PREVIEWS_MAP,
FILE_MODAL_IDS_MAP,
ATTACHMENT_CODE_MODAL_ID,
ATTACHMENT_HAR_FILE_MODAL_ID,
ATTACHMENTS_NAMESPACE,
DOWNLOAD_ATTACHMENT_ACTION,
OPEN_ATTACHMENT_IN_BROWSER_ACTION,
OPEN_ATTACHMENT_IN_MODAL_ACTION,
} from './constants';
export { getFileIconSource, getAttachmentModalId, extractExtension } from './utils';
export {
getFileIconSource,
getAttachmentModalId,
extractExtension,
isFileActionAllowed,
} from './utils';
export {
attachmentItemsSelector,
attachmentsLoadingSelector,
Expand Down
Loading

0 comments on commit 2a3e08f

Please sign in to comment.