Skip to content

Commit

Permalink
Updated logic and refactoring and prettier changes
Browse files Browse the repository at this point in the history
Only CancerStudy objects from treeData are filtered based on whether the readPermission field has a value.  Refactoring: New const created as shownStudiesLengthstring to identify if there is a filter applied or not.

Update Phrase.tsx

conflict resolution fix due to merge

changes for prettier

prettier changes
  • Loading branch information
jagnathan committed May 2, 2023
1 parent 8b211a8 commit 6c849ad
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 63 deletions.
52 changes: 8 additions & 44 deletions src/shared/components/query/CancerStudySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export default class CancerStudySelector extends React.Component<
const quickSetButtons = this.logic.mainView.quickSelectButtons(
getServerConfig().skin_quick_select_buttons
);
const shownStudiesLengthstring =
shownStudies.length < this.store.cancerStudies.result.length
? 'matching filter'
: '';

return (
<FlexCol
Expand Down Expand Up @@ -338,28 +342,8 @@ export default class CancerStudySelector extends React.Component<
<strong>
{shownAndSelectedStudies.length ===
shownStudies.length
? `Deselect all listed studies ${
shownStudies.length <
this.store
.cancerStudies
.result
.length
? 'matching filter'
: ''
} (${
shownStudies.length
})`
: `Select all listed studies ${
shownStudies.length <
this.store
.cancerStudies
.result
.length
? 'matching filter'
: ''
} (${
shownStudies.length
})`}
? `Deselect all listed studies ${shownStudiesLengthstring} (${shownStudies.length})`
: `Select all listed studies ${shownStudiesLengthstring} (${shownStudies.length})`}
</strong>
</label>
</Then>
Expand All @@ -385,28 +369,8 @@ export default class CancerStudySelector extends React.Component<
shownAndAuthorizedStudies.length &&
shownAndAuthorizedStudies.length >
0
? `Deselect all authorized studies ${
shownStudies.length <
this.store
.cancerStudies
.result
.length
? 'matching filter'
: ''
} (${
shownAndAuthorizedStudies.length
})`
: `Select all authorized studies ${
shownStudies.length <
this.store
.cancerStudies
.result
.length
? 'matching filter'
: ''
} (${
shownAndAuthorizedStudies.length
})`}
? `Deselect all authorized studies ${shownStudiesLengthstring} (${shownAndAuthorizedStudies.length})`
: `Select all authorized studies ${shownStudiesLengthstring} (${shownAndAuthorizedStudies.length})`}
</strong>
</label>
</Else>
Expand Down
18 changes: 12 additions & 6 deletions src/shared/components/query/QueryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,12 @@ export class QueryStore {
return client
.getAllSamplesOfPatientInStudyUsingGET({ studyId, patientId })
.then(
samples => ({ studyId, patientId, samples, error: undefined }),
samples => ({
studyId,
patientId,
samples,
error: undefined,
}),
error => ({
studyId,
patientId,
Expand Down Expand Up @@ -1480,11 +1485,12 @@ export class QueryStore {
}

@computed get readPermissions(): Set<string> {
const studies = Array.from(this.treeData.map_node_meta.keys()).filter( s => typeof((s as CancerStudy).readPermission) !== 'undefined' );
console.log(studies);
const readPermissions = studies
.map(n => (!!((n as CancerStudy).readPermission)).toString())
.filter(n => !!n);
const studies = Array.from(this.treeData.map_node_meta.keys()).filter(
s => typeof (s as CancerStudy).readPermission !== 'undefined'
);
const readPermissions = studies.map(n =>
(n as CancerStudy).readPermission.toString()
);
return new Set(readPermissions);
}

Expand Down
8 changes: 3 additions & 5 deletions src/shared/components/query/filteredSearch/Phrase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ export class ListPhrase implements Phrase {
public match(study: FullTextSearchNode): boolean {
let anyFieldMatch = false;
for (const fieldName of this.fields) {
if (!_.has(study, fieldName)) {
continue;
}
const fieldValue = (study as any)[fieldName];
if (typeof fieldValue !== 'undefined') {
let anyPhraseMatch = false;
const fieldValue = study[fieldName];
if (fieldValue) {
for (const phrase of this._phraseList) {
anyPhraseMatch =
anyPhraseMatch ||
Expand Down
2 changes: 1 addition & 1 deletion src/shared/lib/query/QueryParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { QueryParser } from 'shared/lib/query/QueryParser';
import { StringPhrase } from 'shared/components/query/filteredSearch/Phrase';

describe('QueryParser', () => {
const parser = new QueryParser(new Set<string>(),new Set<string>());
const parser = new QueryParser(new Set<string>(), new Set<string>());
const referenceGenomeFields = parser.searchFilters.find(
f => f.phrasePrefix === 'reference-genome'
)!.nodeFields;
Expand Down
17 changes: 10 additions & 7 deletions src/shared/lib/query/QueryParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export class QueryParser {
private readonly _searchFilters: CancerTreeSearchFilter[];

constructor(referenceGenomes: Set<string>, readPermissions: Set<string>) {
console.log('readPermissions');
console.log(readPermissions);
console.log(readPermissions.size);
this._searchFilters = [
/**
* Example queries:
Expand Down Expand Up @@ -65,10 +62,16 @@ export class QueryParser {
nodeFields: ['readPermission'],
form: {
input: FilterCheckbox,
options: readPermissions.size > 1 ? [
{ value: 'true', displayValue: 'Authorized' },
{ value: 'false', displayValue: 'Unauthorized' },
]:[],
options:
readPermissions.size > 1
? [
{ value: 'true', displayValue: 'Authorized' },
{
value: 'false',
displayValue: 'Unauthorized',
},
]
: [],
label: 'Controlled access',
},
},
Expand Down

0 comments on commit 6c849ad

Please sign in to comment.