Skip to content

Commit

Permalink
Calculate description using Mobx @computed
Browse files Browse the repository at this point in the history
  • Loading branch information
forus committed Nov 20, 2024
1 parent c29cb99 commit 7871b78
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 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 userProvidedDescription: string = '';
@observable.ref private dynamic: boolean = false;

@observable private saving = false;
Expand All @@ -108,7 +108,7 @@ export default class VirtualStudy extends React.Component<
super(props);
makeObservable(this);
this.name = props.name || '';
this.setDynamicTypeTo(false);
this.userProvidedDescription = this.description;
}

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

updateDescriptionIfBlankOrDefault(hideSampleCounts: boolean) {
const getVirtualStudyDescriptionWithCounts = getVirtualStudyDescription.bind(
null,
getDefuaultDescriptionByType(dynamic: boolean) {
return getVirtualStudyDescription(
this.props.description,
this.props.studyWithSamples,
this.props.filter,
this.attributeNamesSet,
this.props.molecularProfileNameSet,
this.props.caseListNameSet,
this.props.user
this.props.user,
dynamic
);
}

@computed get description() {
const blankOrDefaultDescription =
!this.description ||
!this.description.trim() ||
this.description ===
getVirtualStudyDescriptionWithCounts(!hideSampleCounts);
!this.userProvidedDescription ||
!this.userProvidedDescription.trim() ||
this.userProvidedDescription ===
this.getDefuaultDescriptionByType(!this.dynamic);
if (blankOrDefaultDescription) {
this.description = getVirtualStudyDescriptionWithCounts(
hideSampleCounts
);
return this.getDefuaultDescriptionByType(this.dynamic);
}
}

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

this.updateDescriptionIfBlankOrDefault(dynamic);
return this.userProvidedDescription;
}

render() {
Expand Down Expand Up @@ -313,7 +309,7 @@ export default class VirtualStudy extends React.Component<
placeholder="Virtual study description (Optional)"
value={this.description}
onChange={event =>
(this.description =
(this.userProvidedDescription =
event.currentTarget.value)
}
/>
Expand All @@ -328,9 +324,7 @@ export default class VirtualStudy extends React.Component<
value="static"
checked={!this.dynamic}
onChange={_ =>
this.setDynamicTypeTo(
false
)
(this.dynamic = false)
}
/>{' '}
Static
Expand All @@ -342,9 +336,7 @@ export default class VirtualStudy extends React.Component<
value="dynamic"
checked={this.dynamic}
onChange={_ =>
this.setDynamicTypeTo(
true
)
(this.dynamic = true)
}
/>{' '}
Dynamic
Expand Down

0 comments on commit 7871b78

Please sign in to comment.