Skip to content

Commit

Permalink
fix(graphCardHelpers): issues/317 yAxisTickFormat locale (#319)
Browse files Browse the repository at this point in the history
* helpers, expose default locale, description
* graphCardHelpers, apply helper default locale
* userServices, apply helper default locale
  • Loading branch information
cdcabrera committed Jul 30, 2020
1 parent 73b57ef commit 5cc5dbd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Object {
"UI_DISPLAY_CONFIG_NAME": "Subscription Watch",
"UI_DISPLAY_NAME": "Subscription Watch",
"UI_DISPLAY_START_NAME": "Subscription Watch",
"UI_LOCALE_DEFAULT": "en-US",
"UI_LOCALE_DEFAULT_DESC": "English",
"UI_LOGGER_ID": "curiosity",
"UI_NAME": "subscriptions",
"UI_PATH": "/",
Expand Down Expand Up @@ -43,6 +45,8 @@ Object {
"UI_DISPLAY_CONFIG_NAME": "Subscription Watch",
"UI_DISPLAY_NAME": "Subscription Watch",
"UI_DISPLAY_START_NAME": "Subscription Watch",
"UI_LOCALE_DEFAULT": "en-US",
"UI_LOCALE_DEFAULT_DESC": "English",
"UI_LOGGER_ID": "curiosity",
"UI_NAME": "subscriptions",
"UI_PATH": "/",
Expand Down Expand Up @@ -72,6 +76,8 @@ Object {
"UI_DISPLAY_CONFIG_NAME": "Subscription Watch",
"UI_DISPLAY_NAME": "Subscription Watch",
"UI_DISPLAY_START_NAME": "Subscription Watch",
"UI_LOCALE_DEFAULT": "en-US",
"UI_LOCALE_DEFAULT_DESC": "English",
"UI_LOGGER_ID": "curiosity",
"UI_NAME": "subscriptions",
"UI_PATH": "/",
Expand Down
16 changes: 16 additions & 0 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ const UI_DISPLAY_CONFIG_NAME = process.env.REACT_APP_UI_DISPLAY_CONFIG_NAME;
*/
const UI_DISPLAY_START_NAME = process.env.REACT_APP_UI_DISPLAY_START_NAME;

/**
* UI locale default.
*
* @type {string}
*/
const UI_LOCALE_DEFAULT = process.env.REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG;

/**
* UI locale default description.
*
* @type {string}
*/
const UI_LOCALE_DEFAULT_DESC = process.env.REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG_DESC;

/**
* UI state logging name/id.
* See dotenv config files for updating.
Expand Down Expand Up @@ -212,6 +226,8 @@ const helpers = {
UI_DISPLAY_NAME,
UI_DISPLAY_CONFIG_NAME,
UI_DISPLAY_START_NAME,
UI_LOCALE_DEFAULT,
UI_LOCALE_DEFAULT_DESC,
UI_LOGGER_ID,
UI_NAME,
UI_PATH,
Expand Down
4 changes: 2 additions & 2 deletions src/components/graphCard/graphCardHelpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moment from 'moment';
import { RHSM_API_QUERY_GRANULARITY_TYPES as GRANULARITY_TYPES } from '../../types/rhsmApiTypes';
import { dateHelpers } from '../../common/dateHelpers';
import { dateHelpers, helpers } from '../../common';

/**
* Returns x axis ticks/intervals array for the xAxisTickInterval
Expand Down Expand Up @@ -109,7 +109,7 @@ const xAxisTickFormat = ({ date, granularity, tick, previousDate }) => {
* @param {string} params.locale
* @returns {string}
*/
const yAxisTickFormat = ({ tick, locale }) =>
const yAxisTickFormat = ({ tick, locale = helpers.UI_LOCALE_DEFAULT }) =>
new Intl.NumberFormat(locale, { maximumFractionDigits: 1, notation: 'compact', compactDisplay: 'short' }).format(
tick
);
Expand Down
4 changes: 2 additions & 2 deletions src/services/userServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const getLocaleFromCookie = () => {
*/
const getLocale = () => {
const defaultLocale = {
value: process.env.REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG,
key: process.env.REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG_DESC
value: helpers.UI_LOCALE_DEFAULT,
key: helpers.UI_LOCALE_DEFAULT_DESC
};

return new Promise(resolve =>
Expand Down

0 comments on commit 5cc5dbd

Please sign in to comment.