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

No more Barrels #542

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { initialize, mswLoader } from 'msw-storybook-addon';
import { handlers } from '../src/mocks/handlers';
import { theme } from '../src/theme';
import { MathJaxProvider } from '../src/mathjax';
import { useCreateQueryClient } from '@/lib';

export const parameters = {
chakra: { theme },
Expand Down
42 changes: 6 additions & 36 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import api from '@/api';
import { APP_DEFAULTS } from '@/config';
import {
coalesceAuthorsFromDoc,
normalizeSolrSort,
normalizeURLParams,
parseAPIError,
parsePublicationDate,
parseQueryFromUrl,
reconcileDocIdentifier,
truncateDecimal,
} from '@/utils';
import { beforeEach, describe, expect, test, TestContext } from 'vitest';
import { rest } from 'msw';

import { truncateDecimal } from '@/utils/common/formatters';
import { normalizeSolrSort, normalizeURLParams, parseQueryFromUrl } from '@/utils/common/search';
import { coalesceAuthorsFromDoc } from '@/utils/common/coalesceAuthorsFromDoc';
import { parsePublicationDate } from '@/utils/common/parsePublicationDate';
import { parseAPIError } from '@/utils/common/parseAPIError';

const defaultSortPostfix = APP_DEFAULTS.QUERY_SORT_POSTFIX;

describe('normalizeSolrSort', () => {
Expand Down Expand Up @@ -316,32 +312,6 @@ describe('coalesceAuthorsFromDoc', () => {
});
});

describe('reconcileDocIdentifier', () => {
const cases: [string, Parameters<typeof reconcileDocIdentifier>, ReturnType<typeof reconcileDocIdentifier>][] = [
['bibcode present', [{ bibcode: '2024TestCode' }], '2024TestCode'],
['alternate_bibcode as an array', [{ alternate_bibcode: ['2024AltCode1', '2024AltCode2'] }], '2024AltCode1'],
['alternate_bibcode as a string', [{ alternate_bibcode: ['2024AltCode'] }], '2024AltCode'],
['identifier as an array', [{ identifier: ['2024IdCode1', '2024IdCode2'] }], '2024IdCode1'],
['identifier as a string', [{ identifier: ['2024IdCode'] }], '2024IdCode'],
['no identifier fields', [{}], null],
[
'all fields present',
[{ bibcode: '2024TestCode', alternate_bibcode: ['2024AltCode1'], identifier: ['2024IdCode1'] }],
'2024TestCode',
],
[
'alternate_bibcode and identifier present',
[{ alternate_bibcode: ['2024AltCode'], identifier: ['2024IdCode'] }],
'2024AltCode',
],
];

test.concurrent.each(cases)('%s', (_, args, expected) => {
const result = reconcileDocIdentifier(...args);
expect(result).toEqual(expected);
});
});

describe('normalizeURLParams', () => {
const cases: [string, Parameters<typeof normalizeURLParams>, ReturnType<typeof normalizeURLParams>][] = [
[
Expand Down
3 changes: 2 additions & 1 deletion src/api/export/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IADSApiSearchParams, IDocsEntity } from '@/api';
import { enumKeys } from '@/utils';

import { enumKeys } from '@/utils/common/enumKeys';

/**
* @see https://github.com/adsabs/export_service#readme
Expand Down
2 changes: 1 addition & 1 deletion src/api/objects/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
ObjectService,
} from '@/api/objects/types';
import { useQuery } from '@tanstack/react-query';
import { isString } from '@/utils';
import { isNotEmpty } from 'ramda-adjunct';
import { hasObjectTerm, replaceObjectTerms } from '@/api/objects/helpers';
import { APP_DEFAULTS, TRACING_HEADERS } from '@/config';
import { defaultRequestConfig } from '../config';
import axios from 'axios';
import { GetServerSidePropsContext } from 'next';
import { pick } from 'ramda';
import { isString } from '@/utils/common/guards';

export enum OBJECTS_API_KEYS {
QUERY = 'object/query',
Expand Down
2 changes: 1 addition & 1 deletion src/api/orcid/models.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isString } from '@/utils';
import { isNilOrEmpty, isNumber, isObject } from 'ramda-adjunct';
import { IOrcidUser } from '@/api/orcid/types';
import { allPass, has } from 'ramda';
import { addSeconds, isValid } from 'date-fns';
import { IOrcidProfileEntry } from '@/api/orcid/types/orcid-profile';
import { isString } from '@/utils/common/guards';

const orcidRegex = /^\d{4}-\d{4}-\d{4}-\d{3}[0-9X]$/;

Expand Down
2 changes: 1 addition & 1 deletion src/api/orcid/orcid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { IOrcidMutationParams, IOrcidParams, IOrcidResponse, IOrcidUser, IOrcidW
import { isValidIOrcidUser } from '@/api/orcid/models';
import { omit } from 'ramda';
import { ORCID_BULK_DELETE_CHUNK_SIZE, ORCID_BULK_DELETE_DELAY } from '@/config';
import { asyncDelay } from '@/utils';
import { getExIds } from '@/lib/orcid/helpers';
import { OrcidErrorResponse } from '@/api/orcid/types/common';
import { asyncDelay } from '@/components/Orcid/helpers';

export enum OrcidKeys {
EXCHANGE_TOKEN = 'orcid/exchange-token',
Expand Down
2 changes: 1 addition & 1 deletion src/api/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import {
getSingleRecordParams,
getTocParams,
} from './models';
import { isString } from '@/utils';
import { resolveObjectQuery, resolveObjectQuerySSR } from '@/api/objects/objects';
import { GetServerSidePropsContext } from 'next';
import { defaultRequestConfig } from '../config';
import { TRACING_HEADERS } from '@/config';
import { isString } from '@/utils/common/guards';

type ErrorType = Error | AxiosError;

Expand Down
6 changes: 4 additions & 2 deletions src/components/AbstractRefList/AbstractRefList.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { IADSApiSearchParams, IDocsEntity } from '@/api';
import { Stack } from '@chakra-ui/react';
import { SimpleResultList } from '@/components';

import { Pagination, PaginationProps } from '@/components/ResultList/Pagination';
import { calculateStartIndex } from '@/components/ResultList/Pagination/usePagination';
import { SearchQueryLink } from '@/components/SearchQueryLink';
import { APP_DEFAULTS } from '@/config';
import { noop, parseQueryFromUrl, stringifySearchParams } from '@/utils';
import { useRouter } from 'next/router';
import { ReactElement } from 'react';
import { SimpleResultList } from '@/components/ResultList';
import { parseQueryFromUrl, stringifySearchParams } from '@/utils/common/search';
import { noop } from '@/utils/common/noop';

export interface IAbstractRefListProps {
doc: IDocsEntity;
Expand Down
4 changes: 3 additions & 1 deletion src/components/AbstractSideNav/AbstractSideNav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDocsEntity } from '@/api';
import { Badge } from '@chakra-ui/react';
import { exportFormats, IMenuItem, SideNavigationMenu, TopNavigationMenu } from '@/components';

import {
ArrowDownIcon as DownloadIcon,
ChartPieIcon,
Expand All @@ -17,13 +17,15 @@
import { Routes } from './types';
import { values } from 'ramda';
import { useSettings } from '@/lib/useSettings';
import { exportFormats } from '@/components/CitationExporter';
import { IMenuItem, SideNavigationMenu, TopNavigationMenu } from '@/components/NavigationMenu';

const abstractPath = '/abs';

const useGetItems = ({
doc,
hasMetrics,

Check warning on line 27 in src/components/AbstractSideNav/AbstractSideNav.tsx

View workflow job for this annotation

GitHub Actions / build-and-lint (20)

'hasMetrics' is defined but never used
graphicsCount,

Check warning on line 28 in src/components/AbstractSideNav/AbstractSideNav.tsx

View workflow job for this annotation

GitHub Actions / build-and-lint (20)

'graphicsCount' is defined but never used
}: {
doc: IDocsEntity;
hasMetrics: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/components/AbstractSources/AbstractSources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
MenuList,
} from '@chakra-ui/react';
import { ChevronDownIcon } from '@chakra-ui/icons';
import { SimpleLink } from '@/components';

import { ReactElement, useMemo } from 'react';
import { useResolverQuery } from '@/api/resolver';
import { processLinkData } from '@/components/AbstractSources/linkGenerator';
Expand All @@ -28,6 +28,7 @@ import {
FullTextResourceType,
} from './AbstractSourceItems';
import { collectBy, prop } from 'ramda';
import { SimpleLink } from '@/components/SimpleLink';

export interface IAbstractSourcesProps {
doc?: IDocsEntity;
Expand Down
2 changes: 1 addition & 1 deletion src/components/AllAuthorsModal/AllAuthorsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { Pagination } from '@/components/ResultList/Pagination';
import { usePagination } from '@/components/ResultList/Pagination/usePagination';
import { SearchQueryLink } from '@/components/SearchQueryLink';
import { useDebounce } from '@/lib/useDebounce';
import { unwrapStringValue } from '@/utils';
import { MathJax } from 'better-react-mathjax';
import { saveAs } from 'file-saver';
import { matchSorter } from 'match-sorter';
Expand All @@ -48,6 +47,7 @@ import {
} from 'react';
import { useGetAuthors } from './useGetAuthors';
import { sendGTMEvent } from '@next/third-parties/google';
import { unwrapStringValue } from '@/utils/common/formatters';

export interface IAllAuthorsModalProps {
bibcode: IDocsEntity['bibcode'];
Expand Down
2 changes: 1 addition & 1 deletion src/components/AuthorAffiliations/AuthorAffiliations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
useBoolean,
VisuallyHidden,
} from '@chakra-ui/react';
import { isIADSSearchParams } from '@/utils';
import { assoc, isNil, pathOr } from 'ramda';
import { isNilOrEmpty, isNotNilOrEmpty } from 'ramda-adjunct';
import { ChangeEventHandler, Dispatch, ReactElement, SetStateAction, useCallback, useEffect, useState } from 'react';
Expand All @@ -37,6 +36,7 @@ import { ExportModal } from './ExportModal';
import { countOptions, NONESYMBOL } from './models';
import { AuthorAffStoreProvider, useAuthorAffStore } from './store';
import { IGroupedAuthorAffilationData } from './types';
import { isIADSSearchParams } from '@/utils/common/guards';

export type AuthorAffiliationsProps =
| (BoxProps & { params: IAuthorAffiliationPayload; query?: IADSApiSearchParams })
Expand Down
2 changes: 1 addition & 1 deletion src/components/AuthorAffiliations/ErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Alert, AlertDescription, AlertIcon, AlertTitle, Button } from '@chakra-ui/react';
import { parseAPIError } from '@/utils';
import { FallbackProps } from 'react-error-boundary';
import { parseAPIError } from '@/utils/common/parseAPIError';

// hard-coded error messages from the service
// this is fragile, but a default is provided if a match no longer works
Expand Down
2 changes: 1 addition & 1 deletion src/components/AuthorAffiliations/ExportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
Stack,
useDisclosure,
} from '@chakra-ui/react';
import { parseAPIError } from '@/utils';
import { useEffect } from 'react';
import { exportTypes } from './models';
import { useExportModal } from './useExportModal';
import { parseAPIError } from '@/utils/common/parseAPIError';

export const ExportModal = (props: ButtonProps) => {
const { ...btnProps } = props;
Expand Down
2 changes: 1 addition & 1 deletion src/components/AuthorAffiliations/useExportModal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { authorAffiliationsKeys, useAuthorAffiliationExport } from '@/api/author-affiliation/author-affiliation';
import { FileType, useDownloadFile } from 'src/lib';
import { mergeLeft } from 'ramda';
import { Reducer, useEffect, useReducer } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { exportTypeFileMappings, exportTypes } from './models';
import { IAuthorAffState, useAuthorAffStore } from './store';
import { FileType, useDownloadFile } from '@/lib/useDownloadFile';

interface IExportModalState {
mode: 'SELECTING' | 'EXPORTING' | 'DOWNLOADING';
Expand Down
3 changes: 2 additions & 1 deletion src/components/BibstemPicker/BibstemPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HStack, Text, VisuallyHidden } from '@chakra-ui/react';
import { useColorModeColorVars } from '@/lib';

import { IBibstemOption } from '@/types';
import axios from 'axios';
import {
Expand Down Expand Up @@ -42,6 +42,7 @@ import {
import AsyncCreatableSelect from 'react-select/async-creatable';
import Select from 'react-select/dist/declarations/src/Select';
import defaultBibstems from './defaultBibstems.json';
import { useColorModeColorVars } from '@/lib/useColorModeColors';

export interface IBibstemPickerProps extends Omit<HTMLProps<HTMLInputElement>, 'onChange'> {
isMultiple?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ExportApiFormatKey, ExportApiJournalFormat, IDocsEntity, IExportApiParams } from '@/api';
import { APP_DEFAULTS } from '@/config';
import { normalizeSolrSort } from '@/utils';
import { assign, createMachine } from '@xstate/fsm';
import { equals } from 'ramda';
import { IUseCitationExporterProps } from './useCitationExporter';
import { normalizeSolrSort } from '@/utils/common/search';

export interface ICitationExporterState {
records: IDocsEntity['bibcode'][];
Expand Down
2 changes: 1 addition & 1 deletion src/components/CitationExporter/CitationExporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
VStack,
} from '@chakra-ui/react';
import { APP_DEFAULTS } from '@/config';
import { noop } from '@/utils';
import { useRouter } from 'next/router';
import { ChangeEventHandler, Dispatch, HTMLAttributes, ReactElement, useEffect, useState } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
Expand All @@ -41,6 +40,7 @@ import { RecordField } from './components/RecordField';
import { ResultArea } from './components/ResultArea';
import { exportFormats } from './models';
import { useCitationExporter } from './useCitationExporter';
import { noop } from '@/utils/common/noop';

export interface ICitationExporterProps extends HTMLAttributes<HTMLDivElement> {
singleMode?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSession } from '@/lib/useSession';
import { SimpleLink } from '@/components/SimpleLink';
import { DEFAULT_USER_DATA } from '@/api';
import { useSettings } from '@/lib/useSettings';
import { useColorModeColors } from '@/lib';
import { useColorModeColors } from '@/lib/useColorModeColors';

export interface ICustomFormatSelectProps {
dispatch: Dispatch<CitationExporterEvent>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IExportApiResponse } from '@/api';
import { Alert, AlertIcon, Button, Stack } from '@chakra-ui/react';
import { parseAPIError } from '@/utils';
import { AxiosError } from 'axios';
import { ReactElement } from 'react';
import { ExportContainer } from './ExportContainer';
import { parseAPIError } from '@/utils/common/parseAPIError';

/**
* Error boundary fallback
Expand Down
3 changes: 2 additions & 1 deletion src/components/CitationExporter/components/FormatSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ExportApiFormatKey, isExportApiFormat } from '@/api';
import { Select } from '@/components';

import { omit, values } from 'ramda';
import { Dispatch, useMemo } from 'react';
import { CitationExporterEvent } from '../CitationExporter.machine';
import { ExportFormat, exportFormats } from '../models';
import { Select } from '@/components/Select';

export interface IFormatSelectProps {
format: ExportApiFormatKey;
Expand Down
3 changes: 2 additions & 1 deletion src/components/CitationExporter/components/ResultArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { useDownloadFile } from '@/lib/useDownloadFile';
import { useIsClient } from '@/lib/useIsClient';
import { exportFormats } from '../models';
import { LabeledCopyButton } from '@/components/CopyButton';
import { useColorModeColors } from '@/lib';

import { sendGTMEvent } from '@next/third-parties/google';
import { useColorModeColors } from '@/lib/useColorModeColors';

export const ResultArea = ({
result = '',
Expand Down
2 changes: 1 addition & 1 deletion src/components/CitationExporter/useCitationExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
SolrSort,
useGetExportCitation,
} from '@/api';
import { purifyString } from '@/utils';
import { useMachine } from '@xstate/react/fsm';
import { useEffect, useMemo } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { generateMachine, ICitationExporterState } from './CitationExporter.machine';
import { purifyString } from '@/utils/common/formatters';

export interface IUseCitationExporterProps {
records: ICitationExporterState['records'];
Expand Down
11 changes: 8 additions & 3 deletions src/components/ClassicForm/ClassicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
VisuallyHidden,
} from '@chakra-ui/react';
import { CalendarIcon } from '@chakra-ui/icons';
import { BibstemPicker, Expandable, IRawClassicFormState, SimpleCopyButton, SimpleLink, Sort } from '@/components';

import { APP_DEFAULTS } from '@/config';
import { useErrorMessage } from '@/lib/useErrorMessage';
import { useIsClient } from '@/lib/useIsClient';
Expand All @@ -32,10 +32,15 @@ import PT from 'prop-types';
import { FormEventHandler, useMemo } from 'react';
import { Control, Controller, useForm, UseFormRegisterReturn, useWatch } from 'react-hook-form';
import { getSearchQuery } from './helpers';
import { IClassicFormState } from './types';
import { IClassicFormState, IRawClassicFormState } from './types';
import { SolrSort, SolrSortField } from '@/api';
import { solrSortOptions } from '@/components/Sort/model';
import { normalizeSolrSort } from '@/utils';
import { SimpleLink } from '@/components/SimpleLink';
import { BibstemPicker } from '@/components/BibstemPicker';
import { Sort } from '@/components/Sort';
import { Expandable } from '@/components/Expandable';
import { SimpleCopyButton } from '@/components/CopyButton';
import { normalizeSolrSort } from '@/utils/common/search';

const propTypes = {
ssrError: PT.string,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ClassicForm/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { makeSearchParams } from '@/utils';
import DOMPurify from 'isomorphic-dompurify';
import {
__,
Expand Down Expand Up @@ -41,6 +40,7 @@ import { isNilOrEmpty, isNotEmpty } from 'ramda-adjunct';
import { CollectionChoice, IClassicFormState, IRawClassicFormState, LogicChoice, PropertyChoice } from './types';
import { getTerms } from '@/query';
import { APP_DEFAULTS } from '@/config';
import { makeSearchParams } from '@/utils/common/search';

const DEFAULT_PREFIXES = ['-', '+', '='];
const NOT_PREFIX = ['-'];
Expand Down
2 changes: 1 addition & 1 deletion src/components/DataDownloader/DataDownloader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DownloadIcon } from '@chakra-ui/icons';
import { Button, StyleProps, Text } from '@chakra-ui/react';
import { useDownloadFile } from 'src/lib';
import { FC } from 'react';
import { useDownloadFile } from '@/lib/useDownloadFile';

export interface IDataDownloaderProps extends StyleProps {
label: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dropdown/SimpleLinkDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChevronDownIcon } from '@chakra-ui/icons';
import { Box, Flex } from '@chakra-ui/react';
import { ReactElement } from 'react';
import { ItemType } from './types';
import { SimpleLink } from '@/components';
import { SimpleLink } from '@/components/SimpleLink';

/** Non JavaScript dropdown */
export interface ISimpleLinkDropdownProps {
Expand Down
Loading
Loading