Skip to content

Commit

Permalink
Update description for dynamic/static VS if blank or default
Browse files Browse the repository at this point in the history
  • Loading branch information
forus committed Oct 23, 2024
1 parent ebbd1b7 commit 4b49f4f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
16 changes: 6 additions & 10 deletions src/pages/studyView/StudyViewUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ export function getVirtualStudyDescription(
attributeNamesSet: { [id: string]: string },
molecularProfileNameSet: { [id: string]: string },
caseListNameSet: { [key: string]: string },
user?: string
user?: string,
hideSampleCounts: boolean = false
) {
let descriptionLines: string[] = [];
const createdOnStr = 'Created on';
Expand All @@ -917,18 +918,13 @@ export function getVirtualStudyDescription(
_.flatMap(studyWithSamples, study => study.uniqueSampleKeys)
);
descriptionLines.push(
`${uniqueSampleKeys.length} sample${
uniqueSampleKeys.length > 1 ? 's' : ''
} from ${studyWithSamples.length} ${
studyWithSamples.length > 1 ? 'studies:' : 'study:'
}`
(hideSampleCounts ? 'Samples' : `${uniqueSampleKeys.length} sample${uniqueSampleKeys.length > 1 ? 's' : ''}`)
+ ` from ${studyWithSamples.length} ${studyWithSamples.length > 1 ? 'studies:' : 'study:'}`
);
//add individual studies sample count
studyWithSamples.forEach(studyObj => {
descriptionLines.push(
`- ${studyObj.name} (${
studyObj.uniqueSampleKeys.length
} sample${uniqueSampleKeys.length > 1 ? 's' : ''})`
descriptionLines.push(`- ${studyObj.name}`
+ (hideSampleCounts ? '' : ` (${studyObj.uniqueSampleKeys.length} sample${uniqueSampleKeys.length > 1 ? 's' : ''})`)
);
});
//add filters
Expand Down
44 changes: 26 additions & 18 deletions src/pages/studyView/virtualStudy/VirtualStudy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class VirtualStudy extends React.Component<
{}
> {
@observable.ref private name: string;
@observable.ref private description: string;
@observable.ref private description: string = '';
@observable.ref private dynamic: boolean = false;

@observable private saving = false;
Expand All @@ -108,17 +108,7 @@ export default class VirtualStudy extends React.Component<
super(props);
makeObservable(this);
this.name = props.name || '';
this.description =
props.description ||
getVirtualStudyDescription(
this.props.description,
this.props.studyWithSamples,
this.props.filter,
this.attributeNamesSet,
this.props.molecularProfileNameSet,
this.props.caseListNameSet,
this.props.user
);
this.setDynamicTypeTo(false);
}

@computed get namePlaceHolder() {
Expand Down Expand Up @@ -233,6 +223,28 @@ export default class VirtualStudy extends React.Component<
);
}

updateDescriptionIfBlankOrDefault(hideSampleCounts: boolean) {
const getVirtualStudyDescriptionWithCounts = getVirtualStudyDescription.bind(null,
this.props.description,
this.props.studyWithSamples,
this.props.filter,
this.attributeNamesSet,
this.props.molecularProfileNameSet,
this.props.caseListNameSet,
this.props.user
);
const blankOrDefaultDescription = !this.description || !this.description.trim() || this.description === getVirtualStudyDescriptionWithCounts(!hideSampleCounts);
if (blankOrDefaultDescription) {
this.description = getVirtualStudyDescriptionWithCounts(hideSampleCounts);
}
}

setDynamicTypeTo(dynamic: boolean) {
this.dynamic = dynamic;

this.updateDescriptionIfBlankOrDefault(dynamic);
}

render() {
return (
<div
Expand Down Expand Up @@ -308,9 +320,7 @@ export default class VirtualStudy extends React.Component<
name="option"
value="static"
checked={!this.dynamic}
onChange={_ =>
(this.dynamic = false)
}
onChange={_ => this.setDynamicTypeTo(false) }
/>{' '}
Static
</label>
Expand All @@ -320,9 +330,7 @@ export default class VirtualStudy extends React.Component<
name="option"
value="dynamic"
checked={this.dynamic}
onChange={_ =>
(this.dynamic = true)
}
onChange={_ => this.setDynamicTypeTo(true) }
/>{' '}
Dynamic
</label>
Expand Down

0 comments on commit 4b49f4f

Please sign in to comment.