Skip to content

Commit f42e164

Browse files
Programatic download/export for workflow history (#546)
* handle export for cross origin * lint fix * fix href for export btn * remove wrong query params to the export get * change export link to use onclick * fix blob content * parse status query param to int (#544) Co-authored-by: Assem Hafez <assem.a.hafez@gmail.com> * move chai-spies to dev dependecies * fix lint * preserve event target reference in the promise context * fix lint --------- Co-authored-by: Assem Hafez <137278762+Assem-Uber@users.noreply.github.com>
1 parent 9bc4e2f commit f42e164

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed

client/containers/workflow-history/component.vue

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import {
4343
SelectInput,
4444
} from '~components';
4545
46+
import { httpService } from '~services';
47+
4648
export default {
4749
name: 'history',
4850
data() {
@@ -88,7 +90,6 @@ export default {
8890
'workflowHistoryEventHighlightList',
8991
'workflowHistoryEventHighlightListEnabled',
9092
'workflowId',
91-
'origin',
9293
],
9394
created() {
9495
this.onResizeWindow = debounce(() => {
@@ -314,6 +315,21 @@ export default {
314315
});
315316
}
316317
},
318+
exportHistory(e) {
319+
const target = e.target;
320+
321+
httpService.get(this.baseAPIURL + '/export').then(historyJson => {
322+
const blob = new Blob([JSON.stringify(historyJson)], {
323+
type: 'application/json',
324+
});
325+
326+
target.href = window.URL.createObjectURL(blob);
327+
target.download = this.exportFilename;
328+
target.click();
329+
});
330+
331+
return false;
332+
},
317333
},
318334
watch: {
319335
eventId(eventId) {
@@ -398,10 +414,7 @@ export default {
398414
class="show-timeline-btn"
399415
>{{ graphView === GRAPH_VIEW_TIMELINE ? 'hide' : 'show' }} timeline</a
400416
>
401-
<a
402-
class="export"
403-
:href="origin + baseAPIURL + '/export'"
404-
:download="exportFilename"
417+
<a class="export" href="#" @click.once.prevent="exportHistory"
405418
>Export</a
406419
>
407420
</div>

client/containers/workflow-history/connector.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
import { connect } from 'vuex-connect';
2323
import { WORKFLOW_EXECUTION_PENDING_TASK_COUNT } from '../workflow/getter-types';
24-
import { DOMAIN_CROSS_ORIGIN } from '../domain/getter-types';
2524

2625
const gettersToProps = {
2726
pendingTaskCount: WORKFLOW_EXECUTION_PENDING_TASK_COUNT,
28-
origin: DOMAIN_CROSS_ORIGIN,
2927
};
3028

3129
const stateToProps = {

client/test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ chai.should();
7272
chai.use(require('chai-dom'));
7373
chai.use(require('chai-string'));
7474
chai.use(require('chai-things'));
75+
chai.use(require('chai-spies'));
7576

7677
require('nathanboktae-browser-test-utils');
7778

client/test/scenario.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,14 @@ Scenario.prototype.withFullHistory = function withFullHistory(events, options) {
365365
.withHistory(parsedEvents.slice(third + third), false, options);
366366
};
367367

368+
Scenario.prototype.withExportHistory = function withExportHistory(events) {
369+
const jsonHistoryEvents = getFixture('history.emailRun1', events);
370+
371+
this.api.getOnce(`${this.execApiBase()}/export`, jsonHistoryEvents);
372+
373+
return this;
374+
};
375+
368376
Scenario.prototype.withQuery = function withQuery(query) {
369377
this.api.getOnce(
370378
`${this.execApiBase()}/query`,

client/test/workflow.test.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,13 @@ describe('Workflow', () => {
505505
...o,
506506
});
507507

508-
scenario.withFullHistory(opts.events);
508+
scenario.withFullHistory(opts.events).withExportHistory(opts.events);
509509

510510
const historyEl = await scenario
511511
.render(opts.attach)
512512
.waitUntilExists('section.execution.ready');
513513

514-
return [historyEl, scenario];
514+
return [historyEl, scenario, opts];
515515
}
516516
it('should pick default view format from localstorage if exists ', async function test() {
517517
localStorage.setItem('ci-test:history-viewing-format', 'json');
@@ -570,19 +570,23 @@ describe('Workflow', () => {
570570
});
571571

572572
it('should allow downloading the full history via export', async function test() {
573-
const [, scenario] = await historyTest(this.test);
573+
const [, scenario, opts] = await historyTest(this.test);
574574
const exportEl = await scenario.vm.$el.waitUntilExists(
575575
'section.history .controls a.export'
576576
);
577+
const downloadLink = 'javascript:void(0);'; //prevent createing a redirectable link
577578

578-
exportEl.should.have.attr(
579-
'href',
580-
'http://localhost:8090/api/domains/ci-test/workflows/email-daily-summaries/emailRun1/export'
581-
);
582-
exportEl.should.have.attr(
583-
'download',
584-
'email daily summaries - emailRun1.json'
585-
);
579+
chai.spy.on(window.URL, 'createObjectURL', () => downloadLink);
580+
exportEl.trigger('click');
581+
582+
await retry(() => {
583+
window.URL.createObjectURL.should.have.been.called();
584+
exportEl.should.have.attr('href', downloadLink);
585+
exportEl.should.have.attr(
586+
'download',
587+
'email daily summaries - emailRun1.json'
588+
);
589+
});
586590
});
587591

588592
describe('Compact View', function describeTest() {

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"babel-jest": "^24.9.0",
110110
"chai": "^4.1.2",
111111
"chai-dom": "^1.7.0",
112+
"chai-spies": "^1.1.0",
112113
"chai-string": "^1.5.0",
113114
"chai-things": "^0.2.0",
114115
"eslint": "^7.32.0",

0 commit comments

Comments
 (0)