Skip to content

Commit

Permalink
feat(config): sw-2353 activate json export for products
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Jun 22, 2024
1 parent 96bd13b commit b67a8e1
Show file tree
Hide file tree
Showing 59 changed files with 2,190 additions and 774 deletions.
6 changes: 5 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ REACT_APP_UI_WINDOW_ID=curiosity

REACT_APP_AJAX_TIMEOUT=60000
REACT_APP_AJAX_CACHE=15000
REACT_APP_AJAX_POLL_INTERVAL=15000
REACT_APP_AJAX_POLL_INTERVAL=5000
REACT_APP_SELECTOR_CACHE=120000

REACT_APP_CONFIG_EXPORT_EXPIRE=86400000
REACT_APP_CONFIG_EXPORT_FILENAME=swatch_report_{0}
REACT_APP_CONFIG_EXPORT_SERVICE_NAME_PREFIX=swatch

REACT_APP_CONFIG_SERVICE_LOCALES_COOKIE=rh_locale
REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG=en-US
REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG_DESC=English
Expand Down
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ REACT_APP_ENV=test

REACT_APP_UI_VERSION=0.0.0.0000000

REACT_APP_AJAX_POLL_INTERVAL=1

REACT_APP_CONFIG_SERVICE_LOCALES=./locales/locales.json
REACT_APP_CONFIG_SERVICE_LOCALES_PATH=./locales/{{lng}}.json
13 changes: 9 additions & 4 deletions config/jest.setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,27 @@ global.renderHook = async (useHook = Function.prototype, options = {}) => {
let result;
let spyUseSelector;
let unmountHook;
let rerenderHook;

const Hook = () => {
result = useHook();
// eslint-disable-next-line react/prop-types
const Hook = ({ args = [] }) => {
result = useHook(...args);
return null;
};

const unmount = async () => {
await act(async () => unmountHook());
};

const rerender = (...args) => rerenderHook(<Hook args={args} />);

await act(async () => {
if (updatedOptions.state) {
spyUseSelector = jest.spyOn(reactRedux, 'useSelector').mockImplementation(_ => _(updatedOptions.state));
}
const { unmount: unmountRender } = await render(<Hook />);
const { unmount: unmountRender, rerender: rerenderRender } = await render(<Hook />);
unmountHook = unmountRender;
rerenderHook = rerenderRender;
});

if (updatedOptions.state) {
Expand All @@ -333,7 +338,7 @@ global.renderHook = async (useHook = Function.prototype, options = {}) => {
});
}

return { unmount, result: updatedResult, act };
return { unmount, rerender, result: updatedResult, act };
};

/**
Expand Down
27 changes: 26 additions & 1 deletion public/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@
},
"curiosity-toolbar": {
"button_displayName": "Search button for name",
"button_yes": "Yes",
"button_no": "No",
"clearFilters": "Reset filters",
"label": "",
"label_billing_provider": "",
Expand Down Expand Up @@ -360,9 +362,32 @@
"label_usage_Development/Test": "Development/Test",
"label_usage_Disaster Recovery": "Disaster Recovery",
"label_usage_Production": "Production",
"notifications_export_completed_description": "Downloading file {{fileName}}",
"notifications_export_completed_description_existing_completed": "{{completed}} completed report(s) are available. Would you like to continue and download?",
"notifications_export_completed_description_existing_completed_one": "{{completed}} completed report is available. Would you like to continue and download?",
"notifications_export_completed_description_existing_completed_other": "{{completed}} completed reports are available. Would you like to continue and download?",
"notifications_export_completed_description_existing_completed_pending": "{{completed}} completed and {{pending}} pending reports are available. Would you like to continue and download?",
"notifications_export_completed_description_existing_pending": "{{pending}} pending report(s) are available. Would you like to continue and download?",
"notifications_export_completed_description_existing_pending_one": "{{pending}} pending report is available. Would you like to continue and download?",
"notifications_export_completed_description_existing_pending_other": "{{pending}} pending reports are available. Would you like to continue and download?",
"notifications_export_completed_descriptionGlobal": "Download in progress",
"notifications_export_completed_descriptionGlobal_one": "{{count}} file download in progress",
"notifications_export_completed_descriptionGlobal_other": "{{count}} file downloads in progress",
"notifications_export_completed_title": "Report ready",
"notifications_export_completed_title_existing": "{{count}} existing report(s) are available",
"notifications_export_completed_title_existing_one": "{{count}} existing report is available",
"notifications_export_completed_title_existing_other": "{{count}} existing reports are available",
"notifications_export_completed_titleGlobal": "Existing report(s) ready",
"notifications_export_completed_titleGlobal_one": "Existing report ready",
"notifications_export_completed_titleGlobal_other": "Existing reports ready",
"notifications_export_error_description": "Closing report generator",
"notifications_export_error_title": "Report failed",
"notifications_export_pending_title": "Generating report in progress",
"notifications_export_pending_titleGlobal": "Continuing reports download",
"placeholder": "Select",
"placeholder_billing_provider": "Select purchased through",
"placeholder_export": "Export",
"placeholder_export": "Export data",
"placeholder_export_loading": "Export data is loading",
"placeholder_granularity": "Select date range",
"placeholder_groupVariant": "Select a variant",
"placeholder_rangedMonthly": "Select a month",
Expand Down
45 changes: 45 additions & 0 deletions src/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [~setStartOfDay(date)](#Helpers.module_Dates..setStartOfDay) ⇒ <code>Date</code>
* [~setEndOfMonth(date)](#Helpers.module_Dates..setEndOfMonth) ⇒ <code>Date</code>
* [~setRangedDateTime(params)](#Helpers.module_Dates..setRangedDateTime) ⇒ <code>Object</code>
* [~setMillisecondsFromDate(params)](#Helpers.module_Dates..setMillisecondsFromDate) ⇒ <code>Date</code>
* [~getRangedDateTime(granularity)](#Helpers.module_Dates..getRangedDateTime) ⇒ <code>Object</code>
* [~getRangedMonthDateTime(month, defaultLocale)](#Helpers.module_Dates..getRangedMonthDateTime) ⇒ <code>Object</code> \| <code>\*</code> \| <code>undefined</code>

Expand Down Expand Up @@ -193,6 +194,29 @@ Set a date range based on a granularity type.
</tr> </tbody>
</table>

<a name="Helpers.module_Dates..setMillisecondsFromDate"></a>

### Dates~setMillisecondsFromDate(params) ⇒ <code>Date</code>
Set milliseconds from date. Defaults to internal current date.

**Kind**: inner method of [<code>Dates</code>](#Helpers.module_Dates)
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>params</td><td><code>object</code></td><td></td>
</tr><tr>
<td>params.date</td><td><code>Date</code></td><td><p>The date to add milliseconds towards. Defaults to current date.</p>
</td>
</tr><tr>
<td>params.ms</td><td><code>number</code></td><td></td>
</tr> </tbody>
</table>

<a name="Helpers.module_Dates..getRangedDateTime"></a>

### Dates~getRangedDateTime(granularity) ⇒ <code>Object</code>
Expand Down Expand Up @@ -282,6 +306,9 @@ Download the debug log file.
* [~PROD_MODE](#Helpers.module_General..PROD_MODE) : <code>boolean</code>
* [~REVIEW_MODE](#Helpers.module_General..REVIEW_MODE) : <code>boolean</code>
* [~TEST_MODE](#Helpers.module_General..TEST_MODE) : <code>boolean</code>
* [~CONFIG_EXPORT_EXPIRE](#Helpers.module_General..CONFIG_EXPORT_EXPIRE) : <code>string</code>
* [~CONFIG_EXPORT_FILENAME](#Helpers.module_General..CONFIG_EXPORT_FILENAME) : <code>string</code>
* [~CONFIG_EXPORT_SERVICE_NAME_PREFIX](#Helpers.module_General..CONFIG_EXPORT_SERVICE_NAME_PREFIX) : <code>string</code>
* [~UI_DEPLOY_PATH_PREFIX](#Helpers.module_General..UI_DEPLOY_PATH_PREFIX) : <code>string</code>
* [~UI_DEPLOY_PATH_LINK_PREFIX](#Helpers.module_General..UI_DEPLOY_PATH_LINK_PREFIX) : <code>string</code>
* [~UI_DISABLED](#Helpers.module_General..UI_DISABLED) : <code>boolean</code>
Expand Down Expand Up @@ -399,6 +426,24 @@ Associated with using the NPM script "start:proxy". See dotenv config files for
Is test mode active.
Associated with running unit tests. See dotenv config files for activation.

**Kind**: inner constant of [<code>General</code>](#Helpers.module_General)
<a name="Helpers.module_General..CONFIG_EXPORT_EXPIRE"></a>

### General~CONFIG\_EXPORT\_EXPIRE : <code>string</code>
CONFIG export download file expiration.

**Kind**: inner constant of [<code>General</code>](#Helpers.module_General)
<a name="Helpers.module_General..CONFIG_EXPORT_FILENAME"></a>

### General~CONFIG\_EXPORT\_FILENAME : <code>string</code>
CONFIG export download file name. Extension is handled at the service level.

**Kind**: inner constant of [<code>General</code>](#Helpers.module_General)
<a name="Helpers.module_General..CONFIG_EXPORT_SERVICE_NAME_PREFIX"></a>

### General~CONFIG\_EXPORT\_SERVICE\_NAME\_PREFIX : <code>string</code>
CONFIG export "post" download name prefix, for consistency.

**Kind**: inner constant of [<code>General</code>](#Helpers.module_General)
<a name="Helpers.module_General..UI_DEPLOY_PATH_PREFIX"></a>

Expand Down
3 changes: 3 additions & 0 deletions src/common/__tests__/__snapshots__/dateHelpers.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DateHelpers should add milliseconds from date: add milliseconds 1`] = `2019-07-21T00:00:00.000Z`;

exports[`DateHelpers should have specific functions: dateHelpers 1`] = `
{
"currentDateTime": {
Expand Down Expand Up @@ -27,6 +29,7 @@ exports[`DateHelpers should have specific functions: dateHelpers 1`] = `
},
"setEndOfDay": [Function],
"setEndOfMonth": [Function],
"setMillisecondsFromDate": [Function],
"setRangedDateTime": [Function],
"setStartOfDay": [Function],
"timestampDayFormats": {
Expand Down
9 changes: 9 additions & 0 deletions src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ G {

exports[`Helpers should expose a window object: limited window object 1`] = `
{
"CONFIG_EXPORT_EXPIRE": "86400000",
"CONFIG_EXPORT_FILENAME": "swatch_report_{0}",
"CONFIG_EXPORT_SERVICE_NAME_PREFIX": "swatch",
"DEV_MODE": false,
"PROD_MODE": false,
"REVIEW_MODE": false,
Expand Down Expand Up @@ -55,6 +58,9 @@ exports[`Helpers should expose a window object: limited window object 1`] = `

exports[`Helpers should expose a window object: window object 1`] = `
{
"CONFIG_EXPORT_EXPIRE": "86400000",
"CONFIG_EXPORT_FILENAME": "swatch_report_{0}",
"CONFIG_EXPORT_SERVICE_NAME_PREFIX": "swatch",
"DEV_MODE": false,
"PROD_MODE": false,
"REVIEW_MODE": false,
Expand Down Expand Up @@ -114,6 +120,9 @@ exports[`Helpers should handle use aggregate error, or fallback: emulated aggreg

exports[`Helpers should have specific functions: helpers 1`] = `
{
"CONFIG_EXPORT_EXPIRE": "86400000",
"CONFIG_EXPORT_FILENAME": "swatch_report_{0}",
"CONFIG_EXPORT_SERVICE_NAME_PREFIX": "swatch",
"DEV_MODE": false,
"PROD_MODE": false,
"REVIEW_MODE": false,
Expand Down
4 changes: 4 additions & 0 deletions src/common/__tests__/dateHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,8 @@ describe('DateHelpers', () => {

expect(dateHelpers.setEndOfMonth(startDate).getTime()).toEqual(expectedDate.getTime());
});

it('should add milliseconds from date', () => {
expect(dateHelpers.setMillisecondsFromDate({ ms: 86400000 })).toMatchSnapshot('add milliseconds');
});
});
13 changes: 13 additions & 0 deletions src/common/dateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ const setRangedDateTime = ({ date = getCurrentDate(), subtract = 0, measurement
}
};

/**
* Set milliseconds from date. Defaults to internal current date.
*
* @param {object} params
* @param {Date} params.date The date to add milliseconds towards. Defaults to current date.
* @param {number} params.ms
* @returns {Date}
*/
const setMillisecondsFromDate = ({ date = getCurrentDate(), ms = 0 } = {}) =>
new Date(new Date(date).setUTCMilliseconds(ms));

/**
* Generates the date range, starting at the beginning of getCurrentDate, and ending at the end of getCurrentDate.
*
Expand Down Expand Up @@ -288,6 +299,7 @@ const dateHelpers = {
setStartOfDay,
setEndOfDay,
setEndOfMonth,
setMillisecondsFromDate,
getRangedMonthDateTime,
getRangedDateTime,
setRangedDateTime,
Expand All @@ -310,6 +322,7 @@ export {
setStartOfDay,
setEndOfDay,
setEndOfMonth,
setMillisecondsFromDate,
getRangedMonthDateTime,
getRangedDateTime,
setRangedDateTime,
Expand Down
2 changes: 1 addition & 1 deletion src/common/downloadHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const downloadData = options => {
anchorTag.click();

setTimeout(() => {
URL.revokeObjectURL(anchorTag.href);
document.body.removeChild(anchorTag);
URL.revokeObjectURL(blob);
resolve({ fileName, data });
}, 250);
}
Expand Down
24 changes: 24 additions & 0 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,27 @@ const REVIEW_MODE = process.env.REACT_APP_ENV === 'review';
*/
const TEST_MODE = process.env.REACT_APP_ENV === 'test';

/**
* CONFIG export download file expiration.
*
* @type {string}
*/
const CONFIG_EXPORT_EXPIRE = process.env.REACT_APP_CONFIG_EXPORT_EXPIRE;

/**
* CONFIG export download file name. Extension is handled at the service level.
*
* @type {string}
*/
const CONFIG_EXPORT_FILENAME = process.env.REACT_APP_CONFIG_EXPORT_FILENAME;

/**
* CONFIG export "post" download name prefix, for consistency.
*
* @type {string}
*/
const CONFIG_EXPORT_SERVICE_NAME_PREFIX = process.env.REACT_APP_CONFIG_EXPORT_SERVICE_NAME_PREFIX;

/**
* Apply a path prefix for routing.
* Typically associated with applying a "beta" path prefix. See dotenv config files for updating.
Expand Down Expand Up @@ -463,6 +484,9 @@ const helpers = {
PROD_MODE,
REVIEW_MODE,
TEST_MODE,
CONFIG_EXPORT_EXPIRE,
CONFIG_EXPORT_FILENAME,
CONFIG_EXPORT_SERVICE_NAME_PREFIX,
UI_DEPLOY_PATH_PREFIX,
UI_DEPLOY_PATH_LINK_PREFIX,
UI_DISABLED,
Expand Down
Loading

0 comments on commit b67a8e1

Please sign in to comment.