forked from RedHatInsights/curiosity-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatformHelpers.js
More file actions
55 lines (46 loc) · 1.37 KB
/
Copy pathplatformHelpers.js
File metadata and controls
55 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { PLATFORM_API_EXPORT_STATUS_TYPES } from './platformConstants';
import { helpers } from '../../common';
/**
* @memberof Platform
* @module PlatformHelpers
*/
/**
* Normalize a product id pulled from an export name. Fallback filtering for product identifiers.
*
* @param {string} str
* @returns {undefined|string}
*/
const getExportProductId = str => {
const attemptId = str?.replace(`${helpers.CONFIG_EXPORT_SERVICE_NAME_PREFIX}-`, '')?.trim();
if (attemptId === str) {
return undefined;
}
return attemptId;
};
/**
* Normalize an export status to be either `pending`, `complete`, or `failed`.
*
* @param {PLATFORM_API_EXPORT_STATUS_TYPES} str
* @returns {string}
*/
const getExportStatus = str => {
let updatedStatus;
switch (str) {
case PLATFORM_API_EXPORT_STATUS_TYPES.PARTIAL:
case PLATFORM_API_EXPORT_STATUS_TYPES.FAILED:
updatedStatus = PLATFORM_API_EXPORT_STATUS_TYPES.FAILED;
break;
case PLATFORM_API_EXPORT_STATUS_TYPES.COMPLETE:
updatedStatus = PLATFORM_API_EXPORT_STATUS_TYPES.COMPLETE;
break;
case PLATFORM_API_EXPORT_STATUS_TYPES.RUNNING:
default:
updatedStatus = PLATFORM_API_EXPORT_STATUS_TYPES.PENDING;
}
return updatedStatus;
};
const platformHelpers = {
getExportProductId,
getExportStatus
};
export { platformHelpers as default, platformHelpers, getExportProductId, getExportStatus };