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

UIBULKED-585 Adding missing translation and filters #658

Merged
merged 3 commits into from
Dec 3, 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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [UIBULKED-580](https://folio-org.atlassian.net/browse/UIBULKED-580) Refactor of publish coordinator related logic.
* [UIBULKED-587](https://folio-org.atlassian.net/browse/UIBULKED-587) Only Users from the first page are displayed in "Users" dropdown on "Logs" page.
* [UIBULKED-560](https://folio-org.atlassian.net/browse/UIBULKED-560) Update actions menu.
* [UIBULKED-585](https://folio-org.atlassian.net/browse/UUIBULKED-585) Adding missing translation and filters.

## [4.2.2](https://github.com/folio-org/ui-bulk-edit/tree/v4.2.2) (2024-11-15)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const LogsTab = () => {
});

const adaptedApplyFilters = useCallback(({ name, values }) => {
return applyFilters(name, getTransformedLogsFilterValue(name, values));
return applyFilters(name, getTransformedLogsFilterValue(values));
}, [applyFilters]);

const { logsQueryParams } = useLogsQueryParams({ search: location.search });
Expand Down
6 changes: 6 additions & 0 deletions src/constants/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export const LOGS_FILTERS = {
USER: 'userId',
};

export const LOGS_FILTER_DEPENDENCY_MAP = {
[CAPABILITIES.INSTANCE]: CAPABILITIES.INSTANCE_MARC,
[JOB_STATUSES.REVIEW_CHANGES]: JOB_STATUSES.REVIEWED_NO_MARC_RECORDS,
[JOB_STATUSES.DATA_MODIFICATION]: JOB_STATUSES.DATA_MODIFICATION_IN_PROGRESS,
};

export const MANUAL_UPLOAD_STEPS = {
UPLOAD: 'UPLOAD',
CONFIRM: 'CONFIRM',
Expand Down
26 changes: 12 additions & 14 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { clone, setWith } from 'lodash';
import {
CAPABILITIES,
EDIT_CAPABILITIES_OPTIONS,
JOB_STATUSES,
LOGS_FILTERS,
LOGS_FILTER_DEPENDENCY_MAP,
} from '../constants';

export const isCapabilityDisabled = (capabilityValue, view, perms = {}) => {
Expand Down Expand Up @@ -161,20 +160,19 @@ export const filterByIds = (items, ids) => {
return items.filter(item => ids.includes(item.id));
};

export const getTransformedLogsFilterValue = (name, values) => {
const getWithDependentValue = (triggerValue, dependentValue) => {
return values.includes(triggerValue)
? [...new Set([...values, dependentValue])]
: values.filter(value => value !== dependentValue);
};
export const getTransformedLogsFilterValue = (values) => {
// ignore case when values is not an array (ex. user ID filter)
if (!Array.isArray(values)) return values;

if (name === LOGS_FILTERS.CAPABILITY) {
return getWithDependentValue(CAPABILITIES.INSTANCE, CAPABILITIES.INSTANCE_MARC);
}
const result = new Set(values);

if (name === LOGS_FILTERS.STATUS) {
return getWithDependentValue(JOB_STATUSES.REVIEW_CHANGES, JOB_STATUSES.REVIEWED_NO_MARC_RECORDS);
for (const [value, dependentValue] of Object.entries(LOGS_FILTER_DEPENDENCY_MAP)) {
if (result.has(value)) {
result.add(dependentValue);
} else {
result.delete(dependentValue);
}
}

return values;
return Array.from(result);
};
18 changes: 9 additions & 9 deletions src/utils/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getTransformedLogsFilterValue,
removeDuplicatesByValue
} from './helpers';
import { CAPABILITIES, JOB_STATUSES, LOGS_FILTERS } from '../constants';
import { CAPABILITIES, JOB_STATUSES } from '../constants';

describe('customFilter', () => {
const dataOptions = [
Expand Down Expand Up @@ -226,56 +226,56 @@ describe('getTenantsById', () => {
describe('getTransformedLogsFilterValue', () => {
it('should add INSTANCE_MARC to the array if INSTANCE is present', () => {
const values = [CAPABILITIES.INSTANCE];
const result = getTransformedLogsFilterValue(LOGS_FILTERS.CAPABILITY, values);
const result = getTransformedLogsFilterValue(values);
expect(result).toContain(CAPABILITIES.INSTANCE);
expect(result).toContain(CAPABILITIES.INSTANCE_MARC);
});

it('should not add INSTANCE_MARC if it is already present', () => {
const values = [CAPABILITIES.INSTANCE, CAPABILITIES.INSTANCE_MARC];
const result = getTransformedLogsFilterValue(LOGS_FILTERS.CAPABILITY, values);
const result = getTransformedLogsFilterValue(values);
expect(result).toContain(CAPABILITIES.INSTANCE);
expect(result).toContain(CAPABILITIES.INSTANCE_MARC);
expect(result.length).toBe(2);
});

it('should remove INSTANCE_MARC from the array if INSTANCE is not present', () => {
const values = [CAPABILITIES.INSTANCE_MARC, 'other_value'];
const result = getTransformedLogsFilterValue(LOGS_FILTERS.CAPABILITY, values);
const result = getTransformedLogsFilterValue(values);
expect(result).not.toContain(CAPABILITIES.INSTANCE_MARC);
expect(result).toContain('other_value');
});

it('should return the same array if INSTANCE and INSTANCE_MARC are not present', () => {
const values = ['other_value'];
const result = getTransformedLogsFilterValue(LOGS_FILTERS.CAPABILITY, values);
const result = getTransformedLogsFilterValue(values);
expect(result).toEqual(values);
});

it('should not modify the original input array', () => {
const values = [CAPABILITIES.INSTANCE];
const result = getTransformedLogsFilterValue(LOGS_FILTERS.CAPABILITY, values);
const result = getTransformedLogsFilterValue(values);
expect(values).not.toContain(CAPABILITIES.INSTANCE_MARC);
expect(result).toContain(CAPABILITIES.INSTANCE_MARC);
});

it('should not modify the original userID', () => {
const values = 'userID';
const result = getTransformedLogsFilterValue(LOGS_FILTERS.USER, values);
const result = getTransformedLogsFilterValue(values);
expect(values).not.toContain(CAPABILITIES.INSTANCE_MARC);
expect(result).toContain('userID');
});

it('should add REVIEWED_NO_MARC_RECORDS to the array if REVIEW_CHANGES is present', () => {
const values = [JOB_STATUSES.REVIEW_CHANGES];
const result = getTransformedLogsFilterValue(LOGS_FILTERS.STATUS, values);
const result = getTransformedLogsFilterValue(values);
expect(result).toContain(JOB_STATUSES.REVIEW_CHANGES);
expect(result).toContain(JOB_STATUSES.REVIEWED_NO_MARC_RECORDS);
});

it('should remove REVIEWED_NO_MARC_RECORDS from the array if REVIEW_CHANGES is not present', () => {
const values = ['other_value'];
const result = getTransformedLogsFilterValue(LOGS_FILTERS.STATUS, values);
const result = getTransformedLogsFilterValue(values);
expect(result).not.toContain(JOB_STATUSES.REVIEWED_NO_MARC_RECORDS);
expect(result).toContain('other_value');
});
Expand Down
1 change: 1 addition & 0 deletions translations/ui-bulk-edit/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
"logs.status.RETRIEVING_RECORDS": "Retrieving records",
"logs.status.SAVING_RECORDS_LOCALLY": "Saving records",
"logs.status.DATA_MODIFICATION": "Data modification",
"logs.status.DATA_MODIFICATION_IN_PROGRESS": "Data modification",
"logs.status.REVIEW_CHANGES": "Reviewing changes",
"logs.status.REVIEWED_NO_MARC_RECORDS": "Reviewing changes",
"logs.status.COMPLETED": "Completed",
Expand Down
Loading