Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/hide empty tab #4969

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 19 additions & 18 deletions src/pages/patientView/PatientViewPageTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,24 +553,25 @@ export function tabs(
</MSKTab>
);

tabs.push(
<MSKTab
key={4}
id={PatientViewPageTabs.FilesAndLinks}
linkText={RESOURCES_TAB_NAME}
hide={!pageComponent.shouldShowResources}
>
<div>
<ResourcesTab
store={pageComponent.patientViewPageStore}
sampleManager={
pageComponent.patientViewPageStore.sampleManager.result!
}
openResource={pageComponent.openResource}
/>
</div>
</MSKTab>
);
if (pageComponent.shouldShowResources)
tabs.push(
<MSKTab
key={4}
id={PatientViewPageTabs.FilesAndLinks}
linkText={RESOURCES_TAB_NAME}
>
<div>
<ResourcesTab
store={pageComponent.patientViewPageStore}
sampleManager={
pageComponent.patientViewPageStore.sampleManager
.result!
}
openResource={pageComponent.openResource}
/>
</div>
</MSKTab>
);

tabs.push(
<MSKTab
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
62 changes: 36 additions & 26 deletions src/shared/components/resources/ResourceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,48 @@ const ResourceTable = observer(
<tr>
<th>Resource</th>
<th></th>
<th>Description</th>
{resourceTable.data.length > 0 && <th>Description</th>}
</tr>
</thead>
<tbody>
{resourceTable.data.map(resource => (
{resourceTable.data.length === 0 ? (
<tr>
<td>
<a onClick={() => openResource(resource)}>
{icon(resource)}
{resource.resourceDefinition.displayName ||
resource.url}
</a>
<td colSpan={3} style={{ textAlign: 'center' }}>
There are no results
</td>
<td>
<a
href={resource.url}
style={{ fontSize: 10 }}
target={'_blank'}
>
<i
className={`fa fa-external-link fa-sm`}
style={{
marginRight: 5,
color: 'black',
}}
/>
Open in new window
</a>
</td>
<td>{resource.resourceDefinition.description}</td>
</tr>
))}
) : (
resourceTable.data.map(resource => (
<tr>
<td>
<a onClick={() => openResource(resource)}>
{icon(resource)}
{resource.resourceDefinition
.displayName || resource.url}
</a>
</td>
<td>
<a
href={resource.url}
style={{ fontSize: 10 }}
target={'_blank'}
>
<i
className={`fa fa-external-link fa-sm`}
style={{
marginRight: 5,
color: 'black',
}}
/>
Open in new window
</a>
</td>
<td>
{resource.resourceDefinition.description}
</td>
</tr>
))
)}
</tbody>
</table>
);
Expand Down
Loading