Skip to content

Commit 330b33c

Browse files
jvigliottadavetsay
andauthored
Updating Historical Export Filenames to use the view name instead of the first child endpoint name (#321)
Co-authored-by: David Tsay <3614296+davetsay@users.noreply.github.com>
1 parent 1294dcc commit 330b33c

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/exportDataAction/ExportDataAction.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class ExportDataAction {
1818
this.group = 'view';
1919
this.priority = 1;
2020
this.validTypes = validTypes;
21-
this.sessionService = SessionService();
2221

2322
this.openmct = openmct;
2423
}
@@ -63,12 +62,16 @@ class ExportDataAction {
6362
);
6463

6564
if (filteredComposition.length > 0) {
66-
await this.runExportTask(filteredComposition);
65+
await this.runExportTask(filteredComposition, domainObject.name);
6766
} else {
6867
this.openmct.notifications.info('No historical data to export');
6968
}
7069
}
7170

71+
getHistoricalSessionFilter() {
72+
return SessionService().getHistoricalSessionFilter();
73+
}
74+
7275
historicalFilterString(sessionFilter) {
7376
let filterString = formatNumberSequence(sessionFilter.numbers);
7477

@@ -78,9 +81,18 @@ class ExportDataAction {
7881
return `${sessionFilter.host}_${filterString}`;
7982
}
8083

81-
runExportTask(domainObjects) {
82-
let filename = domainObjects[0].name;
83-
const sessionFilter = this.sessionService.getHistoricalSessionFilter();
84+
/**
85+
* Runs the export task for the given domain objects with an optional name.
86+
* If no name is provided, uses the name of the first domain object.
87+
* Appends session filter information to the filename if a session filter exists.
88+
*
89+
* @param {Array<Object>} domainObjects - Array of domain objects to export
90+
* @param {string} [name] - Optional name for the export file. If not provided, uses the name of the first domain object
91+
* @returns {Promise} A promise that resolves when the export task is complete
92+
*/
93+
runExportTask(domainObjects, name) {
94+
let filename = name ?? domainObjects[0].name;
95+
const sessionFilter = this.getHistoricalSessionFilter();
8496

8597
if (sessionFilter) {
8698
filename = `${filename} - ${this.historicalFilterString(sessionFilter)}`;

src/exportDataAction/ExportDataActionSpec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ define(['./ExportDataAction'], (ExportDataActionModule) => {
7777
mockOpenmct.notifications.progress.and.returnValue(mockNotification);
7878

7979
exportDataAction = new ExportDataAction(mockOpenmct, ['validType']);
80+
spyOn(exportDataAction, 'getHistoricalSessionFilter').and.callFake(() => {
81+
return {
82+
host: 'test-host',
83+
numbers: [1, 2, 3, 4, 5]
84+
};
85+
});
8086
});
8187

8288
it('applies to objects with a valid type', () => {
@@ -114,7 +120,6 @@ define(['./ExportDataAction'], (ExportDataActionModule) => {
114120
done();
115121
}
116122
};
117-
118123
spyOn(exportDataAction, 'runExportTask').and.callThrough();
119124
spyOn(exportDataAction, 'exportCompositionData').and.callThrough();
120125
mockTarget = singular ? mockTelemetryObject : mockTelemetryObjectWithComposition;
@@ -160,10 +165,16 @@ define(['./ExportDataAction'], (ExportDataActionModule) => {
160165
it('triggers a CSV export for one object', () => {
161166
expect(exportDataAction.runExportTask).toHaveBeenCalled();
162167
});
168+
it('checks for historical session filter', () => {
169+
expect(exportDataAction.getHistoricalSessionFilter).toHaveBeenCalled();
170+
});
163171
} else {
164172
it('triggers a CSV export for each object', () => {
165173
expect(exportDataAction.exportCompositionData).toHaveBeenCalled();
166174
});
175+
it('checks for historical session filter', () => {
176+
expect(exportDataAction.getHistoricalSessionFilter).toHaveBeenCalled();
177+
});
167178
}
168179
});
169180

0 commit comments

Comments
 (0)