Skip to content

Commit 444f5db

Browse files
committed
ACP2E-3033: Unable to export more than 200 orders
1 parent 7cabfb4 commit 444f5db

File tree

2 files changed

+157
-15
lines changed
  • app/code/Magento/Ui/view/base/web/js/grid
  • dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid

2 files changed

+157
-15
lines changed

app/code/Magento/Ui/view/base/web/js/grid/export.js

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,32 +105,62 @@ define([
105105
});
106106
},
107107

108+
/**
109+
* Redirect to built option url.
110+
*/
111+
applyOption: function () {
112+
const option = this.getActiveOption();
113+
114+
this.postRequest(option);
115+
},
116+
108117
/**
109118
* Build option url.
110119
*
111120
* @param {Object} option
112121
* @returns {String}
113122
*/
114-
buildOptionUrl: function (option) {
115-
var params = this.getParams();
123+
postRequest: function (option) {
124+
let params = this.getParams(),
125+
data;
116126

117127
if (!params) {
118128
return 'javascript:void(0);';
119129
}
120130

121-
return option.url + '?' + $.param(params);
122-
//TODO: MAGETWO-40250
123-
},
124-
125-
/**
126-
* Redirect to built option url.
127-
*/
128-
applyOption: function () {
129-
var option = this.getActiveOption(),
130-
url = this.buildOptionUrl(option);
131-
132-
location.href = url;
133-
131+
data = $.param(params);
132+
$.ajax({
133+
url: option.url,
134+
type: 'POST',
135+
data: data,
136+
showLoader: true,
137+
xhrFields: {
138+
responseType: 'blob'
139+
},
140+
success: function (exportedData, status, xhr) {
141+
let a = document.createElement('a'),
142+
blob,
143+
url,
144+
disposition = xhr.getResponseHeader('Content-Disposition'),
145+
matches = disposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/),
146+
fileName = matches && matches[1] ? matches[1].replace(/['"]/g, '') : '';
147+
148+
a.style = 'display: none';
149+
document.body.appendChild(a);
150+
151+
blob = new Blob([exportedData], {
152+
type: 'octet/stream'
153+
});
154+
155+
url = window.URL.createObjectURL(blob);
156+
157+
a.href = url;
158+
a.download = fileName;
159+
a.click();
160+
161+
window.URL.revokeObjectURL(url);
162+
}
163+
});
134164
}
135165
});
136166
});
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/************************************************************************
2+
* Copyright 2024 Adobe
3+
* All Rights Reserved.
4+
*
5+
* NOTICE: All information contained herein is, and remains
6+
* the property of Adobe and its suppliers, if any. The intellectual
7+
* and technical concepts contained herein are proprietary to Adobe
8+
* and its suppliers and are protected by all applicable intellectual
9+
* property laws, including trade secret and copyright laws.
10+
* Dissemination of this information or reproduction of this material
11+
* is strictly forbidden unless prior written permission is obtained
12+
* from Adobe.
13+
* ***********************************************************************
14+
*/
15+
16+
/* eslint-disable max-nested-callbacks */
17+
define([
18+
'jquery',
19+
'underscore',
20+
'uiElement',
21+
'Magento_Ui/js/grid/export'
22+
], function ($, _, Element, ExportComponent) {
23+
'use strict';
24+
25+
describe('Magento_Ui/js/grid/export', function () {
26+
var obj;
27+
28+
beforeEach(function () {
29+
// Mock for selections
30+
var selectionsMock = {
31+
getSelections: function () {
32+
return {
33+
excludeMode: false,
34+
params: {
35+
filters: 'filters',
36+
search: 'search',
37+
namespace: 'namespace'
38+
},
39+
selected: [1, 2, 3]
40+
};
41+
}
42+
};
43+
44+
// Initialize the instance with the mock
45+
obj = new ExportComponent({
46+
ns: 'testNamespace', // Define ns here
47+
options: [
48+
{value: 'csv', url: '/export/csv'},
49+
{value: 'xml', url: '/export/xml'}
50+
],
51+
additionalParams: {foo: 'bar'},
52+
imports: {}, // Ensure imports is initialized
53+
selections: selectionsMock // Pass the mock
54+
});
55+
56+
// Manually set the selections observable to the mock
57+
obj.selections(selectionsMock);
58+
59+
// Mocking $.ajax to avoid actual server calls
60+
spyOn($, 'ajax').and.callFake(function (options) {
61+
if (options.url === '/export/csv') {
62+
options.success('csvData');
63+
} else if (options.url === '/export/xml') {
64+
options.success('xmlData');
65+
}
66+
});
67+
});
68+
69+
it('should initialize correctly', function () {
70+
expect(obj.template).toEqual('ui/grid/exportButton');
71+
expect(obj.selectProvider).toEqual('ns = testNamespace, index = ids');
72+
});
73+
74+
it('should initialize checked value', function () {
75+
obj.initChecked();
76+
expect(obj.checked()).toEqual('csv');
77+
});
78+
79+
it('should observe checked property', function () {
80+
spyOn(obj, 'observe').and.callThrough();
81+
obj.initObservable();
82+
expect(obj.observe).toHaveBeenCalledWith('checked');
83+
});
84+
85+
it('should return active option', function () {
86+
obj.checked('xml');
87+
let option = obj.getActiveOption();
88+
89+
expect(option.value).toEqual('xml');
90+
});
91+
92+
it('should apply the option and call postRequest', function () {
93+
spyOn(obj, 'getActiveOption').and.returnValue({ url: 'test-url' });
94+
spyOn(obj, 'postRequest');
95+
obj.applyOption();
96+
expect(obj.postRequest).toHaveBeenCalledWith({ url: 'test-url' });
97+
});
98+
99+
it('should post request correctly', function () {
100+
spyOn(obj, 'getParams').and.returnValue({ param1: 'value1' });
101+
102+
obj.postRequest({ url: 'test-url' });
103+
104+
expect($.ajax).toHaveBeenCalledWith(jasmine.objectContaining({
105+
url: 'test-url',
106+
type: 'POST',
107+
data: $.param({ param1: 'value1' }),
108+
showLoader: true
109+
}));
110+
});
111+
});
112+
});

0 commit comments

Comments
 (0)