Skip to content

Commit

Permalink
Org/Source/Collections | showing about tab if there is about entry
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Dec 17, 2020
1 parent 17028f3 commit eb31199
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/components/collections/CollectionHome.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { CircularProgress } from '@material-ui/core';
import { includes } from 'lodash';
import { includes, isEmpty, get } from 'lodash';
import APIService from '../../services/APIService';
import CollectionHomeHeader from './CollectionHomeHeader';
import CollectionHomeTabs from './CollectionHomeTabs';
Expand All @@ -21,7 +21,7 @@ class CollectionHome extends React.Component {
getDefaultTabIndex() {
const { location } = this.props;

if(location.pathname.indexOf('/about') > -1)
if(location.pathname.indexOf('/about') > -1 && this.shouldShowAboutTab())
return 4;
if(location.pathname.indexOf('/versions') > -1)
return 3;
Expand Down Expand Up @@ -117,10 +117,15 @@ class CollectionHome extends React.Component {
return version
}

shouldShowAboutTab() {
return !isEmpty(get(this, 'state.collection.extras.about'));
}

render() {
const { collection, versions, isLoading, tab } = this.state;
const currentURL = this.getURLFromPath()
const versionedObjectURL = this.getVersionedObjectURLFromPath()
const showAboutTab = this.shouldShowAboutTab();
return (
<div style={isLoading ? {textAlign: 'center', marginTop: '40px'} : {}}>
{
Expand All @@ -141,6 +146,7 @@ class CollectionHome extends React.Component {
location={this.props.location}
versionedObjectURL={versionedObjectURL}
currentVersion={this.getCurrentVersion()}
aboutTab={showAboutTab}
/>
</div>
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/collections/CollectionHomeTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AboutAccordian from '../common/AboutAccordian';
const CollectionHomeTabs = props => {
const {
tab, onChange, collection, versions, location, versionedObjectURL, currentVersion,
aboutTab
} = props;
const about = get(collection, 'extras.about')

Expand All @@ -18,7 +19,7 @@ const CollectionHomeTabs = props => {
<Tab label="Mappings" />
<Tab label="References" />
<Tab label="Versions" />
<Tab label="About" />
{aboutTab && <Tab label="About" />}
</Tabs>
<div className='sub-tab-container' style={{display: 'flex', minHeight: '500px'}}>
{
Expand Down Expand Up @@ -60,7 +61,7 @@ const CollectionHomeTabs = props => {
<ConceptContainerVersionList versions={versions} resource='collection' />
}
{
tab === 4 &&
aboutTab && tab === 4 &&
<AboutAccordian id={collection.id} about={about} />
}
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/components/orgs/OrgHome.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { CircularProgress } from '@material-ui/core';
import { reject, get } from 'lodash';
import { reject, get, isEmpty } from 'lodash';
import APIService from '../../services/APIService';
import { isCurrentUserMemberOf } from '../../common/utils';
import Pins from '../common/Pins';
Expand All @@ -21,7 +21,7 @@ class OrgHome extends React.Component {
getDefaultTabIndex() {
const { location } = this.props;

if(location.pathname.indexOf('/about') > -1)
if(location.pathname.indexOf('/about') > -1 && this.shouldShowAboutTab())
return 3;
if(location.pathname.indexOf('/members') > -1)
return 2;
Expand Down Expand Up @@ -122,10 +122,15 @@ class OrgHome extends React.Component {
service.put({order: newOrder}).then(() => {})
}

shouldShowAboutTab() {
return !isEmpty(get(this, 'state.org.extras.about'));
}

render() {
const { org, isLoading, tab, pins } = this.state;
const url = this.getURLFromPath()
const isCurrentUserMemberOfOrg = isCurrentUserMemberOf(this.getOrgId());
const showAboutTab = this.shouldShowAboutTab()
return (
<div style={isLoading ? {textAlign: 'center', marginTop: '40px'} : {}}>
{
Expand All @@ -149,6 +154,7 @@ class OrgHome extends React.Component {
onPinCreate={this.createPin}
onPinDelete={this.deletePin}
showPin={isCurrentUserMemberOfOrg}
aboutTab={showAboutTab}
/>
</div>
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/orgs/OrgHomeTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import OrgHomeChildrenList from './OrgHomeChildrenList';

const OrgHomeTabs = props => {
const {
tab, org, location, url, pins, showPin, onTabChange, onPinCreate, onPinDelete,
tab, org, location, url, pins, showPin, onTabChange, onPinCreate, onPinDelete, aboutTab
} = props;
const about = get(org, 'extras.about')

Expand All @@ -16,7 +16,7 @@ const OrgHomeTabs = props => {
<Tab label="Sources" />
<Tab label="Collections" />
<Tab label="Members" />
<Tab label="About" />
{aboutTab && <Tab label="About" />}
</Tabs>
<div className='sub-tab-container' style={{display: 'flex', minHeight: '500px'}}>
{
Expand Down Expand Up @@ -56,7 +56,7 @@ const OrgHomeTabs = props => {
/>
}
{
tab === 3 &&
aboutTab && tab === 3 &&
<AboutAccordian id={org.id} about={about} />
}
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/components/sources/SourceHome.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { CircularProgress } from '@material-ui/core';
import { includes } from 'lodash';
import { includes, isEmpty, get } from 'lodash';
import APIService from '../../services/APIService';
import SourceHomeHeader from './SourceHomeHeader';
import SourceHomeTabs from './SourceHomeTabs';
Expand All @@ -21,7 +21,7 @@ class SourceHome extends React.Component {
getDefaultTabIndex() {
const { location } = this.props;

if(location.pathname.indexOf('/about') > -1)
if(location.pathname.indexOf('/about') > -1 && this.shouldShowAboutTab())
return 3;
if(location.pathname.indexOf('/versions') > -1)
return 2;
Expand Down Expand Up @@ -113,10 +113,15 @@ class SourceHome extends React.Component {
return version
}

shouldShowAboutTab() {
return !isEmpty(get(this, 'state.source.extras.about'));
}

render() {
const { source, versions, isLoading, tab } = this.state;
const currentURL = this.getURLFromPath()
const versionedObjectURL = this.getVersionedObjectURLFromPath()
const showAboutTab = this.shouldShowAboutTab();
return (
<div style={isLoading ? {textAlign: 'center', marginTop: '40px'} : {}}>
{
Expand All @@ -137,6 +142,7 @@ class SourceHome extends React.Component {
location={this.props.location}
versionedObjectURL={versionedObjectURL}
currentVersion={this.getCurrentVersion()}
aboutTab={showAboutTab}
/>
</div>
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/sources/SourceHomeTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AboutAccordian from '../common/AboutAccordian';
const SourceHomeTabs = props => {
const {
tab, onChange, source, versions, location, versionedObjectURL, currentVersion,
aboutTab
} = props;
const about = get(source, 'extras.about')

Expand All @@ -17,7 +18,7 @@ const SourceHomeTabs = props => {
<Tab label="Concepts" />
<Tab label="Mappings" />
<Tab label="Versions" />
<Tab label="About" />
{aboutTab && <Tab label="About" />}
</Tabs>
<div className='sub-tab-container' style={{display: 'flex', minHeight: '500px'}}>
{
Expand Down Expand Up @@ -47,7 +48,7 @@ const SourceHomeTabs = props => {
<ConceptContainerVersionList versions={versions} resource='source' />
}
{
tab === 3 &&
aboutTab && tab === 3 &&
<AboutAccordian id={source.id} about={about} />
}
</div>
Expand Down

0 comments on commit eb31199

Please sign in to comment.