Skip to content

Commit

Permalink
Merge pull request #4 from Nelliney/hide-empty-tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelliney authored Aug 21, 2024
2 parents e41c49e + 41a48e4 commit 593846a
Show file tree
Hide file tree
Showing 8 changed files with 493 additions and 42 deletions.
5 changes: 5 additions & 0 deletions src/pages/patientView/PatientViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ export class PatientViewPageInner extends React.Component<

@computed
get shouldShowResources(): boolean {
const tabId: string = this.urlWrapper.activeTabId;
if (tabId === 'filesAndLinks') {
return true;
}

if (this.pageStore.resourceIdToResourceData.isComplete) {
return _.some(
this.pageStore.resourceIdToResourceData.result,
Expand Down
35 changes: 35 additions & 0 deletions src/pages/patientView/resources/ResourcesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,40 @@ export default class ResourcesTab extends React.Component<
},
});

readonly showNoResource = MakeMobxView({
await: () => [this.props.store.resourceIdToResourceData],
render: () => {
const shouldShowNoResource = () => {
if (this.props.store.resourceIdToResourceData.isComplete) {
return !_.some(
this.props.store.resourceIdToResourceData.result,
data => data.length > 0
);
}
return true;
};

if (shouldShowNoResource()) {
return (
<div className="resourcesSection">
<h4 className="blackHeader">
Resources for {this.props.store.patientId}
</h4>
<ResourceTable
resources={
this.props.store.studyResourceData.result!
}
isTabOpen={this.props.store.isResourceTabOpen}
openResource={this.props.openResource}
/>
</div>
);
} else {
return null;
}
},
});

render() {
return (
<div className="resourcesTab">
Expand All @@ -136,6 +170,7 @@ export default class ResourcesTab extends React.Component<
{this.patientResources.component}
{this.sampleResources.component}
{this.studyResources.component}
{this.showNoResource.component}
</div>
</div>
);
Expand Down
7 changes: 2 additions & 5 deletions src/pages/studyView/StudyViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,8 @@ export default class StudyViewPage extends React.Component<
}

@computed get shouldShowResources() {
if (this.store.resourceIdToResourceData.isComplete) {
return _.some(
this.store.resourceIdToResourceData.result,
data => data.length > 0
);
if (this.store.resourceDefinitions.isComplete) {
return this.store.resourceDefinitions.result.length > 0;
} else {
return false;
}
Expand Down
38 changes: 38 additions & 0 deletions src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5784,6 +5784,44 @@ export class StudyViewPageStore
},
});

readonly sampleResourceData = remoteData<{
[sampleId: string]: ResourceData[];
}>({
await: () => [this.resourceDefinitions, this.samples],
invoke: () => {
const sampleResourceDefinitions = this.resourceDefinitions.result!.filter(
d => d.resourceType === 'SAMPLE'
);
if (!sampleResourceDefinitions.length) {
return Promise.resolve({});
}

const res = _(this.samples.result!)
.map(sample =>
sampleResourceDefinitions.map(resource =>
internalClient.getAllResourceDataOfSampleInStudyUsingGET(
{
sampleId: sample.sampleId,
studyId: sample.studyId,
resourceId: resource.resourceId,
projection: 'DETAILED',
}
)
)
)
.flatten()
.value();

return Promise.all(res).then(resData =>
_(resData)
.flatMap()
.groupBy('sampleId')
.mapValues(data => data)
.value()
);
},
});

readonly resourceIdToResourceData = remoteData<{
[resourceId: string]: ResourceData[];
}>({
Expand Down
Loading

0 comments on commit 593846a

Please sign in to comment.