Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AN-370] When converting submission to a TSV, access data by the headers #5230

Merged
merged 8 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions src/libs/ajax/workspaces/workspace-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,20 @@ export interface BucketUsageResponse {
usageInBytes: number;
lastUpdated?: string;
}

export interface Workflow {
cost: number | string;
inputResolutions: {
value: any;
error: string;
inputName: string;
}[];
messages: string[];
status: string;
statusLastChangedDate: string;
workflowEntity: {
entityType: string;
entityName: string;
};
workflowId: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getWorkflowInputSuggestionsForAttributesOfSetMembers } from 'src/libs/workflow-utils';
import FileSaver from 'file-saver';
import { downloadWorkflows, getWorkflowInputSuggestionsForAttributesOfSetMembers } from 'src/libs/workflow-utils';

describe('getWorkflowInputSuggestionsForAttributesOfSetMembers', () => {
it('returns workflow input expressions for attributes of entities reference by selected data', () => {
Expand Down Expand Up @@ -153,3 +154,56 @@ describe('getWorkflowInputSuggestionsForAttributesOfSetMembers', () => {
).toEqual(['this.issues.description', 'this.issues.id', 'this.issues.priority', 'this.issues.severity']);
});
});

jest.mock('file-saver', () => ({
saveAs: jest.fn(),
}));

describe('downloadWorkflows', () => {
it('should contain the specified columns in the TSV', async () => {
const mockWorkflows = [
{
workflowId: 'wf1',
inputResolutions: [],
messages: [],
status: 'Succeeded',
statusLastChangedDate: '2023-01-01T00:00:00Z',
workflowEntity: { entityType: 'sample', entityName: 'sample1' },
cost: 1.71972,
asText: 'sample text',
},
{
workflowId: 'wf2',
inputResolutions: [],
messages: [],
status: 'Failed',
statusLastChangedDate: '2023-01-01T00:00:00Z',
workflowEntity: { entityType: 'sample', entityName: 'sample1' },
cost: 'N/A',
asText: 'sample text',
},
];

downloadWorkflows(mockWorkflows, 'test');

const tsvContent = FileSaver.saveAs.mock.calls[0][0] as Blob;
const tsvText = await tsvContent.text();
const tsvLines = tsvText.split('\n');
const headers = tsvLines[0].split('\t');

const expectedColumns = [
'workflowId',
'inputResolutions',
'messages',
'status',
'statusLastChangedDate',
'workflowEntity',
'cost',
'asText',
];

expectedColumns.forEach((column) => {
expect(headers).toContain(column);
});
});
});
13 changes: 8 additions & 5 deletions src/libs/workflow-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FileSaver from 'file-saver';
import _ from 'lodash/fp';
import { Workflow } from 'src/libs/ajax/workspaces/workspace-models';
import * as Utils from 'src/libs/utils';

export const workflowNameValidation = () => {
Expand Down Expand Up @@ -53,13 +54,15 @@ export const downloadIO = (io, filename) => {
FileSaver.saveAs(blob, `${filename}.json`);
};

export const downloadWorkflows = (rows, filename) => {
export const downloadWorkflows = (rows: Workflow[], filename: string) => {
const headers = _.keys(_.head(rows));

const stringifiedRows = _.flow(
_.sortBy('workflowEntity'),
_.map((row) => _.map((v) => (_.isObject(v) ? JSON.stringify(v) : v), _.values(row)))
)(rows);
const stringifiedRows = _.map((row: Workflow) => {
lucymcnatt marked this conversation as resolved.
Show resolved Hide resolved
return _.map((header) => {
const value = row[header];
return _.isObject(value) ? JSON.stringify(value) : value;
}, headers);
}, _.sortBy('workflowEntity', rows));

const rowsAndHeaders = [headers, ...stringifiedRows];

Expand Down
Loading