Skip to content

Commit

Permalink
SV: Fix group refreshing issue on checkbox selection
Browse files Browse the repository at this point in the history
  • Loading branch information
kalletlak committed Aug 13, 2021
1 parent 0479e0c commit 879e1e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,11 @@ export default class ComparisonGroupManager extends React.Component<
if (reservedColor != undefined)
this.props.store.onGroupColorChange(id, reservedColor);
this.props.store.notifyComparisonGroupsChange();
this.props.store.setComparisonGroupSelected(id); // created groups start selected
if (!this.props.store.isLoggedIn) {
//save group id to page session only for non-logged in user.
// this is to keep track of what groups are created by the user
this.props.store.trackNewlyCreatedGroup(id);
}
this.cancelAddGroup();
}

Expand Down
41 changes: 24 additions & 17 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ export class StudyViewPageStore
ComparisonGroupId,
boolean
>({}, { deep: false });
private createdGroups = observable.map<ComparisonGroupId, boolean>(
{},
{ deep: false }
);
private _selectedComparisonGroupsWarningSigns = observable.map<
string,
boolean
Expand All @@ -619,6 +623,10 @@ export class StudyViewPageStore
{ deep: false }
);

@action public trackNewlyCreatedGroup(groupId: string): void {
this.createdGroups.set(groupId, true);
}

@action public setComparisonGroupSelected(
groupId: string,
selected = true
Expand Down Expand Up @@ -711,6 +719,7 @@ export class StudyViewPageStore
}
// delete it even from the shared group set
delete this.sharedGroupSet[groupId];
this.createdGroups.delete(groupId);

this._selectedComparisonGroups.delete(groupId);
}
Expand Down Expand Up @@ -939,29 +948,26 @@ export class StudyViewPageStore
}

// group present in page session which are not saved to user account
const missingGroupIds = Array.from(
this._selectedComparisonGroups.keys()
const missingGroupIds: string[] = Array.from(
this.createdGroups.keys()
).filter(groupId => groupIdSet[groupId] === undefined);

if (missingGroupIds.length > 0) {
const promises = [];
for (const groupId of missingGroupIds) {
promises.push(comparisonClient.getGroup(groupId));
}
const promises = missingGroupIds.map(groupId =>
comparisonClient.getGroup(groupId)
);
const studyIdsSet = stringListToSet(
this.queriedPhysicalStudyIds.result!
);
let newGroups: Group[] = await Promise.all(promises);

newGroups
.filter(
group =>
!_.some(
group.data.studies,
study => studyIdsSet[study.id] === undefined
)
)
.forEach(group =>
newGroups.forEach(group => {
if (
!_.some(
group.data.studies,
study => studyIdsSet[study.id] === undefined
)
) {
groups.push(
Object.assign(
group.data,
Expand All @@ -972,8 +978,9 @@ export class StudyViewPageStore
this.sampleSet.result!
)
)
)
);
);
}
});
}

return groups;
Expand Down

0 comments on commit 879e1e1

Please sign in to comment.