Skip to content

Commit

Permalink
refactor: Utilities
Browse files Browse the repository at this point in the history
Small refactor to move all utilities into a dedicated utilities directory, and ensure that anything exported from that dir is exported from the library itself as well
  • Loading branch information
EthanFreestone committed Nov 17, 2023
1 parent f665fea commit 80f209d
Show file tree
Hide file tree
Showing 41 changed files with 69 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 9.1.0 In progress
* usePrevNextPagination null safety (yarn test warnings)
* Refactor to move utilities tp dedicated directory

## 9.0.0 2023-10-12
* Added useParallelBatchFetch hook
Expand Down
49 changes: 9 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Components
export { default as ActionMenu } from './lib/ActionMenu';
export { default as AlternativeNamesFieldArray } from './lib/AlternativeNamesFieldArray';
export { default as CustomMetaSection } from './lib/CustomMetaSection';
export { default as DateFilter } from './lib/DateFilter';
export { default as DocumentCard } from './lib/DocumentCard';
export { default as DocumentFilter } from './lib/DocumentFilter';
export { default as DocumentsFieldArray } from './lib/DocumentsFieldArray';
Expand All @@ -11,65 +13,32 @@ export { default as EResourceType } from './lib/EResourceType';
export { default as FileUploader } from './lib/FileUploader';
export { default as FileUploaderField } from './lib/FileUploaderField';
export { default as FormattedDateTime } from './lib/FormattedDateTime';
export { default as InfoBox } from './lib/InfoBox';
export { default as InternalContactCard } from './lib/InternalContactCard';
export { default as InternalContactSelection } from './lib/InternalContactSelection';
export { default as InternalContactsFieldArray } from './lib/InternalContactsFieldArray';
export { default as OrganizationsFieldArray } from './lib/OrganizationsFieldArray';
export { default as DateFilter } from './lib/DateFilter';
export { default as ViewOrganizationCard } from './lib/ViewOrganizationCard';
export { default as LicenseCard } from './lib/LicenseCard';
export { default as LicenseEndDate } from './lib/LicenseEndDate';
export { default as LogsList } from './lib/LogsList';
export { default as Logs } from './lib/Logs';
export { default as NewBox } from './lib/NewBox';
export { default as OrganizationSelection } from './lib/OrganizationSelection';
export { default as SearchKeyControl } from './lib/SearchKeyControl';
export { default as SerialCoverage } from './lib/SerialCoverage';
export { default as Tags } from './lib/Tags';
export { default as TitleOnPlatformLink } from './lib/TitleOnPlatformLink';
export { default as CustomMetaSection } from './lib/CustomMetaSection';
export { default as SearchKeyControl } from './lib/SearchKeyControl';

// Functions, utilities, and misc.
export { default as generateQueryParams } from './lib/generateQueryParams';
export { default as getSASParams } from './lib/getSASParams';
export { default as getSiblingIdentifier } from './lib/getSiblingIdentifier';
export { default as getResourceIdentifier } from './lib/getResourceIdentifier';
export { default as isPackage } from './lib/isPackage';
export { default as renderUserName } from './lib/renderUserName';
export { default as getRefdataValuesByDesc } from './lib/getRefdataValuesByDesc';
export { default as renderDynamicRows } from './lib/renderDynamicRows';
export { default as downloadBlob } from './lib/downloadBlob';
export { default as recursiveUrlDecoding } from './lib/recursiveUrlDecoding';
export { default as selectifyRefdata } from './lib/selectifyRefdata';

export {
tagsPath,
defaultTagsParams,
defaultTagQuery,
tagNamespaceArray
} from './lib/tagsConfig'; // Tag configuration for consistency across ERM apps

export { default as preventResourceRefresh } from './lib/preventResourceRefresh';
export {
composeValidators,
composeValidatorsWithArgs,
invalidNumber as invalidNumberValidator,
rangeOverflow,
rangeUnderflow,
required as requiredValidator,
requiredObject as requiredObjectValidator,
} from './lib/validators';

export { default as handleSaveKeyCommand } from './lib/keyboardShortcutHandlers';
export { default as ViewOrganizationCard } from './lib/ViewOrganizationCard';

// Shared registry components/functions
export { default as InternalContactsArrayDisplay } from './lib/InternalContactsArrayDisplay';
export { default as OrganizationsArrayDisplay } from './lib/OrganizationsArrayDisplay';

export { default as InfoBox } from './lib/InfoBox';
export { default as NewBox } from './lib/NewBox';

// customHooks
export * from './lib/hooks';

// constants
export * from './lib/constants';

// utility functions
export * from './lib/utils';
2 changes: 1 addition & 1 deletion lib/AlternativeNamesFieldArray/AlternativeNamesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { Field } from 'react-final-form';

import { TextField } from '@folio/stripes/components';
import { required } from '../validators';
import { requiredValidator as required } from '../utils';

export default class AlternativeNamesField extends React.Component {
static propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion lib/DocumentFilter/DocumentFilterRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@folio/stripes/components';
import { FormattedMessage, useIntl } from 'react-intl';
import { Field } from 'react-final-form';
import { required as requiredValidator } from '../validators';
import { requiredValidator } from '../utils';
import DocumentFilterRuleConstants from './DocumentFilterRuleConstants';

const DocumentFilterRule = ({
Expand Down
2 changes: 1 addition & 1 deletion lib/DocumentsFieldArray/DocumentField.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@folio/stripes/components';

import FileUploaderField from '../FileUploaderField';
import { composeValidators } from '../validators';
import { composeValidators } from '../utils';

const MAX_URL_SIZE = 2048;
export default class DocumentField extends React.Component {
Expand Down
2 changes: 1 addition & 1 deletion lib/EResourceType/EResourceType.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import isPackage from '../isPackage';
import { isPackage } from '../utils';

export default class EResourceType extends React.Component {
static propTypes = {
Expand Down
5 changes: 3 additions & 2 deletions lib/InternalContactCard/InternalContactCard.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';

import { Link } from 'react-router-dom';
import { AppIcon } from '@folio/stripes/core';
import { FormattedMessage } from 'react-intl';
import { Card, Col, KeyValue, NoValue, Row } from '@folio/stripes/components';

import renderUserName from '../renderUserName';
import { renderUserName } from '../utils';

export default class ContactCard extends React.Component {
static propTypes = {
Expand Down
5 changes: 3 additions & 2 deletions lib/InternalContactSelection/InternalContactSelection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import uniqBy from 'lodash/uniqBy';

import { useChunkedUsers, useParallelBatchFetch } from '../hooks';
import renderUserName from '../renderUserName';
import { renderUserName } from '../utils';

import InternalContactSelectionDisplay from './InternalContactSelectionDisplay';

const InternalContactSelection = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useQuery } from 'react-query';
import { useOkapiKy } from '@folio/stripes/core';
import { Row } from '@folio/stripes/components';

import renderUserName from '../renderUserName';
import { renderUserName } from '../utils';

const InternalContactsArrayDisplay = ({ contacts }) => {
/* eslint-disable no-param-reassign */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

import { useKiwtFieldArray } from '@k-int/stripes-kint-components';
import EditCard from '../EditCard';
import { composeValidators, required } from '../validators';
import { composeValidators, requiredValidator as required } from '../utils';

import UserField from './UserField';

Expand Down
6 changes: 4 additions & 2 deletions lib/InternalContactsFieldArray/UserField.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';

import {
Button,
Card,
Expand All @@ -13,9 +15,9 @@ import {
} from '@folio/stripes/components';
import { AppIcon, Pluggable } from '@folio/stripes/core';

import { Link } from 'react-router-dom';
import { renderUserName } from '../utils';

import css from '../styles.css';
import renderUserName from '../renderUserName';

export default class UserField extends React.Component {
static propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion lib/OrganizationsFieldArray/EditOrganizationCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@folio/stripes/components';

import EditCard from '../EditCard';
import { required } from '../validators';
import { requiredValidator as required } from '../utils';
import ViewOrganizationCard from '../ViewOrganizationCard';
import RolesFieldArray from './RolesFieldArray';
import FieldPrimaryOrg from './FieldPrimaryOrg';
Expand Down
2 changes: 1 addition & 1 deletion lib/OrganizationsFieldArray/RolesFieldArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@folio/stripes/components';
import { useKiwtFieldArray } from '@k-int/stripes-kint-components';

import { required } from '../validators';
import { requiredValidator as required } from '../utils';
import { usePrevious } from '../hooks';

// Utility function to check if two arrays of scalars contain the same items (Order does not count)
Expand Down
4 changes: 2 additions & 2 deletions lib/Tags/Tags.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import { useContext } from 'react';
import PropTypes from 'prop-types';

import { FormattedMessage } from 'react-intl';
Expand All @@ -12,7 +12,7 @@ import { Pane } from '@folio/stripes/components';
import { TagsForm } from '@folio/stripes/smart-components';

import { useTags } from '../hooks';
import { tagNamespaceArray } from '../tagsConfig';
import { tagNamespaceArray } from '../utils';

const Tags = ({
invalidateLinks = [], // If there are other queries that need invalidating, pass those here
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/useExportLogStream/useExportLogStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useQuery } from 'react-query';

import { CalloutContext, useOkapiKy } from '@folio/stripes/core';

import downloadBlob from '../../downloadBlob';
import { downloadBlob } from '../../utils';

const useExportLogStream = (job, type) => {
const callout = useContext(CalloutContext);
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/useFileHandlers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation } from 'react-query';

import { useOkapiKy } from '@folio/stripes/core';
import downloadBlob from '../downloadBlob';
import { downloadBlob } from '../utils';

const useFileHandlers = (fileEndpoint) => {
const ky = useOkapiKy();
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/useTags.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from 'react-query';
import { useOkapiKy } from '@folio/stripes/core';
import { defaultTagQuery, tagNamespaceArray } from '../tagsConfig';
import { defaultTagQuery, tagNamespaceArray } from '../utils';

const useTags = (namespaceArray, options) => {
const ky = useOkapiKy();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Stripes connect utils (Maybe redundant)
export { default as generateQueryParams } from './generateQueryParams';
export { default as getSASParams } from './getSASParams';
export { default as preventResourceRefresh } from './preventResourceRefresh';

// Validators
export {
composeValidators,
composeValidatorsWithArgs,
invalidNumber as invalidNumberValidator,
rangeOverflow,
rangeUnderflow,
required as requiredValidator,
requiredObject as requiredObjectValidator,
} from './validators';

// Tag configuration for consistency across ERM apps
export {
tagsPath,
defaultTagsParams,
defaultTagQuery,
tagNamespaceArray
} from './tagsConfig';

Check failure on line 23 in lib/utils/index.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Trailing spaces not allowed

Check failure on line 23 in lib/utils/index.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Trailing spaces not allowed

// Rest of utils
export { default as downloadBlob } from './downloadBlob';
export { default as getRefdataValuesByDesc } from './getRefdataValuesByDesc';
export { default as isPackage } from './isPackage';
export { default as handleSaveKeyCommand } from './keyboardShortcutHandlers';
export { default as recursiveUrlDecoding } from './recursiveUrlDecoding';
export { default as renderDynamicRows } from './renderDynamicRows';
export { default as renderUserName } from './renderUserName';
export { default as selectifyRefdata } from './selectifyRefdata';
export { default as getSiblingIdentifier } from './getSiblingIdentifier';
export { default as getResourceIdentifier } from './getResourceIdentifier';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions lib/utils/renderDynamicRows/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './renderDynamicRows';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 80f209d

Please sign in to comment.