Skip to content

Commit

Permalink
query - changed deletion to look for either id/name or filterID
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethienne Roy committed Aug 7, 2023
1 parent e71c8b1 commit 8c692f3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
72 changes: 72 additions & 0 deletions src/tests/savedFilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,78 @@ describe('Validate filters handle query pills', () => {
expect(JSON.stringify(result)).not.toContain('0a1292c2-0bab-4190-a8d1-6db6e125af8a');
});

it('should remove object with title and id', () => {
const initialFilters = [
{
id: '924569d4-706f-4658-a349-f5168a1ed966',
keycloak_id: '3999fd60-80d2-477d-819e-93f6873efdb2',
title: 'Filtre 3',
tag: 'snv_exploration_rqdm',
type: 'filter',
favorite: false,
queries: [
{
id: '0e21dcc6-27ac-4e83-a386-75bcba8db818',
op: 'and',
content: [
{
id: '3355ead1-83c2-4003-9ac2-db87c086e6d3',
op: 'and',
title: 'pill three',
content: [
{
op: 'in',
content: {
field: 'variant_class',
index: 'Variants',
value: ['SNV', 'deletion'],
},
},
{
op: 'in',
content: {
field: 'variant_external_reference',
index: 'Variants',
value: ['DBSNP', 'Clinvar'],
},
},
],
},
{
op: 'in',
content: {
field: 'donors.analysis_code',
index: 'Variants',
value: ['MYOC'],
},
},
],
},
{
id: 'c23b89df-36ef-47cf-92c0-28971dea9385',
op: 'and',
content: [
{
op: 'in',
content: {
field: 'donors.analysis_code',
index: 'Variants',
value: ['MYOC', 'RGDI', 'EXTUM'],
},
},
],
},
],
creation_date: '2023-08-07T19:07:13.904Z',
updated_date: '2023-08-07T19:07:13.904Z',
},
];

const result = removeQueryFromFilters(initialFilters, '3355ead1-83c2-4003-9ac2-db87c086e6d3');

expect(JSON.stringify(result)).not.toContain('3355ead1-83c2-4003-9ac2-db87c086e6d3');
});

it('replace object containing filterID with query content', async () => {
const value = new Promise((resolve) => {
resolve({ query: { content: 'abcde' }, title: 'fghijklm', filterID: '1234' });
Expand Down
4 changes: 2 additions & 2 deletions src/utils/savedFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { getById } from '../db/dal/savedFilter';
const removeFilterFromContent = (content, id) => {
if (content)
return content.map((obj) => {
if (content.content) return removeFilterFromContent(obj.content, id);
if (obj.filterID !== id) {
if (obj.filterID !== id && obj.title && obj.id !== id) {
return obj;
}
if (content.content) return removeFilterFromContent(obj.content, id);
});
};

Expand Down

0 comments on commit 8c692f3

Please sign in to comment.