Skip to content

Commit

Permalink
UIBULKED-553 Replace generic error with the detailed error message
Browse files Browse the repository at this point in the history
  • Loading branch information
vashjs committed Oct 16, 2024
1 parent 94e4f4c commit 11a0b18
Show file tree
Hide file tree
Showing 26 changed files with 178 additions and 38 deletions.
4 changes: 4 additions & 0 deletions src/components/PermissionsModal/hooks/useAllPermissions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useQuery } from 'react-query';
import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { FILTER_KEYS } from '../constants/core';
import { useErrorMessages } from '../../../hooks/useErrorMessages';

export const ALL_PERMISSIONS_KEY = 'ALL_PERMISSIONS_KEY';

export const useAllPermissions = (options = {}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: ALL_PERMISSIONS_KEY });
const { showErrorMessage } = useErrorMessages();

const { data: permissions, isLoading: isPermissionsLoading } = useQuery(
{
Expand All @@ -18,6 +20,8 @@ export const useAllPermissions = (options = {}) => {
...permission,
type: permission.mutable ? FILTER_KEYS.PERMISSION_SETS : FILTER_KEYS.PERMISSIONS,
})),
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options,
},
);
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useBulkEditLogs/useBulkEditLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@folio/stripes-acq-components';

import { getFullName } from '../../../utils/getFullName';
import { useErrorMessages } from '../../useErrorMessages';

const buildLogsQuery = makeQueryBuilder(
'cql.allRecords=1',
Expand All @@ -27,6 +28,7 @@ export const useBulkEditLogs = ({ filters = {}, pagination }) => {
const usersMap = useRef({});
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: BULK_EDIT_LOGS_KEY });
const { showErrorMessage } = useErrorMessages();

const logsQuery = buildLogsQuery(filters);
const filtersCount = getFiltersCount(filters);
Expand Down Expand Up @@ -83,6 +85,8 @@ export const useBulkEditLogs = ({ filters = {}, pagination }) => {
queryFn,
enabled: Boolean(pagination.timestamp),
keepPreviousData: true,
onError: showErrorMessage,
onSuccess: showErrorMessage,
});

return {
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useBulkOperationDelete.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useOkapiKy } from '@folio/stripes/core';
import { useMutation } from 'react-query';
import { useErrorMessages } from '../useErrorMessages';

export const useBulkOperationDelete = (mutationOptions = {}) => {
const ky = useOkapiKy();
const { showErrorMessage } = useErrorMessages();

const { mutateAsync: bulkOperationDelete, isLoading } = useMutation({
mutationFn: async ({ operationId }) => {
await ky.post(`bulk-operations/${operationId}/cancel`);
},
onError: showErrorMessage,
onSuccess: showErrorMessage,
...mutationOptions,
});

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/api/useBulkOperationStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useErrorMessages } from '../useErrorMessages';
export const useBulkOperationStart = (mutationOptions = {}) => {
const params = useRef({});
const ky = useOkapiKy();
const { checkErrorMessage } = useErrorMessages();
const { showErrorMessage } = useErrorMessages();

const { refetch: fetchBulkOperation } = useQuery({
queryFn: async () => {
Expand Down Expand Up @@ -64,7 +64,7 @@ export const useBulkOperationStart = (mutationOptions = {}) => {
json: body,
}).json();

checkErrorMessage(startResult);
showErrorMessage(startResult);

// eslint-disable-next-line no-empty
} catch (e) {}
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useBulkOperationTenants.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { useQuery } from 'react-query';

import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { useErrorMessages } from '../useErrorMessages';

export const BULK_TENANTS_KEY = 'BULK_TENANTS_KEY';

export const useBulkOperationTenants = (id, options = {}) => {
const ky = useOkapiKy();
const [namespace] = useNamespace({ key: BULK_TENANTS_KEY });
const { showErrorMessage } = useErrorMessages();

const { data, isLoading } = useQuery({
queryKey: [namespace],
queryFn: () => ky.get(`bulk-operations/used-tenants/${id}`).json(),
keepPreviousData: true,
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options,
});

Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useBulkOperationUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { omit } from 'lodash';
import { makeQueryBuilder } from '@folio/stripes-acq-components';
import noop from 'lodash/noop';
import { LOGS_FILTERS, PAGINATION_CONFIG as pagination } from '../../constants';
import { useErrorMessages } from '../useErrorMessages';

export const BULK_OPERATION_USERS_KEY = 'BULK_OPERATION_USERS_KEY';

Expand All @@ -17,6 +18,7 @@ const buildLogsQuery = makeQueryBuilder(
export const useBulkOperationUsers = (filters, options) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: BULK_OPERATION_USERS_KEY });
const { showErrorMessage } = useErrorMessages();

const logsQuery = buildLogsQuery(omit(filters, [LOGS_FILTERS.USER]));

Expand All @@ -29,6 +31,8 @@ export const useBulkOperationUsers = (filters, options) => {
const { data, isLoading } = useQuery({
queryKey: [namespaceKey, filters],
queryFn: () => ky.get('bulk-operations/list-users', { searchParams }).json(),
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options,
});

Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useContentUpdate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { useMutation } from 'react-query';
import { useOkapiKy } from '@folio/stripes/core';
import { useErrorMessages } from '../useErrorMessages';

export const useContentUpdate = ({ id }) => {
const ky = useOkapiKy();
const { showErrorMessage } = useErrorMessages();

const { data, mutateAsync: contentUpdate, isLoading } = useMutation({
mutationFn: ({ contentUpdates }) => {
return ky.post(`bulk-operations/${id}/content-update`, {
json: contentUpdates,
});
},
onError: showErrorMessage,
onSuccess: showErrorMessage,
});

return { contentUpdate, isLoading, data };
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useElectronicAccess.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { useQuery } from 'react-query';
import { useErrorMessages } from '../useErrorMessages';

export const ELECTRONIC_ACCESS_RELATIONSHIPS_KEY = 'ELECTRONIC_ACCESS_RELATIONSHIPS_KEY';

export const useElectronicAccessRelationships = (options = {}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: ELECTRONIC_ACCESS_RELATIONSHIPS_KEY });
const { showErrorMessage } = useErrorMessages();

const { data, isLoading: isElectronicAccessLoading } = useQuery(
{
queryKey: [namespaceKey],
cacheTime: Infinity,
staleTime: Infinity,
queryFn: () => ky.get('electronic-access-relationships?limit=1000&query=cql.allRecords=1 sortby name').json(),
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options,
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/api/useElectronicAccessEsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useElectronicAccessEsc = (tenants, options = {}) => {
(tenantData, tenantName) => tenantData.response?.electronicAccessRelationships?.map(type => ({
...type,
name: `${type.name} (${tenantName})`,
tenantName,
tenantName,
})),
options
);
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/api/useErrorsPreview.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { useQuery } from 'react-query';
import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { useErrorMessages } from '../useErrorMessages';

export const PREVIEW_ERRORS_KEY = 'PREVIEW_ERRORS_KEY';

export const useErrorsPreview = ({ id }) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: PREVIEW_ERRORS_KEY });

const { showErrorMessage } = useErrorMessages();

const { data, isLoading } = useQuery(
{
queryKey: [namespaceKey, id],
cacheTime: 0,
enabled: !!id,
queryFn: () => ky.get(`bulk-operations/${id}/errors`, { searchParams: { limit: 10 } }).json(),
onError: showErrorMessage,
onSuccess: showErrorMessage,
},
);

Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useEscCommon.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useNamespace } from '@folio/stripes/core';
import { useQuery } from 'react-query';
import { usePublishCoordinator } from '../usePublishCoordinator';
import { useErrorMessages } from '../useErrorMessages';

const DEFAULT_DATA = {};

export const useEscCommon = (key, url, tenants, mapResponse, options = {}) => {
const [namespace] = useNamespace({ key });
const { initPublicationRequest } = usePublishCoordinator(namespace);
const { showErrorMessage } = useErrorMessages();

const { data = DEFAULT_DATA, isFetching } = useQuery({
queryKey: [namespace, tenants],
Expand All @@ -21,6 +23,8 @@ export const useEscCommon = (key, url, tenants, mapResponse, options = {}) => {
keepPreviousData: true,
cacheTime: Infinity,
staleTime: Infinity,
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options
});

Expand Down
8 changes: 7 additions & 1 deletion src/hooks/api/useFileDownload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery } from 'react-query';
import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { useErrorMessages } from '../useErrorMessages';

export const QUERY_KEY_DOWNLOAD_LOGS = 'downloadLogs';
export const QUERY_KEY_DOWNLOAD_ACTION_MENU = 'downloadActionMenu';
Expand All @@ -16,6 +17,7 @@ export const useFileDownload = ({
}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: queryKey });
const { showErrorMessage } = useErrorMessages();

const { refetch, isFetching } = useQuery(
{
Expand All @@ -24,7 +26,11 @@ export const useFileDownload = ({
searchParams: { fileContentType: fileInfo?.fileContentType },
}).blob(),
enabled: !!fileInfo,
onSuccess,
onSuccess: response => {
showErrorMessage(response);
onSuccess?.(response);
},
onError: showErrorMessage,
onSettled,
...queryProps,
},
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useHoldingsNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import { useIntl } from 'react-intl';
import { useMemo } from 'react';
import { OPTIONS, PARAMETERS_KEYS } from '../../constants';
import { getMappedAndSortedNotes } from '../../utils/helpers';
import { useErrorMessages } from '../useErrorMessages';

export const HOLDINGS_NOTES_KEY = 'HOLDINGS_NOTES_KEY';

export const useHoldingsNotes = (options = {}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: HOLDINGS_NOTES_KEY });
const { formatMessage } = useIntl();
const { showErrorMessage } = useErrorMessages();

const { data, isLoading: isHoldingsNotesLoading } = useQuery(
{
queryKey: [namespaceKey],
cacheTime: Infinity,
staleTime: Infinity,
queryFn: () => ky.get('holdings-note-types', { searchParams: { limit: 1000 } }).json(),
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options,
},
);
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useInstanceNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import { useIntl } from 'react-intl';
import { useMemo } from 'react';
import { OPTIONS, PARAMETERS_KEYS } from '../../constants';
import { getMappedAndSortedNotes } from '../../utils/helpers';
import { useErrorMessages } from '../useErrorMessages';

export const INSTANCE_NOTES_KEY = 'INSTANCE_NOTES_KEY';

export const useInstanceNotes = (options = {}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: INSTANCE_NOTES_KEY });
const { formatMessage } = useIntl();
const { showErrorMessage } = useErrorMessages();

const { data, isLoading: isInstanceNotesLoading } = useQuery(
{
queryKey: [namespaceKey],
cacheTime: Infinity,
staleTime: Infinity,
queryFn: () => ky.get('instance-note-types', { searchParams: { limit: 1000 } }).json(),
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options,
},
);
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useItemNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import { useIntl } from 'react-intl';
import { useMemo } from 'react';
import { OPTIONS, PARAMETERS_KEYS } from '../../constants';
import { getMappedAndSortedNotes } from '../../utils/helpers';
import { useErrorMessages } from '../useErrorMessages';

export const ITEM_NOTES_KEY = 'ITEM_NOTES_KEY';

export const useItemNotes = (options = {}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: ITEM_NOTES_KEY });
const { formatMessage } = useIntl();
const { showErrorMessage } = useErrorMessages();

const { data, isLoading: isItemNotesLoading } = useQuery(
{
queryKey: [namespaceKey],
cacheTime: Infinity,
staleTime: Infinity,
queryFn: () => ky.get('item-note-types', { searchParams: { limit: 1000 } }).json(),
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options,
},
);
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useLoanTypes.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { useQuery } from 'react-query';
import { useErrorMessages } from '../useErrorMessages';

export const LOAN_TYPES_KEY = 'LOAN_TYPES_KEY';

export const useLoanTypes = (options = {}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: LOAN_TYPES_KEY });
const { showErrorMessage } = useErrorMessages();

const { data, isLoading } = useQuery(
{
queryKey: [namespaceKey],
cacheTime: Infinity,
staleTime: Infinity,
queryFn: () => ky.get('loan-types?query=cql.allRecords%3D1%20sortby%20name&limit=1000').json(),
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options,
},
);
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/api/useLocationEsc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useNamespace } from '@folio/stripes/core';
import { useQuery } from 'react-query';
import { usePublishCoordinator } from '../usePublishCoordinator';
import { useErrorMessages } from '../useErrorMessages';

const DEFAULT_DATA = {};

export const useLocationEsc = (tenants, options = {}) => {
const [namespace] = useNamespace({ key: 'locationsEsc' });
const { initPublicationRequest } = usePublishCoordinator(namespace);
const { showErrorMessage } = useErrorMessages();

const { data = DEFAULT_DATA, isFetching } = useQuery({
queryKey: [namespace, tenants],
Expand All @@ -19,6 +21,8 @@ export const useLocationEsc = (tenants, options = {}) => {
return publicationResults;
},
keepPreviousData: true,
onError: showErrorMessage,
onSuccess: showErrorMessage,
...options
});

Expand Down
Loading

0 comments on commit 11a0b18

Please sign in to comment.