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

STCOM-1094 Replace momentJS with dayJS #2192

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e58b5a7
progress
JohnC-80 Dec 21, 2023
04808db
timepicker converted
JohnC-80 Dec 21, 2023
0aa10a8
add dynamic locale hook, fix tests for datepicker, Calendar, timepicker
JohnC-80 Jan 3, 2024
ce5073a
Merge branch 'master' into dayjs-refresh
JohnC-80 Jan 3, 2024
39692da
cleanup bugs in calendar - thanks SonarDad!
JohnC-80 Jan 3, 2024
f76a950
Merge branch 'dayjs-refresh' of https://github.com/folio-org/stripes-…
JohnC-80 Jan 3, 2024
50fb8d4
more SonarDad feedback on Calendar/Timepicker
JohnC-80 Jan 3, 2024
be9c197
resolve conflics on timepicker tests
JohnC-80 Jan 5, 2024
24924bc
re-export dayjs from stripes-components
JohnC-80 Jan 5, 2024
f0ac1f4
remove commented code from Timepicker
JohnC-80 Jan 5, 2024
f2d8569
remove duplicate imports in dateTimeUtils
JohnC-80 Jan 5, 2024
a298ad2
Merge branch 'master' into dayjs-refresh
JohnC-80 Jan 5, 2024
720fe5b
one more time... eyes and webpack cache killing me
JohnC-80 Jan 5, 2024
40e106e
Merge branch 'dayjs-refresh' of https://github.com/folio-org/stripes-…
JohnC-80 Jan 5, 2024
aa37188
add Dayjs Range utility class
JohnC-80 Jan 5, 2024
a466a7d
add tests for DayRange methods
JohnC-80 Jan 5, 2024
f46d7c9
remove only
JohnC-80 Jan 5, 2024
cce3e02
export DayRange
JohnC-80 Jan 9, 2024
dc27113
semicolons
JohnC-80 Jan 9, 2024
9f0d822
add inclusive parameter to DayRange#contains
JohnC-80 Jan 10, 2024
af4f95c
add locale-loading utilities to stripes-components
JohnC-80 Jan 10, 2024
1d981f9
remove only
JohnC-80 Jan 10, 2024
ad0f823
expand testing for loadDayJSLocale
JohnC-80 Jan 11, 2024
ff74e10
update date/time documentation
JohnC-80 Jan 12, 2024
0ca6e16
account for undefined timezone in datepicker
JohnC-80 Jan 16, 2024
f4b3355
move array format parsing to dateTimeUtils
JohnC-80 Jan 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -156,6 +156,18 @@ Useful recipes for UI patterns appearing in FOLIO modules.
* [Show/Hide Columns in MCL](guides/patterns/ColumnSelector.stories.mdx) -- Give users the ability to select only the data they need to see.
* [Accessible Routing](guides/patterns/AccessibleRouting.stories.mdx) -- Detail the approaches to implementing accessible focus management.

## Working with dates/times in UI-Modules

We provide a handful of components and utilities for date/time functionality.

* **Datepicker, Timepicker, DateRangeWrapper components** - UI-widgets for accepting date/time input.
* **FormattedDate, FormattedUTCDate, FormattedTime** - Cross-browser convenience components for displaying localized representations of system ISO8601 timestamps.
* [dateTimeUtils](util/DateUtils_readme.md) - A handful of utility functions for working with date/time code in application logic.
* **Hooks**
* useFormatDate - presentational date-formatting.
* useFormatTime - presentational time-formatting.
* useDynamicLocale - loading DayJS locale information within functional components (also available in component form, via `DynamicLocaleRenderer`).

## Testing
Stripes Components' tests are automated browser tests powered by
[Karma](http://karma-runner.github.io) and written using
Expand Down
20 changes: 20 additions & 0 deletions hooks/useDynamicLocale/DynamicLocaleRenderer.js
@@ -0,0 +1,20 @@
import { useEffect } from 'react';
import PropTypes from 'prop-types';
import useDynamicLocale from './useDynamicLocale';

const DynamicLocaleRenderer = ({ children, onLoaded }) => {
const { localeLoaded, isEnglishLang } = useDynamicLocale();
useEffect(() => {
if (localeLoaded) {
onLoaded({ isEnglishLang });
}
}, [localeLoaded, onLoaded, isEnglishLang]);
return localeLoaded ? children : null;
};

DynamicLocaleRenderer.propTypes = {
children: PropTypes.node,
onLoaded: PropTypes.func,
};

export default DynamicLocaleRenderer;
3 changes: 3 additions & 0 deletions hooks/useDynamicLocale/index.js
@@ -0,0 +1,3 @@
export { default as useDynamicLocale } from './useDynamicLocale';
export { default as DynamicLocaleRenderer } from './DynamicLocaleRenderer';

47 changes: 47 additions & 0 deletions hooks/useDynamicLocale/useDynamicLocale.js
@@ -0,0 +1,47 @@
import React from 'react';
import { IntlContext } from 'react-intl';
import { loadDayJSLocale } from '../../util/dateTimeUtils';

const isEnglishLang = (locale) => {
return /^en/.test(locale);
};

/**
* useDynamicLocale -
* React hook that loads a DayJS locale, returns an
* @date 12/15/2023 - 1:58:58 PM
*
* @param {Object} hookParams
* @param {String} hookParams.locale - locale string ex : 'en-SE'
*/
const useDynamicLocale = ({ locale : localeProp } = {}) => {
const { locale: localeContext } = React.useContext(IntlContext);
const [localeLoaded, setLocaleLoaded] = React.useState(
localeProp ? isEnglishLang(localeProp) :
isEnglishLang(localeContext)
);
const [prevLocale, updatePrevLocale] = React.useState(localeProp || localeContext);
const locale = localeProp || localeContext;

React.useEffect(() => {
const localeCallback = (loadedLocale, err) => {
if (!err) {
setLocaleLoaded(true);
}
};

loadDayJSLocale(locale, localeCallback);
}, [localeLoaded, locale, prevLocale]);

if (locale !== prevLocale) {
updatePrevLocale(localeProp || localeContext);
setLocaleLoaded(localeProp ? isEnglishLang(localeProp) : isEnglishLang(localeContext));
}

return {
localeLoaded,
isEnglish: localeProp ? localeProp === 'en' : localeContext === 'en'
};
};

export default useDynamicLocale;
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -12,7 +12,6 @@ export {
staticFirstWeekDay,
staticLangCountryCodes
} from './lib/Datepicker';
export { getLocaleDateFormat, getLocalizedTimeFormatInfo } from './util/dateTimeUtils';
export { default as DateRangeWrapper } from './lib/DateRangeWrapper';
export { default as FormattedDate } from './lib/FormattedDate';
export { default as FormattedTime } from './lib/FormattedTime';
Expand Down Expand Up @@ -142,6 +141,13 @@ export { default as ExportCsv } from './lib/ExportCsv';
export { default as exportToCsv } from './lib/ExportCsv/exportToCsv';

/* utilities */
export {
getLocaleDateFormat,
getLocalizedTimeFormatInfo,
dayjs,
DayRange,
loadDayJSLocale,
} from './util/dateTimeUtils';
export { default as RootCloseWrapper } from './util/RootCloseWrapper';
export { default as omitProps } from './util/omitProps';
export {
Expand Down