Skip to content

Commit

Permalink
UIBULKED-544 Remove Instance (MARC) record type from Bulk edit logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vashjs committed Oct 2, 2024
1 parent 54bf6d0 commit e1fa1c5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import { useBulkOperationUsers } from '../../../../hooks/api/useBulkOperationUsers';
import { getFullName } from '../../../../utils/getFullName';
import { useLocationFilters, useLogsQueryParams, useSearchParams } from '../../../../hooks';
import { customFilter } from '../../../../utils/helpers';
import { customFilter, getTransformedLogsFilterValue } from '../../../../utils/helpers';

export const LogsTab = () => {
const intl = useIntl();
Expand Down Expand Up @@ -60,7 +60,9 @@ export const LogsTab = () => {
}
});

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

const { logsQueryParams } = useLogsQueryParams({ search: location.search });

Expand Down
10 changes: 6 additions & 4 deletions src/constants/selectOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ export const FILTER_OPTIONS = {
value: status,
label: <FormattedMessage id={`ui-bulk-edit.logs.status.${status}`} />,
})),
CAPABILITY: Object.values(CAPABILITIES).map(entityType => ({
value: entityType,
label: <FormattedMessage id={`ui-bulk-edit.logs.entityType.${entityType}`} />,
})),
CAPABILITY: Object.values(CAPABILITIES)
.filter(capability => capability !== CAPABILITIES.INSTANCE_MARC)
.map(entityType => ({
value: entityType,
label: <FormattedMessage id={`ui-bulk-edit.logs.entityType.${entityType}`} />,
})),
OPERATION_TYPE: [
{
value: 'UPDATE',
Expand Down
6 changes: 5 additions & 1 deletion src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ export const filterByIds = (items, ids) => {
return items.filter(item => ids.includes(item.id));
};


export const getTransformedLogsFilterValue = (values) => {
return values.includes(CAPABILITIES.INSTANCE)
? [...new Set([...values, CAPABILITIES.INSTANCE_MARC])]
: values.filter(value => value !== CAPABILITIES.INSTANCE_MARC);
};
40 changes: 39 additions & 1 deletion src/utils/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
customFilter,
getTenantsById,
getTenantsById, getTransformedLogsFilterValue,
removeDuplicatesByValue
} from './helpers';
import { CAPABILITIES } from '../constants';

describe('customFilter', () => {
const dataOptions = [
Expand Down Expand Up @@ -220,3 +221,40 @@ describe('getTenantsById', () => {
expect(result).toBeNull();
});
});

describe('getTransformedLogsFilterValue', () => {
it('should add INSTANCE_MARC to the array if INSTANCE is present', () => {
const values = [CAPABILITIES.INSTANCE];
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(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(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(values);
expect(result).toEqual(values);
});

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

0 comments on commit e1fa1c5

Please sign in to comment.